changeset 2204:afc703419186

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.
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2017 21:04:01 +0100
parents 427391c706eb
children 582359de7268
files frontends/src/jp/cmd_pubsub.py
diffstat 1 files changed, 67 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_pubsub.py	Thu Mar 23 21:01:51 2017 +0100
+++ b/frontends/src/jp/cmd_pubsub.py	Thu Mar 23 21:04:01 2017 +0100
@@ -101,8 +101,44 @@
             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 @@
             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'))