changeset 2286:330f8d4e2ad4

plugin XEP-0277: change affiliations for comments + fixes: - mbGet now use client instead of profile_key - fixed max_items handling - for whitelist access model, if a comments node is created, "member" affiliations are transformed to "publisher" This is because most of time we want that somebody is able to read a private blog but not write on it, and be able to write a comment.
author Goffi <goffi@goffi.org>
date Thu, 29 Jun 2017 20:45:54 +0200
parents 688ff67d6ae9
children ea869f30f204
files src/plugins/plugin_xep_0277.py
diffstat 1 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Thu Jun 29 20:37:06 2017 +0200
+++ b/src/plugins/plugin_xep_0277.py	Thu Jun 29 20:45:54 2017 +0200
@@ -536,8 +536,14 @@
         else:
             if access == self._p.ACCESS_WHITELIST:
                 # for whitelist access we need to copy affiliations from parent item
-                parent_affiliations = yield self._p.getNodeAffiliations(client, service, node)
-                yield self._p.setNodeAffiliations(client, comments_service, comments_node, parent_affiliations)
+                comments_affiliations = yield self._p.getNodeAffiliations(client, service, node)
+                # …except for "member", that we transform to publisher
+                # because we wants members to be able to write to comments
+                for jid_, affiliation in comments_affiliations.items():
+                    if affiliation == 'member':
+                        comments_affiliations[jid_] == 'publisher'
+
+                yield self._p.setNodeAffiliations(client, comments_service, comments_node, comments_affiliations)
 
         if comments_service is None:
             comments_service = client.jid.userhostJID()
@@ -595,30 +601,30 @@
         @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
         @param item_ids (list[unicode]): list of item IDs
         """
+        client = self.host.getClient(profile_key)
         service = jid.JID(service) if service else None
         max_items = None if max_items == C.NO_LIMIT else max_items
         extra = self._p.parseExtra(extra_dict)
-        return self.mbGet(service, node or None, max_items or None, item_ids, extra.rsm_request, extra.extra, profile_key)
+        return self.mbGet(client, service, node or None, None if max_items==C.NO_LIMIT else None, item_ids, extra.rsm_request, extra.extra)
 
 
     @defer.inlineCallbacks
-    def mbGet(self, service=None, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
+    def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None, rsm_request=None, extra=None):
         """Get some microblogs
 
         @param service(jid.JID, None): jid of the publisher
             None to get profile's PEP
         @param node(unicode, None): node to get (or microblog node if None)
-        @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
+        @param max_items(int): maximum number of item to get, None for no limit
         @param item_ids (list[unicode]): list of item IDs
         @param rsm_request (rsm.RSMRequest): RSM request data
         @param extra (dict): extra data
-        @param profile_key: %(doc_profile_key)s
 
         @return: a deferred couple with the list of items and metadatas.
         """
         if node is None:
             node = NS_MICROBLOG
-        items_data = yield self._p.getItems(service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key)
+        items_data = yield self._p.getItems(service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=client.profile)
         serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata)
         defer.returnValue(serialised)
 
@@ -798,7 +804,7 @@
         max_items = None if max_items == C.NO_LIMIT else max_items
         publishers_type, publishers = self._checkPublishers(publishers_type, publishers)
         extra = self._p.parseExtra(extra_dict)
-        return self.mbGetFromMany(publishers_type, publishers, max_items or None, extra.rsm_request, extra.extra, profile_key)
+        return self.mbGetFromMany(publishers_type, publishers, None if max_items==C.NO_LIMIT else max_items, extra.rsm_request, extra.extra, profile_key)
 
     def mbGetFromMany(self, publishers_type, publishers, max_items=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
         """Get the published microblogs for a list of groups or jids
@@ -855,7 +861,7 @@
         publishers_type, publishers = self._checkPublishers(publishers_type, publishers)
         extra = self._p.parseExtra(extra_dict)
         extra_comments = self._p.parseExtra(extra_comments_dict)
-        return self.mbGetFromManyWithComments(publishers_type, publishers, max_items or None, max_comments or None,
+        return self.mbGetFromManyWithComments(publishers_type, publishers, None if max_items==C.NO_LIMIT else max_items, max_comments or None,
                                               extra.rsm_request,
                                               extra.extra,
                                               extra_comments.rsm_request,