plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
This commit is contained in:
parent
73bd9e0755
commit
da7965bb5f
1 changed files with 28 additions and 4 deletions
|
|
@ -139,7 +139,7 @@ class GroupBlog():
|
||||||
|
|
||||||
if hasattr(client,"_item_access_pubsub_pending"):
|
if hasattr(client,"_item_access_pubsub_pending"):
|
||||||
#XXX: we need to wait for item access pubsub service check
|
#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
|
del client._item_access_pubsub_pending
|
||||||
|
|
||||||
if not client.item_access_pubsub:
|
if not client.item_access_pubsub:
|
||||||
|
|
@ -155,6 +155,7 @@ class GroupBlog():
|
||||||
origin_host = publisher.host.split('.')
|
origin_host = publisher.host.split('.')
|
||||||
event_host = event.sender.host.split('.')
|
event_host = event.sender.host.split('.')
|
||||||
#FIXME: basic origin check, must be improved
|
#FIXME: basic origin check, must be improved
|
||||||
|
#TODO: automatic security test
|
||||||
if (not (origin_host)
|
if (not (origin_host)
|
||||||
or len(event_host) < len(origin_host)
|
or len(event_host) < len(origin_host)
|
||||||
or event_host[-len(origin_host):] != origin_host):
|
or event_host[-len(origin_host):] != origin_host):
|
||||||
|
|
@ -162,12 +163,35 @@ class GroupBlog():
|
||||||
unicode(publisher)))
|
unicode(publisher)))
|
||||||
return
|
return
|
||||||
for item in event.items:
|
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)
|
self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", microblog_data, profile)
|
||||||
return False
|
return False
|
||||||
return True
|
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):
|
def getNodeName(self, publisher):
|
||||||
"""Retrieve the name of publisher's node
|
"""Retrieve the name of publisher's node
|
||||||
|
|
@ -252,7 +276,7 @@ class GroupBlog():
|
||||||
profile, client = result
|
profile, client = result
|
||||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
|
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)
|
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 !)
|
d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
@ -298,7 +322,7 @@ class GroupBlog():
|
||||||
for _jid in jids:
|
for _jid in jids:
|
||||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
|
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
|
||||||
max_items=max_items, profile_key=profile_key)
|
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)
|
mblogs.append(d)
|
||||||
dlist = defer.DeferredList(mblogs)
|
dlist = defer.DeferredList(mblogs)
|
||||||
dlist.addCallback(sendResult)
|
dlist.addCallback(sendResult)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue