# HG changeset patch # User Goffi # Date 1351554882 -3600 # Node ID 07f369ed39885d8af53a68431b417686c1ab7261 # Parent 52ab19ea940e69532bfa0fb5290a9b265e11e8d4 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data diff -r 52ab19ea940e -r 07f369ed3988 src/plugins/plugin_misc_groupblog.py --- a/src/plugins/plugin_misc_groupblog.py Sun Oct 28 18:40:14 2012 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Tue Oct 30 00:54:42 2012 +0100 @@ -139,7 +139,7 @@ if hasattr(client,"_item_access_pubsub_pending"): #XXX: we need to wait for item access pubsub service check - ignore = yield client._item_access_pubsub_pending + yield client._item_access_pubsub_pending del client._item_access_pubsub_pending if not client.item_access_pubsub: @@ -155,6 +155,7 @@ origin_host = publisher.host.split('.') event_host = event.sender.host.split('.') #FIXME: basic origin check, must be improved + #TODO: automatic security test if (not (origin_host) or len(event_host) < len(origin_host) or event_host[-len(origin_host):] != origin_host): @@ -162,12 +163,35 @@ unicode(publisher))) return for item in event.items: - microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item) + microblog_data = self.item2gbdata(item) + self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile) return False return True + def _parseAccessData(self, microblog_data, item): + form_elts = filter(lambda elt: elt.name == "x", item.children) + for form_elt in form_elts: + form = data_form.Form.fromElement(form_elt) + + if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG): + access_model = form.get(OPT_ACCESS_MODEL, 'open') + if access_model == "roster": + try: + microblog_data["groups"] = '\n'.join(form.fields[OPT_ROSTER_GROUPS_ALLOWED].values) + except KeyError: + warning("No group found for roster access-model") + microblog_data["groups"] = '' + + break + + def item2gbdata(self, item): + """ Convert item to microblog data dictionary + add access data """ + microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item) + self._parseAccessData(microblog_data, item) + return microblog_data + def getNodeName(self, publisher): """Retrieve the name of publisher's node @@ -252,7 +276,7 @@ profile, client = result d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), max_items=max_items, profile_key=profile_key) - d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items)) + d.addCallback(lambda items: map(self.item2gbdata, items)) d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !) return d @@ -298,7 +322,7 @@ for _jid in jids: d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), max_items=max_items, profile_key=profile_key) - d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid) + d.addCallback(lambda items, source_jid: (source_jid, map(self.item2gbdata, items)), _jid) mblogs.append(d) dlist = defer.DeferredList(mblogs) dlist.addCallback(sendResult)