annotate src/plugins/plugin_misc_groupblog.py @ 616:8782f94e761e

plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
author Goffi <goffi@goffi.org>
date Sun, 16 Jun 2013 18:49:02 +0200
parents 6f4c31192c7c
children dafdbe28ca2f
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
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for microbloging with roster access
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
20 from logging import debug, info, warning, error
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
21 from twisted.internet import defer
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.protocols.jabber import jid
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
23
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
24 from wokkel import disco, data_form, iwokkel
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 zope.interface import implements
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
28 import uuid
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
29 import urllib
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
30
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
31 try:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
32 from twisted.words.protocols.xmlstream import XMPPHandler
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
33 except ImportError:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
34 from wokkel.subprotocols import XMPPHandler
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
36 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
37 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
38 NS_NODE_PREFIX = 'urn:xmpp:groupblog:'
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
39 NS_COMMENT_PREFIX = 'urn:xmpp:comments:'
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
40 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
42 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
43 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
44 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
45 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create"
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 TYPE_COLLECTION = 'collection'
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
47 ACCESS_TYPE_MAP = { 'PUBLIC': 'open',
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
48 'GROUP': 'roster',
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
49 'JID': None, #JID is not yet managed
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
50 }
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
53 "name": "Group blogging throught collections",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
54 "import_name": "groupblog",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
55 "type": "MISC",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
56 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
57 "dependencies": ["XEP-0277"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58 "main": "GroupBlog",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
59 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
60 "description": _("""Implementation of microblogging with roster access""")
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 }
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
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
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
67
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
68 class BadAccessTypeError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
69 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
70
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
71
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
72 class BadAccessListError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
73 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
74
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
75
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
76 class UnknownType(Exception):
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
77 pass
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
78
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
79
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
80 class GroupBlog(object):
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
81 """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
82
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def __init__(self, host):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 info(_("Group blog plugin initialization"))
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.host = host
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
87 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='',
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
88 method=self.sendGroupBlog)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
89
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
90 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='',
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
91 method=self.sendGroupBlogComment,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
92 async=True)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
93
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
94 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
95 in_sign='sis', out_sign='aa{ss}',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
96 method=self.getLastGroupBlogs,
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
97 async=True)
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
98
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
99 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
100 in_sign='sasis', out_sign='a{saa{ss}}',
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
101 method=self.getMassiveLastGroupBlogs,
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
102 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
103
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
104 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
105 method=self.subscribeGroupBlog,
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
106 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
107
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
108 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
109 method=self.massiveSubscribeGroupBlogs,
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
110 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
111
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
112 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
113
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
114 def getHandler(self, profile):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
115 return GroupBlog_handler()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
116
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
117 @defer.inlineCallbacks
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
118 def initialise(self, profile_key):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
119 """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
120 @param client: client of the profile
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
121 @profile_key: %(doc_profile)s"""
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
122 profile = self.host.memory.getProfileName(profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
123 if not profile:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
124 error(_("Unknown profile"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
125 raise Exception("Unknown profile")
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
126
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
127 client = self.host.getClient(profile)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
128 if not client:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
129 error(_('No client for this profile key: %s') % profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
130 raise Exception("Unknown profile")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
131 yield client.client_initialized # we want to be sure that the client is initialized
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
132
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
133 #we first check that we have a item-access pubsub server
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
134 if not hasattr(client, "item_access_pubsub"):
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
135 debug(_('Looking for item-access power pubsub server'))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
136 #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
137 client.item_access_pubsub = None
478
f856575a62a6 plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents: 477
diff changeset
138 client._item_access_pubsub_pending = defer.Deferred()
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
139 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
140 _disco = yield client.disco.requestInfo(entity)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
141 #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
142 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
143 info(_("item-access powered pubsub service found: [%s]") % entity.full())
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
144 client.item_access_pubsub = entity
478
f856575a62a6 plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents: 477
diff changeset
145 client._item_access_pubsub_pending.callback(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
146
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
147 if "_item_access_pubsub_pending" in client:
478
f856575a62a6 plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents: 477
diff changeset
148 #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
149 yield client._item_access_pubsub_pending
478
f856575a62a6 plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents: 477
diff changeset
150 del client._item_access_pubsub_pending
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
151
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
152 if not client.item_access_pubsub:
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
153 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
154 raise NoCompatiblePubSubServerFound
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
155
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
156 defer.returnValue((profile, client))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
157
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
158 def pubSubItemsReceivedTrigger(self, event, profile):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
159 """"Trigger which catch groupblogs events"""
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
160
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
161 if event.nodeIdentifier.startswith(NS_NODE_PREFIX):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
162 # Microblog
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
163 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
164 origin_host = publisher.host.split('.')
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
165 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
166 #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
167 #TODO: automatic security test
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
168 if (not (origin_host)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
169 or len(event_host) < len(origin_host)
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
170 or event_host[-len(origin_host):] != origin_host):
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
171 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
172 unicode(publisher)))
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
173 return
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
174 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
175 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
176
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
177 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
178 return False
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
179 elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
180 # Comment
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
181 for item in event.items:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
182 publisher = "" # FIXME: publisher attribute for item in SàT pubsub is not managed yet, so
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
183 # publisher is not checked and can be easily spoofed. This need to be fixed
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
184 # quickly.
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
185 microblog_data = self.item2gbdata(item, "comment")
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
186 microblog_data["service"] = event.sender.userhost()
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
187 microblog_data["node"] = event.nodeIdentifier
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
188 microblog_data["verified_publisher"] = "true" if publisher else "false"
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
189
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
190 self.host.bridge.personalEvent(publisher.full() if publisher else microblog_data["author"], "MICROBLOG", microblog_data, profile)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
191 return False
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
192 return True
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
193
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
194 def _parseAccessData(self, microblog_data, item):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
195 P = self.host.plugins["XEP-0060"]
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
196 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
197 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
198 form = data_form.Form.fromElement(form_elt)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
199
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
200 if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
201 access_model = form.get(P.OPT_ACCESS_MODEL, 'open')
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
202 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
203 try:
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
204 microblog_data["groups"] = '\n'.join(form.fields[P.OPT_ROSTER_GROUPS_ALLOWED].values)
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
205 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
206 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
207 microblog_data["groups"] = ''
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
208
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
209 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
210
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
211 def item2gbdata(self, item, _type="main_item"):
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
212 """ 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
213 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item)
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
214 microblog_data["type"] = _type
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
215 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
216 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
217
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
218 def getNodeName(self, publisher):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
219 """Retrieve the name of publisher's node
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
220 @param publisher: publisher's jid
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
221 @return: node's name (string)"""
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
222 return NS_NODE_PREFIX + publisher.userhost()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
223
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
224 def _publishMblog(self, service, client, access_type, access_list, message, options):
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
225 """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
226 @param service: jid of the item-access pubsub service
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
227 @param client: SatXMPPClient of the published
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
228 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
229 @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
230 @param message: message to publish
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
231 @param options: dict which option name as key, which can be:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
232 - allow_comments: True to accept comments, False else (default: False)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
233 """
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
234 node_name = self.getNodeName(client.jid)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
235 mblog_data = {'content': message}
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
236 P = self.host.plugins["XEP-0060"]
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
237 access_model_value = ACCESS_TYPE_MAP[access_type]
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
238
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
239 if options.get('allow_comments', 'False').lower() == 'true':
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
240 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
241 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(),
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
242 'query': urllib.urlencode([('node',comments_node.encode('utf-8'))])}
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
243 _options = {P.OPT_ACCESS_MODEL: access_model_value,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
244 P.OPT_PERSIST_ITEMS: 1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
245 P.OPT_MAX_ITEMS: -1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
246 P.OPT_DELIVER_PAYLOADS: 1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
247 P.OPT_SEND_ITEM_SUBSCRIBE: 1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
248 P.OPT_PUBLISH_MODEL: "subscribers", #TODO: should be open if *both* node and item access_model are open (public node and item)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
249 }
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
250 if access_model_value == 'roster':
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
251 _options[P.OPT_ROSTER_GROUPS_ALLOWED] = list(access_list)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
252
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
253 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
254 # already exists, the creation will silently fail, but the comments link will stay the same, linking to a
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
255 # node owned by somebody else)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
256 defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
257
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
258 mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
259 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
260
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
261 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
262 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
263 raise BadAccessListError("access_list must be empty for PUBLIC access")
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
264 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
265 form.addField(access)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
266 elif access_type == "GROUP":
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
267 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
268 allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
269 form.addField(access)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
270 form.addField(allowed)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
271 mblog_item.addChild(form.toElement())
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
272 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
273 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
274 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
275 error(_("Unknown access_type"))
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
276 raise BadAccessTypeError
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
277
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
278 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
279 defer_blog.addErrback(self._mblogPublicationFailed)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
280
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
281 def _mblogPublicationFailed(self, failure):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
282 #TODO
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
283 return failure
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
284
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
285 def sendGroupBlog(self, access_type, access_list, message, options, profile_key='@NONE@'):
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
286 """Publish a microblog with given item access
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
287 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
288 @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
289 list of groups or list of jids) for this item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
290 @param message: microblog
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
291 @param options: dict which option name as key, which can be:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
292 - allow_comments: True to accept comments, False else (default: False)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
293 @profile_key: %(doc_profile)s
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
294 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
295
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
296 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
297 profile, client = result
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
298 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
299 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
300 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
301 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, options)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
302 elif access_type == "GROUP":
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
303 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
304 if not _groups:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
305 raise BadAccessListError("No valid group")
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
306 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, options)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
307 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
308 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
309 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
310 error(_("Unknown access type"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
311 raise BadAccessTypeError
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
312
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
313 self.initialise(profile_key).addCallback(initialised)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
314
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
315 def sendGroupBlogComment(self, node_url, message, profile_key='@DEFAULT@'):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
316 """Publish a comment in the given node
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
317 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
318 @param message: comment
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
319 @profile_key: %(doc_profile)s
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
320 """
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
321 profile = self.host.memory.getProfileName(profile_key)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
322 if not profile:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
323 error(_("Unknown profile"))
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
324 raise Exception("Unknown profile")
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
325
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
326 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
327
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
328 mblog_data = {'content': message}
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
329 mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
330
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
331 return self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
332
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
333 def _itemsConstruction(self, items, pub_jid, client):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
334 """ Transforms items to group blog data and manage comments node
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
335 @param items: iterable of items
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
336 @return: list of group blog data """
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
337 ret = []
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
338 for item in items:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
339 gbdata = self.item2gbdata(item)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
340 ret.append(gbdata)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
341 # if there is a comments node, we subscribe to it
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
342 if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID():
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
343 try:
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
344 self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"],
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
345 profile_key=client.profile)
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
346 self.host.plugins["XEP-0060"].getItems(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], profile_key=client.profile)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
347 except KeyError:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
348 warning("Missing key for comments")
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
349 return ret
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
350
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
351 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@DEFAULT@'):
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
352 """Get the last published microblogs
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
353 @param pub_jid_s: jid of the publisher
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
354 @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
355 @param profile_key: profile key
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
356 @return: list of microblog data (dict)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
357 """
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
358 pub_jid = jid.JID(pub_jid_s)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
359
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
360 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
361 profile, client = result
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
362 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid),
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
363 max_items=max_items, profile_key=profile_key)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
364 d.addCallback(self._itemsConstruction, pub_jid, client)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
365 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
366 return d
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
367
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
368 #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
369 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
370
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
371 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
372 """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
373 @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
374 @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
375 @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
376 @param profile_key: profile key
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
377 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
378
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
379 def sendResult(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
380 """send result of DeferredList (list of microblogs to the calling method"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
381
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
382 ret = {}
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
383
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
384 for (success, value) in result:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
385 if success:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
386 source_jid, data = value
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
387 ret[source_jid] = data
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
388
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
389 return ret
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
390
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
391 def initialised(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
392 profile, client = result
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
393
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
394 if publishers_type == "ALL":
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
395 contacts = client.roster.getItems()
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
396 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
397 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
398 jids = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
399 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
400 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
401 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
402 jids = publishers
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
403 else:
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
404 raise UnknownType
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
405
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
406 mblogs = []
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
407
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
408 for jid_s in jids:
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
409 _jid = jid.JID(jid_s)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
410 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(_jid),
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
411 max_items=max_items, profile_key=profile_key)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
412 d.addCallback(lambda items, source_jid: (source_jid, self._itemsConstruction(items, _jid, client)), jid_s)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
413
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
414 mblogs.append(d)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
415 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
416 dlist.addCallback(sendResult)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
417
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
418 return dlist
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
419
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
420 #TODO: custom exception
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
421 if publishers_type not in ["GROUP", "JID", "ALL"]:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
422 raise Exception("Bad call, unknown publishers_type")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
423 if publishers_type == "ALL" and publishers:
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
424 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
425 return self.initialise(profile_key).addCallback(initialised)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
426 #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
427
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
428 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT@'):
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
429 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
430 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
431 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
432 profile_key=profile_key)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
433 return d
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
434
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
435 #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
436 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
437
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
438 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@'):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
439 """Subscribe microblogs for a list of groups or jids
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
440 @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
441 @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
442 @param profile_key: profile key
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
443 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
444
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
445 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
446 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
447
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
448 if publishers_type == "ALL":
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
449 contacts = client.roster.getItems()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
450 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
451 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
452 jids = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
453 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
454 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
455 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
456 jids = publishers
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
457 else:
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
458 raise UnknownType
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
459
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
460 mblogs = []
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
461 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
462 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
463 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
464 mblogs.append(d)
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
465 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
466 return dlist
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
467
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
468 #TODO: custom exception
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
469 if publishers_type not in ["GROUP", "JID", "ALL"]:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
470 raise Exception("Bad call, unknown publishers_type")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
471 if publishers_type == "ALL" and publishers:
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
472 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
473 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
474 #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
475
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
476
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
477 class GroupBlog_handler(XMPPHandler):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
478 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
479
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
480 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
481 return [disco.DiscoFeature(NS_GROUPBLOG)]
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
482
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
483 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
484 return []