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.
This commit is contained in:
Goffi 2017-06-29 20:57:12 +02:00
commit b1b39a636e

View file

@ -36,6 +36,7 @@ PLUGIN_INFO = {
C.PI_TYPE: "EXP",
C.PI_PROTOCOLS: [],
C.PI_DEPENDENCIES: ["XEP-0060"],
C.PI_RECOMMENDATIONS: ["INVITATIONS", "XEP-0277"],
C.PI_MAIN: "Events",
C.PI_HANDLER: "no",
C.PI_DESCRIPTION: _("""Experimental implementation of XMPP events management""")
@ -51,6 +52,8 @@ class Events(object):
log.info(_(u"Event plugin initialization"))
self.host = host
self._p = self.host.plugins["XEP-0060"]
self._i = self.host.plugins.get("INVITATIONS")
self._b = self.host.plugins.get("XEP-0277")
host.bridge.addMethod("eventGet", ".plugin",
in_sign='ssss', out_sign='(ia{ss})',
method=self._eventGet,
@ -71,6 +74,9 @@ class Events(object):
in_sign='ssa{ss}s', out_sign='',
method=self._eventInviteeSet,
async=True)
host.bridge.addMethod("eventInvite", ".plugin", in_sign='sssssssssss', out_sign='',
method=self._invite,
async=True)
def _eventGet(self, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
service = jid.JID(service) if service else None
@ -91,7 +97,6 @@ class Events(object):
location: location of the event
image: URL of a picture to use to represent event
background-image: URL of a picture to use in background
an empty dict is returned if nothing has been answered yed
"""
if not id_:
id_ = NS_EVENT
@ -314,3 +319,59 @@ class Events(object):
pass
item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt)
return self._p.publish(client, service, node, items=[item_elt])
def _invite(self, service, node, id_=NS_EVENT, email=u'', name=u'', host_name=u'', language=u'', url_template=u'',
message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
kwargs = {u'profile': client.profile}
for key in ("email", "name", "host_name", "language", "url_template", "message_subject", "message_body"):
value = locals()[key]
kwargs[key] = unicode(value)
return self.invite(client,
jid.JID(service) if service else None,
node,
id_ or NS_EVENT,
**kwargs)
@defer.inlineCallbacks
def invite(self, client, service, node, id_=NS_EVENT, **kwargs):
"""High level method to create an email invitation to an event
@param service(unicode, None): PubSub service
@param node(unicode): PubSub node of the event
@param id_(unicode): id_ with even data
"""
if self._i is None:
raise exceptions.FeatureNotFound(_(u'"Invitations" plugin is needed for this feature'))
if self._b is None:
raise exceptions.FeatureNotFound(_(u'"XEP-0277" (blog) plugin is needed for this feature'))
event_service = (service or client.jid.userhostJID())
event_uri = uri_parse.buildXMPPUri('pubsub',
path=event_service.full(),
node=node,
item=id_)
kwargs['extra'] = {u'event_uri': event_uri}
invitation_data = yield self._i.create(**kwargs)
invitee_jid = invitation_data[u'jid']
log.debug(_(u'invitation created'))
yield self._p.setNodeAffiliations(client, event_service, node, {invitee_jid: u'member'})
log.debug(_(u'affiliation set on event node'))
dummy, event_data = yield self.eventGet(client, service, node, id_)
log.debug(_(u'got event data'))
invitees_service = jid.JID(event_data['invitees_service'])
invitees_node = event_data['invitees_node']
blog_service = jid.JID(event_data['blog_service'])
blog_node = event_data['blog_node']
yield self._p.setNodeAffiliations(client, invitees_service, invitees_node, {invitee_jid: u'publisher'})
log.debug(_(u'affiliation set on invitee node'))
yield self._p.setNodeAffiliations(client, blog_service, blog_node, {invitee_jid: u'member'})
# FIXME: what follow is crazy, we have no good way to handle comments affiliations for blog
blog_items, dummy = yield self._b.mbGet(client, blog_service, blog_node, None)
for item in blog_items:
comments_service = jid.JID(item['comments_service'])
comments_node = item['comments_node']
yield self._p.setNodeAffiliations(client, comments_service, comments_node, {invitee_jid: u'publisher'})
log.debug(_(u'affiliation set on blog and comments nodes'))