annotate src/plugins/plugin_misc_groupblog.py @ 532:db4ae4d18f09

plugin group blog: security check + fixed publisher in personalEvent signal
author Goffi <goffi@goffi.org>
date Sun, 28 Oct 2012 18:27:37 +0100
parents c18e0e108925
children 07f369ed3988
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for microbloging with roster access
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 TYPE_COLLECTION = 'collection'
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 PLUGIN_INFO = {
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "name": "Group blogging throught collections",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "import_name": "groupblog",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "type": "MISC",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "protocols": [],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "dependencies": ["XEP-0277"],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "main": "GroupBlog",
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
60 "handler": "yes",
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "description": _("""Implementation of microblogging with roster access""")
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 }
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
67 class BadAccessTypeError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
68 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
69
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
70 class BadAccessListError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
71 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def __init__(self, host):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 info(_("Group blog plugin initialization"))
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.host = host
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
83 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='',
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
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
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
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
f856575a62a6 plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents: 477
diff changeset
142 ignore = yield client._item_access_pubsub_pending
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
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
158 if (not (origin_host)
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
159 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
160 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
161 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
162 unicode(publisher)))
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
163 return
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
164 for item in event.items:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
165 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item)
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
166 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
167 return False
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
168 return True
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
169
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
170
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 def getNodeName(self, publisher):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
173 """Retrieve the name of publisher's node
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
174 @param publisher: publisher's jid
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
175 @return: node's name (string)"""
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
176 return NS_NODE_PREFIX + publisher.userhost()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
177
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
178
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
179
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
180 def _publishMblog(self, service, client, access_type, access_list, message):
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 """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
182 @param service: jid of the item-access pubsub service
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
183 @param client: SatXMPPClient of the published
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
184 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
185 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 @param message: message to publish
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
187 """
311
0aa6ca6cdbdd plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents: 310
diff changeset
188 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
189 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
190 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
191 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
192 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
193 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
194 form.addField(access)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
195 elif access_type == "GROUP":
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
196 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
197 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
198 form.addField(access)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
199 form.addField(allowed)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
200 mblog_item.addChild(form.toElement())
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
201 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
202 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
203 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
204 error(_("Unknown access_type"))
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
205 raise BadAccessTypeError
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
206 defer_blog = self.host.plugins["XEP-0060"].publish(service, self.getNodeName(client.jid), items=[mblog_item], profile_key=client.profile)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 defer_blog.addErrback(self._mblogPublicationFailed)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209 def _mblogPublicationFailed(self, failure):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 #TODO
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
211 return failure
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
213 def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
214 """Publish a microblog with given item access
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
215 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
216 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS,
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
217 list of groups or list of jids) for this item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218 @param message: microblog
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219 @profile_key: %(doc_profile)s
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220 """
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
221 print "sendGroupBlog"
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
222 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
223 profile, client = result
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
224 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
225 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
226 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
227 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message)
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
228 elif access_type == "GROUP":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
229 _groups = set(access_list).intersection(client.roster.getGroups()) #We only keep group which actually exist
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
230 if not _groups:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
231 raise BadAccessListError("No valid group")
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
232 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message)
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
233 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
234 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
235 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
236 error(_("Unknown access type"))
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
237 raise BadAccessTypeError
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
238
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
239 self.initialise(profile_key).addCallback(initialised)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
240
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
241
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
242
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
243 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
244 """Get the last published microblogs
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
245 @param pub_jid: jid of the publisher
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
246 @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
247 @param profile_key: profile key
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
248 @return: list of microblog data (dict)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
249 """
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
250
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
251 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
252 profile, client = result
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
253 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
254 max_items=max_items, profile_key=profile_key)
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
255 d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
256 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
257 return d
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
258
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
259 #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
260 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
261
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
262 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
263 """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
264 @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
265 @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
266 @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
267 @param profile_key: profile key
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
268 """
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
269 def sendResult(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
270 """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
271
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
272 ret = {}
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
273
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
274 for (success, value) in result:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
275 if success:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
276 source_jid, data = value
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
277 ret[source_jid] = data
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
278
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
279 return ret
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
280
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
281 def initialised(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
282 profile, client = result
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
283
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
284 if publishers_type == "ALL":
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
285 contacts = client.roster.getItems()
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
286 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
287 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
288 jids = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
289 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
290 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
291 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
292 jids = publishers
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
293 else:
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
294 raise UnknownType
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
295
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
296 mblogs = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
297
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
298 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
299 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
300 max_items=max_items, 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
301 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
302 mblogs.append(d)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
303 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
304 dlist.addCallback(sendResult)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
305
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
306 return dlist
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
307
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
308
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
309 #TODO: custom exception
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
310 if publishers_type not in ["GROUP", "JID", "ALL"]:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
311 raise Exception("Bad call, unknown publishers_type")
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
312 if publishers_type=="ALL" and publishers:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
313 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
314 return self.initialise(profile_key).addCallback(initialised)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
315 #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
316
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
317 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT'):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
318 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
319 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
320 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
321 profile_key=profile_key)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
322 return d
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
323
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
324 #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
325 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
326
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
327
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
328 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@'):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
329 """Subscribe microblogs for a list of groups or jids
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
330 @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
331 @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
332 @param profile_key: profile key
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
333 """
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
334 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
335 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
336
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
337 if publishers_type == "ALL":
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
338 contacts = client.roster.getItems()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
339 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
340 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
341 jids = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
342 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
343 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
344 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
345 jids = publishers
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
346 else:
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
347 raise UnknownType
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
348
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
349 mblogs = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
350 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
351 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
352 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
353 mblogs.append(d)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
354 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
355 return dlist
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
356
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 #TODO: custom exception
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
359 if publishers_type not in ["GROUP", "JID", "ALL"]:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
360 raise Exception("Bad call, unknown publishers_type")
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
361 if publishers_type=="ALL" and publishers:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
362 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
363 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
364 #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
365
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
366
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
367
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
368 class GroupBlog_handler(XMPPHandler):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
369 implements(iwokkel.IDisco)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
370
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
371 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
372 return [disco.DiscoFeature(NS_GROUPBLOG)]
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
373
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
374 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
375 return []
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
376