Mercurial > libervia-backend
changeset 1662:9aa2a703e460
plugin group blog: group permissions are used if "group*" keys are found in mbdata (in data2entry and comments trigger)
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Nov 2015 16:21:18 +0100 |
parents | 96ee986dab3c |
children | 47224056ce5c |
files | src/plugins/plugin_misc_groupblog.py |
diffstat | 1 files changed, 52 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py Tue Nov 24 16:21:18 2015 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Tue Nov 24 16:21:18 2015 +0100 @@ -28,6 +28,7 @@ from wokkel import disco, data_form, iwokkel from wokkel import rsm from zope.interface import implements +from tools import common # import uuid try: @@ -48,7 +49,7 @@ ACCESS_TYPE_MAP = { 'PUBLIC': 'open', 'GROUP': 'roster', 'JID': None, #JID is not yet managed - } + } MAX_ITEMS = 5 MAX_COMMENTS = 5 @@ -60,10 +61,9 @@ "type": "MISC", "protocols": [], "dependencies": ["XEP-0277"], - "recommendations": ["XEP-0059"], "main": "GroupBlog", "handler": "yes", - "description": _("""Implementation of microblogging with roster access""") + "description": _("""Implementation of microblogging fine permissions""") } @@ -88,32 +88,33 @@ def __init__(self, host): log.info(_("Group blog plugin initialization")) self.host = host + self._p = self.host.plugins["XEP-0060"] - host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='', - method=self.sendGroupBlog, - async=True) + # host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='', + # method=self.sendGroupBlog, + # async=True) - host.bridge.addMethod("deleteGroupBlog", ".plugin", in_sign='(sss)ss', out_sign='', - method=self.deleteGroupBlog, - async=True) + # host.bridge.addMethod("deleteGroupBlog", ".plugin", in_sign='(sss)ss', out_sign='', + # method=self.deleteGroupBlog, + # async=True) - host.bridge.addMethod("updateGroupBlog", ".plugin", in_sign='(sss)ssa{ss}s', out_sign='', - method=self.updateGroupBlog, - async=True) + # host.bridge.addMethod("updateGroupBlog", ".plugin", in_sign='(sss)ssa{ss}s', out_sign='', + # method=self.updateGroupBlog, + # async=True) - host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='', - method=self.sendGroupBlogComment, - async=True) + # host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='', + # method=self.sendGroupBlogComment, + # async=True) # host.bridge.addMethod("getGroupBlogs", ".plugin", # in_sign='sasa{ss}bs', out_sign='(aa{ss}a{ss})', # method=self.getGroupBlogs, # async=True) - host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", - in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})', - method=self.getGroupBlogsWithComments, - async=True) + # host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", + # in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})', + # method=self.getGroupBlogsWithComments, + # async=True) # host.bridge.addMethod("getMassiveGroupBlogs", ".plugin", # in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}', @@ -130,6 +131,8 @@ # async=True) # host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) + host.trigger.add("XEP-0277_data2entry", self._data2entryTrigger) + host.trigger.add("XEP-0277_comments", self._commentsTrigger) ## plugin management methods ## @@ -140,7 +143,7 @@ def profileConnected(self, profile): client = self.host.getClient(profile) try: - yield self.host.checkFeatures((NS_PUBSUB_GROUPBLOG, NS_PUBSUB_AUTO_CREATE), profile=profile) + yield self.host.checkFeatures((NS_PUBSUB_GROUPBLOG,), profile=profile) except exceptions.FeatureNotFound: client.server_groupblog_available = False log.warning(_(u"Server is not able to manage item-access pubsub, we can't use group blog")) @@ -162,6 +165,35 @@ log.error("Service should be available !") return {} + def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): + """Build fine access permission if needed + + This trigger check if "group*" key are present, + and create a fine item config to restrict view to these groups + """ + groups = list(common.dict2iter('group', mb_data)) + if not groups: + return + if not client.server_groupblog_available: + raise exceptions.CancelError(u"GroupBlog is not available") + log.debug(u"This entry use group blog") + form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) + # FIXME: ACCESS_ROSTER need to be changed to a new ACCESS_PUBLISHER_ROSTER when available + access = data_form.Field(None, self._p.OPT_ACCESS_MODEL, value=self._p.ACCESS_ROSTER) + allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups) + form.addField(access) + form.addField(allowed) + item_elt.addChild(form.toElement()) + + def _commentsTrigger(self, client, mb_data, options): + """This method is called when a comments node is about to be created + + It changes the access mode to roster if needed, and give the authorized groups + """ + if "group" in mb_data: + # FIXME: ACCESS_ROSTER need to be changed to a new ACCESS_PUBLISHER_ROSTER when available + options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_ROSTER + options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = list(common.dict2iter('group', mb_data)) @defer.inlineCallbacks def _initialise(self, profile_key):