changeset 2246:e8641b7718dc

plugin events: fixed blog/invitees uri handling
author Goffi <goffi@goffi.org>
date Fri, 19 May 2017 13:53:52 +0200
parents e09048cb7595
children 0f3bfe89999e
files src/plugins/plugin_exp_events.py
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_exp_events.py	Fri May 19 12:54:31 2017 +0200
+++ b/src/plugins/plugin_exp_events.py	Fri May 19 13:53:52 2017 +0200
@@ -133,7 +133,7 @@
 
         for uri_type in (u'invitees', u'blog'):
             try:
-                elt = next(event_elt.elements(NS_EVENT, 'invitees'))
+                elt = next(event_elt.elements(NS_EVENT, uri_type))
                 uri = data[uri_type + u'_uri'] = elt['uri']
                 uri_data = uri_parse.parseXMPPUri(uri)
                 if uri_data[u'type'] != u'pubsub':
@@ -203,17 +203,22 @@
         # we first create the invitees and blog nodes (if not specified in data)
         for uri_type in (u'invitees', u'blog'):
             key = uri_type + u'_uri'
+            for to_delete in (u'service', u'node'):
+                k = uri_type + u'_' + to_delete
+                if k in data:
+                    del data[k]
             if key not in data:
                 # FIXME: affiliate invitees
                 uri_node = yield self._p.createNode(client, service)
                 yield self._p.setConfiguration(client, service, uri_node, {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST})
                 uri_service = service
             else:
-                # we suppose that *_service and *_node are present
-                # FIXME: handle cases when they are not
-                uri_service = data.pop(uri_type + u'_service')
-                uri_node = data.pop(uri_type + u'_node')
-                del data[key]
+                uri = data.pop(key)
+                uri_data = uri_parse.parseXMPPUri(uri)
+                if uri_data[u'type'] != u'pubsub':
+                    raise ValueError(_(u'The given URI is not valid: {uri}').format(uri=uri))
+                uri_service = jid.JID(uri_data[u'path'])
+                uri_node = uri_data[u'node']
 
             elt = event_elt.addElement((NS_EVENT, uri_type))
             elt['uri'] = uri_parse.buildXMPPUri('pubsub', path=uri_service.full(), node=uri_node)