From 281c514ae4de51666753a19e93eae1626827201f Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 23 Mar 2017 21:04:01 +0100 Subject: [PATCH] jp (pubsub): added affiliations and node/affiliations/get: affiliations allow to retrieve all node were a profile is affiliated on a service, or the affiliation on a specific node. node/affiliations/get is for node owner and allow to retrieve who is affiliated with a node and which kind of affiliation. --- frontends/src/jp/cmd_pubsub.py | 69 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/frontends/src/jp/cmd_pubsub.py b/frontends/src/jp/cmd_pubsub.py index ff4204ee..85bd7ed1 100644 --- a/frontends/src/jp/cmd_pubsub.py +++ b/frontends/src/jp/cmd_pubsub.py @@ -101,8 +101,44 @@ class NodeSet(base.CommandBase): errback=self.psNodeConfigurationSetEb) +class NodeAffiliationsGet(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, help=_(u'retrieve node affiliations (for node owner)')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) + self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', + help=_(u"JID of the PubSub service (default: request profile own pubsub)")) + + def psNodeAffiliationsGetCb(self, affiliations): + self.output(affiliations) + self.host.quit() + + def psNodeAffiliationsGetEb(self, failure_): + self.disp(u"can't get node affiliations: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def start(self): + self.host.bridge.psNodeAffiliationsGet( + self.args.service, + self.args.node, + self.profile, + callback=self.psNodeAffiliationsGetCb, + errback=self.psNodeAffiliationsGetEb) + + +class NodeAffiliations(base.CommandBase): + subcommands = (NodeAffiliationsGet,) + + def __init__(self, host): + super(NodeAffiliations, self).__init__(host, 'affiliations', use_profile=False, help=_(u'set or retrieve node affiliations')) + + class Node(base.CommandBase): - subcommands = (NodeInfo, NodeSet) + subcommands = (NodeInfo, NodeSet, NodeAffiliations) def __init__(self, host): super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling')) @@ -149,8 +185,37 @@ class Get(base.CommandBase): errback=self.psItemGetEb) +class Affiliations(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'affiliations', use_output=C.OUTPUT_DICT, help=_(u'retrieve all affiliations on a service')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("-n", "--node", type=base.unicode_decoder, default=u'', help=_(u"node to request")) + self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', + help=_(u"JID of the PubSub service (default: request profile own pubsub)")) + + def psAffiliationsGetCb(self, affiliations): + self.output(affiliations) + self.host.quit() + + def psAffiliationsGetEb(self, failure_): + self.disp(u"can't get node affiliations: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def start(self): + self.host.bridge.psAffiliationsGet( + self.args.service, + self.args.node, + self.profile, + callback=self.psAffiliationsGetCb, + errback=self.psAffiliationsGetEb) + + class Pubsub(base.CommandBase): - subcommands = (Get, Node) + subcommands = (Get, Node, Affiliations) def __init__(self, host): super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))