annotate src/plugins/plugin_exp_events.py @ 2287:ea869f30f204

plugin events: added eventInvite command as a helper for the complex invitation workflow: when this command is used: - an email invitation is sent with the event node set - invitee's jid is affiliated to event - invitee's jid is affiliated to invitee's node as a publisher - invitee's jid is affiliated to blog's node as a member - invitee's jid is affiliated to every blog's item's comments node as a publisher last affiliation complex operation is currently needed because of the way blogs and comments are handled, but this need to be changed in the future with XEP proposal.
author Goffi <goffi@goffi.org>
date Thu, 29 Jun 2017 20:57:12 +0200
parents b5befe7722d3
children c05000d00dbb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin to detect language (experimental)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
21 from sat.core import exceptions
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.constants import Const as C
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.log import getLogger
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
25 from sat.tools import utils
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
26 from sat.tools.common import uri as uri_parse
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.internet import defer
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
28 from twisted.words.protocols.jabber import jid, error
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from twisted.words.xish import domish
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from wokkel import pubsub
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_NAME: "Event plugin",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_IMPORT_NAME: "events",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_TYPE: "EXP",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_PROTOCOLS: [],
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_DEPENDENCIES: ["XEP-0060"],
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
39 C.PI_RECOMMENDATIONS: ["INVITATIONS", "XEP-0277"],
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_MAIN: "Events",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_HANDLER: "no",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_DESCRIPTION: _("""Experimental implementation of XMPP events management""")
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 NS_EVENT = 'org.salut-a-toi.event:0'
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 class Events(object):
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 """Q&D module to handle event attendance answer, experimentation only"""
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def __init__(self, host):
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 log.info(_(u"Event plugin initialization"))
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.host = host
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self._p = self.host.plugins["XEP-0060"]
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
55 self._i = self.host.plugins.get("INVITATIONS")
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
56 self._b = self.host.plugins.get("XEP-0277")
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 host.bridge.addMethod("eventGet", ".plugin",
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
58 in_sign='ssss', out_sign='(ia{ss})',
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 method=self._eventGet,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 async=True)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
61 host.bridge.addMethod("eventCreate", ".plugin",
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
62 in_sign='ia{ss}ssss', out_sign='s',
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
63 method=self._eventCreate,
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
64 async=True)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
65 host.bridge.addMethod("eventModify", ".plugin",
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
66 in_sign='sssia{ss}s', out_sign='',
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
67 method=self._eventModify,
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
68 async=True)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
69 host.bridge.addMethod("eventInviteeGet", ".plugin",
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
70 in_sign='sss', out_sign='a{ss}',
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
71 method=self._eventInviteeGet,
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
72 async=True)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
73 host.bridge.addMethod("eventInviteeSet", ".plugin",
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 in_sign='ssa{ss}s', out_sign='',
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
75 method=self._eventInviteeSet,
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 async=True)
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
77 host.bridge.addMethod("eventInvite", ".plugin", in_sign='sssssssssss', out_sign='',
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
78 method=self._invite,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
79 async=True)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
81 def _eventGet(self, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 service = jid.JID(service) if service else None
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 node = node if node else NS_EVENT
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 client = self.host.getClient(profile_key)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
85 return self.eventGet(client, service, node, id_)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
86
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
87 @defer.inlineCallbacks
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
88 def eventGet(self, client, service, node, id_=NS_EVENT):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
89 """Retrieve event data
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
90
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
91 @param service(unicode, None): PubSub service
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
92 @param node(unicode): PubSub node of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
93 @param id_(unicode): id_ with even data
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
94 @return (tuple[int, dict[unicode, unicode]): event data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
95 - timestamp of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
96 - event metadata where key can be:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
97 location: location of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
98 image: URL of a picture to use to represent event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
99 background-image: URL of a picture to use in background
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
100 """
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
101 if not id_:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
102 id_ = NS_EVENT
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
103 items, metadata = yield self._p.getItems(service, node, item_ids=[id_], profile_key=client.profile)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
104 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
105 event_elt = next(items[0].elements(NS_EVENT, u'event'))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
106 except IndexError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
107 raise exceptions.NotFound(_(u"No event with this id has been found"))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
108
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
109 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
110 timestamp = utils.date_parse(next(event_elt.elements(NS_EVENT, "date")))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
111 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
112 timestamp = -1
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
113
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
114 data = {}
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
115
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
116 for key in (u'name',):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
117 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
118 data[key] = event_elt[key]
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
119 except KeyError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
120 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
121
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
122 for elt_name in (u'description',):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
123 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
124 elt = next(event_elt.elements(NS_EVENT, elt_name))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
125 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
126 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
127 else:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
128 data[elt_name] = unicode(elt)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
129
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
130 for elt_name in (u'image', 'background-image'):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
131 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
132 image_elt = next(event_elt.elements(NS_EVENT, elt_name))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
133 data[elt_name] = image_elt['src']
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
134 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
135 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
136 except KeyError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
137 log.warning(_(u'no src found for image'))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
138
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
139 for uri_type in (u'invitees', u'blog'):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
140 try:
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
141 elt = next(event_elt.elements(NS_EVENT, uri_type))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
142 uri = data[uri_type + u'_uri'] = elt['uri']
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
143 uri_data = uri_parse.parseXMPPUri(uri)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
144 if uri_data[u'type'] != u'pubsub':
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
145 raise ValueError
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
146 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
147 log.warning(_(u"no {uri_type} element found!").format(uri_type=uri_type))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
148 except KeyError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
149 log.warning(_(u"incomplete {uri_type} element").format(uri_type=uri_type))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
150 except ValueError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
151 log.warning(_(u"bad {uri_type} element").format(uri_type=uri_type))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
152 else:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
153 data[uri_type + u'_service'] = uri_data[u'path']
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
154 data[uri_type + u'_node'] = uri_data[u'node']
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
155
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
156 for meta_elt in event_elt.elements(NS_EVENT, 'meta'):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
157 key = meta_elt[u'name']
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
158 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
159 log.warning(u'Ignoring conflicting meta element: {xml}'.format(xml=meta_elt.toXml()))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
160 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
161 data[key] = unicode(meta_elt)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
162
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
163 defer.returnValue((timestamp, data))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
164
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
165 def _eventCreate(self, timestamp, data, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
166 service = jid.JID(service) if service else None
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
167 node = node if node else NS_EVENT
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
168 client = self.host.getClient(profile_key)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
169 return self.eventCreate(client, timestamp, data, service, node, id_ or NS_EVENT)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 @defer.inlineCallbacks
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
172 def eventCreate(self, client, timestamp, data, service, node=None, item_id=NS_EVENT):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
173 """Create or replace an event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
174
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
175 @param service(jid.JID, None): PubSub service
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
176 @param node(unicode, None): PubSub node of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
177 None will create instant node.
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
178 @param item_id(unicode): ID of the item to create.
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
179 @param timestamp(timestamp, None)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
180 @param data(dict[unicode, unicode]): data to update
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
181 dict will be cleared, do a copy if data are still needed
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
182 key can be:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
183 - name: name of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
184 - description: details
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
185 - image: main picture of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
186 - background-image: image to use as background
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
187 @return (unicode): created node
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
188 """
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
189 if not item_id:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
190 raise ValueError(_(u"item_id must be set"))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
191 if not service:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
192 service = client.jid.userhostJID()
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
193 event_elt = domish.Element((NS_EVENT, 'event'))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
194 if timestamp is not None and timestamp != -1:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
195 formatted_date = utils.xmpp_date(timestamp)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
196 event_elt.addElement((NS_EVENT, 'date'), content=formatted_date)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
197 for key in (u'name',):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
198 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
199 event_elt[key] = data.pop(key)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
200 for key in (u'description',):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
201 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
202 event_elt.addElement((NS_EVENT, key), content=data.pop(key))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
203 for key in (u'image', u'background-image'):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
204 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
205 elt = event_elt.addElement((NS_EVENT, key))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
206 elt['src'] = data.pop(key)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
207
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
208 # we first create the invitees and blog nodes (if not specified in data)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
209 for uri_type in (u'invitees', u'blog'):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
210 key = uri_type + u'_uri'
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
211 for to_delete in (u'service', u'node'):
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
212 k = uri_type + u'_' + to_delete
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
213 if k in data:
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
214 del data[k]
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
215 if key not in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
216 # FIXME: affiliate invitees
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
217 uri_node = yield self._p.createNode(client, service)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
218 yield self._p.setConfiguration(client, service, uri_node, {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST})
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
219 uri_service = service
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
220 else:
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
221 uri = data.pop(key)
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
222 uri_data = uri_parse.parseXMPPUri(uri)
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
223 if uri_data[u'type'] != u'pubsub':
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
224 raise ValueError(_(u'The given URI is not valid: {uri}').format(uri=uri))
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
225 uri_service = jid.JID(uri_data[u'path'])
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
226 uri_node = uri_data[u'node']
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
227
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
228 elt = event_elt.addElement((NS_EVENT, uri_type))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
229 elt['uri'] = uri_parse.buildXMPPUri('pubsub', path=uri_service.full(), node=uri_node)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
230
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
231 # remaining data are put in <meta> elements
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
232 for key in data.keys():
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
233 elt = event_elt.addElement((NS_EVENT, 'meta'), content = data.pop(key))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
234 elt['name'] = key
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
235
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
236 item_elt = pubsub.Item(id=item_id, payload=event_elt)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
237 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
238 # TODO: check auto-create, no need to create node first if available
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
239 node = yield self._p.createNode(client, service, nodeIdentifier=node)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
240 except error.StanzaError as e:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
241 if e.condition == u'conflict':
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
242 log.debug(_(u"requested node already exists"))
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
243
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2246
diff changeset
244 yield self._p.publish(client, service, node, items=[item_elt])
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
245
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
246 defer.returnValue(node)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
247
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
248 def _eventModify(self, service, node, id_, timestamp_update, data_update, profile_key=C.PROF_KEY_NONE):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
249 service = jid.JID(service) if service else None
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
250 node = node if node else NS_EVENT
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
251 client = self.host.getClient(profile_key)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
252 return self.eventModify(client, service, node, id_ or NS_EVENT, timestamp_update or None, data_update)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
253
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
254 @defer.inlineCallbacks
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
255 def eventModify(self, client, service, node, id_=NS_EVENT, timestamp_update=None, data_update=None):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
256 """Update an event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
257
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
258 Similar as create instead that it update existing item instead of
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
259 creating or replacing it. Params are the same as for [eventCreate].
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
260 """
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
261 event_timestamp, event_metadata = yield self.eventGet(client, service, node, id_)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
262 new_timestamp = event_timestamp if timestamp_update is None else timestamp_update
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
263 new_data = event_metadata
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
264 if data_update:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
265 for k, v in data_update.iteritems():
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
266 new_data[k] = v
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
267 yield self.eventCreate(client, new_timestamp, new_data, service, node, id_)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
268
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
269 def _eventInviteeGet(self, service, node, profile_key):
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
270 service = jid.JID(service) if service else None
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
271 node = node if node else NS_EVENT
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
272 client = self.host.getClient(profile_key)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
273 return self.eventInviteeGet(client, service, node)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
274
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
275 @defer.inlineCallbacks
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
276 def eventInviteeGet(self, client, service, node):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 """Retrieve attendance from event node
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
278
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 @param service(unicode, None): PubSub service
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 @param node(unicode): PubSub node of the event
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 @return (dict): a dict with current attendance status,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 an empty dict is returned if nothing has been answered yed
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 """
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 items, metadata = yield self._p.getItems(service, node, item_ids=[client.jid.userhost()], profile_key=client.profile)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 try:
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
286 event_elt = next(items[0].elements(NS_EVENT, u'invitee'))
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 except IndexError:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 # no item found, event data are not set yet
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 defer.returnValue({})
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 data = {}
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 for key in (u'attend', u'guests'):
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 try:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 data[key] = event_elt[key]
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 except KeyError:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 continue
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 defer.returnValue(data)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
297
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
298 def _eventInviteeSet(self, service, node, event_data, profile_key):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 service = jid.JID(service) if service else None
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 node = node if node else NS_EVENT
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 client = self.host.getClient(profile_key)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
302 return self.eventInviteeSet(client, service, node, event_data)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
304 def eventInviteeSet(self, client, service, node, data):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """Set or update attendance data in event node
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 @param service(unicode, None): PubSub service
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 @param node(unicode): PubSub node of the event
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 @param data(dict[unicode, unicode]): data to update
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 key can be:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 attend: one of "yes", "no", "maybe"
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 guests: an int
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 """
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
314 event_elt = domish.Element((NS_EVENT, 'invitee'))
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 for key in (u'attend', u'guests'):
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 try:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 event_elt[key] = data.pop(key)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 except KeyError:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 pass
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt)
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2246
diff changeset
321 return self._p.publish(client, service, node, items=[item_elt])
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
322
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
323 def _invite(self, service, node, id_=NS_EVENT, email=u'', name=u'', host_name=u'', language=u'', url_template=u'',
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
324 message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE):
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
325 client = self.host.getClient(profile_key)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
326 kwargs = {u'profile': client.profile}
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
327 for key in ("email", "name", "host_name", "language", "url_template", "message_subject", "message_body"):
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
328 value = locals()[key]
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
329 kwargs[key] = unicode(value)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
330 return self.invite(client,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
331 jid.JID(service) if service else None,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
332 node,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
333 id_ or NS_EVENT,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
334 **kwargs)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
335
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
336 @defer.inlineCallbacks
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
337 def invite(self, client, service, node, id_=NS_EVENT, **kwargs):
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
338 """High level method to create an email invitation to an event
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
339
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
340 @param service(unicode, None): PubSub service
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
341 @param node(unicode): PubSub node of the event
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
342 @param id_(unicode): id_ with even data
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
343 """
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
344 if self._i is None:
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
345 raise exceptions.FeatureNotFound(_(u'"Invitations" plugin is needed for this feature'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
346 if self._b is None:
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
347 raise exceptions.FeatureNotFound(_(u'"XEP-0277" (blog) plugin is needed for this feature'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
348 event_service = (service or client.jid.userhostJID())
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
349 event_uri = uri_parse.buildXMPPUri('pubsub',
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
350 path=event_service.full(),
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
351 node=node,
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
352 item=id_)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
353 kwargs['extra'] = {u'event_uri': event_uri}
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
354 invitation_data = yield self._i.create(**kwargs)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
355 invitee_jid = invitation_data[u'jid']
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
356 log.debug(_(u'invitation created'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
357 yield self._p.setNodeAffiliations(client, event_service, node, {invitee_jid: u'member'})
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
358 log.debug(_(u'affiliation set on event node'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
359 dummy, event_data = yield self.eventGet(client, service, node, id_)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
360 log.debug(_(u'got event data'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
361 invitees_service = jid.JID(event_data['invitees_service'])
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
362 invitees_node = event_data['invitees_node']
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
363 blog_service = jid.JID(event_data['blog_service'])
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
364 blog_node = event_data['blog_node']
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
365 yield self._p.setNodeAffiliations(client, invitees_service, invitees_node, {invitee_jid: u'publisher'})
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
366 log.debug(_(u'affiliation set on invitee node'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
367 yield self._p.setNodeAffiliations(client, blog_service, blog_node, {invitee_jid: u'member'})
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
368 # FIXME: what follow is crazy, we have no good way to handle comments affiliations for blog
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
369 blog_items, dummy = yield self._b.mbGet(client, blog_service, blog_node, None)
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
370
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
371 for item in blog_items:
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
372 comments_service = jid.JID(item['comments_service'])
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
373 comments_node = item['comments_node']
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
374 yield self._p.setNodeAffiliations(client, comments_service, comments_node, {invitee_jid: u'publisher'})
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
375 log.debug(_(u'affiliation set on blog and comments nodes'))
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
376
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
377