Mercurial > libervia-backend
annotate src/plugins/plugin_misc_groupblog.py @ 572:ca13633d3b6b
dates update
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Jan 2013 23:30:13 +0100 |
parents | 07f369ed3988 |
children | 952322b1d490 |
rev | line source |
---|---|
307 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT plugin for microbloging with roster access | |
572 | 6 Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
307 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
478
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
307 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
478
diff
changeset
|
16 GNU Affero General Public License for more details. |
307 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
478
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
307 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
22 from logging import debug, info, warning, error |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
23 from twisted.internet import defer |
307 | 24 from twisted.words.protocols.jabber import jid |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
25 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
26 from wokkel import disco, data_form, iwokkel |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
27 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
28 from zope.interface import implements |
307 | 29 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
30 try: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
31 from twisted.words.protocols.xmlstream import XMPPHandler |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
32 except ImportError: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
33 from wokkel.subprotocols import XMPPHandler |
307 | 34 |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
35 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
36 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog' |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
37 NS_NODE_PREFIX = 'urn:xmpp:groupblog:' |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
38 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
39 NS_PUBSUB_EXP = NS_PUBSUB #XXX: we can't use custom namespace as Wokkel's PubSubService use official NS |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
40 NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access" |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
41 NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check" |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
42 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config" |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
43 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create" |
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
44 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed' |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
45 OPT_ACCESS_MODEL = 'pubsub#access_model' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
46 OPT_PERSIST_ITEMS = 'pubsub#persist_items' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
47 OPT_MAX_ITEMS = 'pubsub#max_items' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
48 OPT_NODE_TYPE = 'pubsub#node_type' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
49 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
50 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth' |
307 | 51 TYPE_COLLECTION = 'collection' |
52 | |
53 PLUGIN_INFO = { | |
54 "name": "Group blogging throught collections", | |
55 "import_name": "groupblog", | |
56 "type": "MISC", | |
57 "protocols": [], | |
58 "dependencies": ["XEP-0277"], | |
59 "main": "GroupBlog", | |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
60 "handler": "yes", |
307 | 61 "description": _("""Implementation of microblogging with roster access""") |
62 } | |
63 | |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
64 class NoCompatiblePubSubServerFound(Exception): |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
65 pass |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
66 |
471 | 67 class BadAccessTypeError(Exception): |
68 pass | |
69 | |
70 class BadAccessListError(Exception): | |
71 pass | |
72 | |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
73 class UnknownType(Exception): |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
74 pass |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
75 |
307 | 76 class GroupBlog(): |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
77 """This class use a SàT PubSub Service to manage access on microblog""" |
307 | 78 |
79 def __init__(self, host): | |
80 info(_("Group blog plugin initialization")) | |
81 self.host = host | |
82 | |
471 | 83 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='', |
84 method=self.sendGroupBlog) | |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
85 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
86 host.bridge.addMethod("getLastGroupBlogs", ".plugin", |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
87 in_sign='sis', out_sign='aa{ss}', |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
88 method=self.getLastGroupBlogs, |
471 | 89 async = True) |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
90 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
91 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
92 in_sign='sasis', out_sign='a{saa{ss}}', |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
93 method=self.getMassiveLastGroupBlogs, |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
94 async = True) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
95 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
96 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='', |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
97 method=self.subscribeGroupBlog, |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
98 async = True) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
99 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
100 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='', |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
101 method=self.massiveSubscribeGroupBlogs, |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
102 async = True) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
103 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
104 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
105 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
106 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
107 def getHandler(self, profile): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
108 return GroupBlog_handler() |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
109 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
110 @defer.inlineCallbacks |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
111 def initialise(self, profile_key): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
112 """Check that this data for this profile are initialised, and do it else |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
113 @param client: client of the profile |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
114 @profile_key: %(doc_profile)s""" |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
115 profile = self.host.memory.getProfileName(profile_key) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
116 if not profile: |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
117 error(_("Unknown profile")) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
118 raise Exception("Unknown profile") |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
119 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
120 client = self.host.getClient(profile) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
121 if not client: |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
122 error(_('No client for this profile key: %s') % profile_key) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
123 raise Exception("Unknown profile") |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
124 yield client.client_initialized #we want to be sure that the client is initialized |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
125 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
126 #we first check that we have a item-access pubsub server |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
127 if not hasattr(client,"item_access_pubsub"): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
128 debug(_('Looking for item-access power pubsub server')) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
129 #we don't have any pubsub server featuring item access yet |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
130 client.item_access_pubsub = None |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
131 client._item_access_pubsub_pending = defer.Deferred() |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
132 for entity in self.host.memory.getServerServiceEntities("pubsub", "service", profile): |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
133 _disco = yield client.disco.requestInfo(entity) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
134 #if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
135 if set([NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
136 info(_("item-access powered pubsub service found: [%s]") % entity.full()) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
137 client.item_access_pubsub = entity |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
138 client._item_access_pubsub_pending.callback(None) |
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
139 |
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
140 if hasattr(client,"_item_access_pubsub_pending"): |
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
141 #XXX: we need to wait for item access pubsub service check |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
142 yield client._item_access_pubsub_pending |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
143 del client._item_access_pubsub_pending |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
144 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
145 if not client.item_access_pubsub: |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
146 error(_("No item-access powered pubsub server found, can't use group blog")) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
147 raise NoCompatiblePubSubServerFound |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
148 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
149 defer.returnValue((profile, client)) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
150 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
151 def pubSubItemsReceivedTrigger(self, event, profile): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
152 """"Trigger which catch groupblogs events""" |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
153 if event.nodeIdentifier.startswith(NS_NODE_PREFIX): |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
154 publisher = jid.JID(event.nodeIdentifier[len(NS_NODE_PREFIX):]) |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
155 origin_host = publisher.host.split('.') |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
156 event_host = event.sender.host.split('.') |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
157 #FIXME: basic origin check, must be improved |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
158 #TODO: automatic security test |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
159 if (not (origin_host) |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
160 or len(event_host) < len(origin_host) |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
161 or event_host[-len(origin_host):] != origin_host): |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
162 warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender), |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
163 unicode(publisher))) |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
164 return |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
165 for item in event.items: |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
166 microblog_data = self.item2gbdata(item) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
167 |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
168 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
169 return False |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
170 return True |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
171 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
172 |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
173 def _parseAccessData(self, microblog_data, item): |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
174 form_elts = filter(lambda elt: elt.name == "x", item.children) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
175 for form_elt in form_elts: |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
176 form = data_form.Form.fromElement(form_elt) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
177 |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
178 if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG): |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
179 access_model = form.get(OPT_ACCESS_MODEL, 'open') |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
180 if access_model == "roster": |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
181 try: |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
182 microblog_data["groups"] = '\n'.join(form.fields[OPT_ROSTER_GROUPS_ALLOWED].values) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
183 except KeyError: |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
184 warning("No group found for roster access-model") |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
185 microblog_data["groups"] = '' |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
186 |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
187 break |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
188 |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
189 def item2gbdata(self, item): |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
190 """ Convert item to microblog data dictionary + add access data """ |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
191 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
192 self._parseAccessData(microblog_data, item) |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
193 return microblog_data |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
194 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
195 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
196 def getNodeName(self, publisher): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
197 """Retrieve the name of publisher's node |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
198 @param publisher: publisher's jid |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
199 @return: node's name (string)""" |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
200 return NS_NODE_PREFIX + publisher.userhost() |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
201 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
202 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
203 |
471 | 204 def _publishMblog(self, service, client, access_type, access_list, message): |
307 | 205 """Actually publish the message on the group blog |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
206 @param service: jid of the item-access pubsub service |
471 | 207 @param client: SatXMPPClient of the published |
208 @param access_type: one of "PUBLIC", "GROUP", "JID" | |
209 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item | |
307 | 210 @param message: message to publish |
471 | 211 """ |
311
0aa6ca6cdbdd
plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents:
310
diff
changeset
|
212 mblog_item = self.host.plugins["XEP-0277"].data2entry({'content':message}, client.profile) |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
213 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) |
471 | 214 if access_type == "PUBLIC": |
215 if access_list: | |
216 raise BadAccessListError("access_list must be empty for PUBLIC access") | |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
217 access = data_form.Field(None, OPT_ACCESS_MODEL, value="open") |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
218 form.addField(access) |
471 | 219 elif access_type == "GROUP": |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
220 access = data_form.Field(None, OPT_ACCESS_MODEL, value="roster") |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
221 allowed = data_form.Field(None, OPT_ROSTER_GROUPS_ALLOWED, values=access_list) |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
222 form.addField(access) |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
223 form.addField(allowed) |
471 | 224 mblog_item.addChild(form.toElement()) |
225 elif access_type == "JID": | |
226 raise NotImplementedError | |
227 else: | |
228 error(_("Unknown access_type")) | |
229 raise BadAccessTypeError | |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
230 defer_blog = self.host.plugins["XEP-0060"].publish(service, self.getNodeName(client.jid), items=[mblog_item], profile_key=client.profile) |
307 | 231 defer_blog.addErrback(self._mblogPublicationFailed) |
232 | |
233 def _mblogPublicationFailed(self, failure): | |
234 #TODO | |
471 | 235 return failure |
307 | 236 |
471 | 237 def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'): |
238 """Publish a microblog with given item access | |
239 @param access_type: one of "PUBLIC", "GROUP", "JID" | |
240 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, | |
241 list of groups or list of jids) for this item | |
307 | 242 @param message: microblog |
243 @profile_key: %(doc_profile)s | |
244 """ | |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
245 print "sendGroupBlog" |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
246 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
247 profile, client = result |
471 | 248 if access_type == "PUBLIC": |
249 if access_list: | |
250 raise Exception("Publishers list must be empty when getting microblogs for all contacts") | |
251 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message) | |
252 elif access_type == "GROUP": | |
253 _groups = set(access_list).intersection(client.roster.getGroups()) #We only keep group which actually exist | |
254 if not _groups: | |
255 raise BadAccessListError("No valid group") | |
256 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message) | |
257 elif access_type == "JID": | |
258 raise NotImplementedError | |
259 else: | |
260 error(_("Unknown access type")) | |
261 raise BadAccessTypeError | |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
262 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
263 self.initialise(profile_key).addCallback(initialised) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
264 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
265 |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
266 |
470
5c916b99d0f6
plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents:
467
diff
changeset
|
267 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'): |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
268 """Get the last published microblogs |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
269 @param pub_jid: jid of the publisher |
471 | 270 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
271 @param profile_key: profile key |
471 | 272 @return: list of microblog data (dict) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
273 """ |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
274 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
275 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
276 profile, client = result |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
277 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
278 max_items=max_items, profile_key=profile_key) |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
279 d.addCallback(lambda items: map(self.item2gbdata, items)) |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
280 d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !) |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
281 return d |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
282 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
283 #TODO: we need to use the server corresponding the the host of the jid |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
284 return self.initialise(profile_key).addCallback(initialised) |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
285 |
470
5c916b99d0f6
plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents:
467
diff
changeset
|
286 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'): |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
287 """Get the last published microblogs for a list of groups or jids |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
288 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
289 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
290 @param max_items: how many microblogs we want to get |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
291 @param profile_key: profile key |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
292 """ |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
293 def sendResult(result): |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
294 """send result of DeferredList (list of microblogs to the calling method""" |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
295 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
296 ret = {} |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
297 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
298 for (success, value) in result: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
299 if success: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
300 source_jid, data = value |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
301 ret[source_jid] = data |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
302 |
470
5c916b99d0f6
plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents:
467
diff
changeset
|
303 return ret |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
304 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
305 def initialised(result): |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
306 profile, client = result |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
307 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
308 if publishers_type == "ALL": |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
309 contacts = client.roster.getItems() |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
310 jids = [contact.jid.userhost() for contact in contacts] |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
311 elif publishers_type == "GROUP": |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
312 jids = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
313 for _group in publishers: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
314 jids.extend(client.roster.getJidsFromGroup(_group)) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
315 elif publishers_type == 'JID': |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
316 jids = publishers |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
317 else: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
318 raise UnknownType |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
319 |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
320 mblogs = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
321 |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
322 for _jid in jids: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
323 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
324 max_items=max_items, profile_key=profile_key) |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
325 d.addCallback(lambda items, source_jid: (source_jid, map(self.item2gbdata, items)), _jid) |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
326 mblogs.append(d) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
327 dlist = defer.DeferredList(mblogs) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
328 dlist.addCallback(sendResult) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
329 |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
330 return dlist |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
331 |
470
5c916b99d0f6
plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents:
467
diff
changeset
|
332 |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
333 #TODO: custom exception |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
334 if publishers_type not in ["GROUP", "JID", "ALL"]: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
335 raise Exception("Bad call, unknown publishers_type") |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
336 if publishers_type=="ALL" and publishers: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
337 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
338 return self.initialise(profile_key).addCallback(initialised) |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
339 #TODO: we need to use the server corresponding the the host of the jid |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
340 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
341 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT'): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
342 def initialised(result): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
343 profile, client = result |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
344 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
345 profile_key=profile_key) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
346 return d |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
347 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
348 #TODO: we need to use the server corresponding the the host of the jid |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
349 return self.initialise(profile_key).addCallback(initialised) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
350 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
351 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
352 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@'): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
353 """Subscribe microblogs for a list of groups or jids |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
354 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
355 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
356 @param profile_key: profile key |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
357 """ |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
358 def initialised(result): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
359 profile, client = result |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
360 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
361 if publishers_type == "ALL": |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
362 contacts = client.roster.getItems() |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
363 jids = [contact.jid.userhost() for contact in contacts] |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
364 elif publishers_type == "GROUP": |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
365 jids = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
366 for _group in publishers: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
367 jids.extend(client.roster.getJidsFromGroup(_group)) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
368 elif publishers_type == 'JID': |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
369 jids = publishers |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
370 else: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
371 raise UnknownType |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
372 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
373 mblogs = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
374 for _jid in jids: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
375 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
376 profile_key=profile_key) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
377 mblogs.append(d) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
378 dlist = defer.DeferredList(mblogs) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
379 return dlist |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
380 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
381 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
382 #TODO: custom exception |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
383 if publishers_type not in ["GROUP", "JID", "ALL"]: |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
384 raise Exception("Bad call, unknown publishers_type") |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
385 if publishers_type=="ALL" and publishers: |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
386 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
387 return self.initialise(profile_key).addCallback(initialised) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
388 #TODO: we need to use the server corresponding the the host of the jid |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
389 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
390 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
391 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
392 class GroupBlog_handler(XMPPHandler): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
393 implements(iwokkel.IDisco) |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
394 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
395 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
396 return [disco.DiscoFeature(NS_GROUPBLOG)] |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
397 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
398 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
399 return [] |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
400 |