Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 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 | b5befe7722d3 |
children | f8276bd8baf6 |
comparison
equal
deleted
inserted
replaced
2285:688ff67d6ae9 | 2286:330f8d4e2ad4 |
---|---|
534 else: | 534 else: |
535 raise e | 535 raise e |
536 else: | 536 else: |
537 if access == self._p.ACCESS_WHITELIST: | 537 if access == self._p.ACCESS_WHITELIST: |
538 # for whitelist access we need to copy affiliations from parent item | 538 # for whitelist access we need to copy affiliations from parent item |
539 parent_affiliations = yield self._p.getNodeAffiliations(client, service, node) | 539 comments_affiliations = yield self._p.getNodeAffiliations(client, service, node) |
540 yield self._p.setNodeAffiliations(client, comments_service, comments_node, parent_affiliations) | 540 # …except for "member", that we transform to publisher |
541 # because we wants members to be able to write to comments | |
542 for jid_, affiliation in comments_affiliations.items(): | |
543 if affiliation == 'member': | |
544 comments_affiliations[jid_] == 'publisher' | |
545 | |
546 yield self._p.setNodeAffiliations(client, comments_service, comments_node, comments_affiliations) | |
541 | 547 |
542 if comments_service is None: | 548 if comments_service is None: |
543 comments_service = client.jid.userhostJID() | 549 comments_service = client.jid.userhostJID() |
544 | 550 |
545 if 'comments' in mb_data: | 551 if 'comments' in mb_data: |
593 def _mbGet(self, service='', node='', max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): | 599 def _mbGet(self, service='', node='', max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): |
594 """ | 600 """ |
595 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit | 601 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
596 @param item_ids (list[unicode]): list of item IDs | 602 @param item_ids (list[unicode]): list of item IDs |
597 """ | 603 """ |
604 client = self.host.getClient(profile_key) | |
598 service = jid.JID(service) if service else None | 605 service = jid.JID(service) if service else None |
599 max_items = None if max_items == C.NO_LIMIT else max_items | 606 max_items = None if max_items == C.NO_LIMIT else max_items |
600 extra = self._p.parseExtra(extra_dict) | 607 extra = self._p.parseExtra(extra_dict) |
601 return self.mbGet(service, node or None, max_items or None, item_ids, extra.rsm_request, extra.extra, profile_key) | 608 return self.mbGet(client, service, node or None, None if max_items==C.NO_LIMIT else None, item_ids, extra.rsm_request, extra.extra) |
602 | 609 |
603 | 610 |
604 @defer.inlineCallbacks | 611 @defer.inlineCallbacks |
605 def mbGet(self, service=None, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): | 612 def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None, rsm_request=None, extra=None): |
606 """Get some microblogs | 613 """Get some microblogs |
607 | 614 |
608 @param service(jid.JID, None): jid of the publisher | 615 @param service(jid.JID, None): jid of the publisher |
609 None to get profile's PEP | 616 None to get profile's PEP |
610 @param node(unicode, None): node to get (or microblog node if None) | 617 @param node(unicode, None): node to get (or microblog node if None) |
611 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit | 618 @param max_items(int): maximum number of item to get, None for no limit |
612 @param item_ids (list[unicode]): list of item IDs | 619 @param item_ids (list[unicode]): list of item IDs |
613 @param rsm_request (rsm.RSMRequest): RSM request data | 620 @param rsm_request (rsm.RSMRequest): RSM request data |
614 @param extra (dict): extra data | 621 @param extra (dict): extra data |
615 @param profile_key: %(doc_profile_key)s | |
616 | 622 |
617 @return: a deferred couple with the list of items and metadatas. | 623 @return: a deferred couple with the list of items and metadatas. |
618 """ | 624 """ |
619 if node is None: | 625 if node is None: |
620 node = NS_MICROBLOG | 626 node = NS_MICROBLOG |
621 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) | 627 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) |
622 serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata) | 628 serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata) |
623 defer.returnValue(serialised) | 629 defer.returnValue(serialised) |
624 | 630 |
625 def parseCommentUrl(self, node_url): | 631 def parseCommentUrl(self, node_url): |
626 """Parse a XMPP URI | 632 """Parse a XMPP URI |
796 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit | 802 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
797 """ | 803 """ |
798 max_items = None if max_items == C.NO_LIMIT else max_items | 804 max_items = None if max_items == C.NO_LIMIT else max_items |
799 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) | 805 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
800 extra = self._p.parseExtra(extra_dict) | 806 extra = self._p.parseExtra(extra_dict) |
801 return self.mbGetFromMany(publishers_type, publishers, max_items or None, extra.rsm_request, extra.extra, profile_key) | 807 return self.mbGetFromMany(publishers_type, publishers, None if max_items==C.NO_LIMIT else max_items, extra.rsm_request, extra.extra, profile_key) |
802 | 808 |
803 def mbGetFromMany(self, publishers_type, publishers, max_items=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): | 809 def mbGetFromMany(self, publishers_type, publishers, max_items=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): |
804 """Get the published microblogs for a list of groups or jids | 810 """Get the published microblogs for a list of groups or jids |
805 | 811 |
806 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") | 812 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
853 max_items = None if max_items == C.NO_LIMIT else max_items | 859 max_items = None if max_items == C.NO_LIMIT else max_items |
854 max_comments = None if max_comments == C.NO_LIMIT else max_comments | 860 max_comments = None if max_comments == C.NO_LIMIT else max_comments |
855 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) | 861 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
856 extra = self._p.parseExtra(extra_dict) | 862 extra = self._p.parseExtra(extra_dict) |
857 extra_comments = self._p.parseExtra(extra_comments_dict) | 863 extra_comments = self._p.parseExtra(extra_comments_dict) |
858 return self.mbGetFromManyWithComments(publishers_type, publishers, max_items or None, max_comments or None, | 864 return self.mbGetFromManyWithComments(publishers_type, publishers, None if max_items==C.NO_LIMIT else max_items, max_comments or None, |
859 extra.rsm_request, | 865 extra.rsm_request, |
860 extra.extra, | 866 extra.extra, |
861 extra_comments.rsm_request, | 867 extra_comments.rsm_request, |
862 extra_comments.extra, | 868 extra_comments.extra, |
863 profile_key) | 869 profile_key) |