From 9e47ec37b49c9e55ca64576d12dd12ad259ebe8c Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Thu, 20 Jan 2011 13:22:42 +0100 Subject: Add content request to alias plugin (to get the content of a given node) Catch the permission errors in the plugin and send an error reply --- server/plugin.py | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/server/plugin.py b/server/plugin.py index c3bd81d..1f456ef 100644 --- a/server/plugin.py +++ b/server/plugin.py @@ -16,8 +16,8 @@ class AliasQuery(ElementBase): namespace = 'alias:query' name = 'query' plugin_attrib = 'alias' - interfaces = set(('node', 'type', 'items', 'object')) - sub_interfaces = set(('items')) + interfaces = set(('node', 'type', 'content', 'permission')) + sub_interfaces = set(('content', 'permission')) def addItem(self, node, permission = None): item = AliasItem(None, self) @@ -45,6 +45,14 @@ class AliasPlugin(base.base_plugin): base.base_plugin.post_init(self) self.xmpp.plugin['xep_0030'].add_feature("alias:query") + def send_permission_error(self, iq, message): + node = iq['alias']['node'] + iq.reply() + iq['alias']['type'] = 'error' + iq['alias']['node'] = node + iq['alias']['permission'] = message + iq.send() + def handle_alias_query(self, iq): try: callee = base64.b64decode(iq['to'].user) @@ -58,11 +66,26 @@ class AliasPlugin(base.base_plugin): node = Object(callee, node) if iq['alias']['type'] == 'items': - logging.debug('childs of {} requested'.format(node)) - childs = Object.get_child_list(node, caller) - reply = AliasQuery() - reply['node'] = node.hash - reply['type'] = 'items' - for name, perm in childs: - reply.addItem(name, perm) - iq.reply().set_payload(reply).send() \ No newline at end of file + try: + childs = node.get_child_list(caller) + except PermissionError: + self.send_permission_error(iq, 'Permission') + else: + iq.reply() + iq['alias']['type'] = 'items' + iq['alias']['node'] = node.hash + for name, perm in childs: + iq['alias'].addItem(name, perm) + iq.send() + + if iq['alias']['type'] == 'content': + try: + content = node.get_content(caller) + except PermissionError: + self.send_permission_error(iq, 'Permission') + else: + iq.reply() + iq['alias']['type'] = 'content' + iq['alias']['node'] = node.hash + iq['alias']['content'] = content + iq.send() \ No newline at end of file -- cgit v1.2.3-70-g09d2