changeset 809:743b757777d3

core: security limit in menus
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:32:39 +0100 (2014-02-04)
parents d035c662b357
children b11df74e49d2
files src/core/sat_main.py src/plugins/plugin_xep_0050.py src/plugins/plugin_xep_0055.py src/plugins/plugin_xep_0100.py
diffstat 4 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/sat_main.py	Tue Feb 04 18:32:33 2014 +0100
+++ b/src/core/sat_main.py	Tue Feb 04 18:32:39 2014 +0100
@@ -893,7 +893,7 @@
             /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open")))
         @param callback: method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback]
         @param security_limit: %(doc_security_limit)s
-            /!\ security_limit MUST be added to data in launchCallback if used
+            /!\ security_limit MUST be added to data in launchCallback if used #TODO
         @param help_string: string used to indicate what the menu do (can be show as a tooltip).
             /!\ use D_() instead of _() for translations
         @param type: one of:
@@ -932,7 +932,7 @@
 
         return callback_id
 
-    def getMenus(self, language='', security_limit = NO_SECURITY_LIMIT):
+    def getMenus(self, language='', security_limit=NO_SECURITY_LIMIT):
         """Return all menus registered
         @param language: language used for translation, or empty string for default
         @param security_limit: %(doc_security_limit)s
@@ -947,6 +947,9 @@
         for menu_id, menu_data in self._menus.iteritems():
             type_ = menu_data['type']
             path = menu_data['path']
+            menu_security_limit = menu_data['security_limit']
+            if security_limit!=NO_SECURITY_LIMIT and (menu_security_limit==NO_SECURITY_LIMIT or menu_security_limit>security_limit):
+                continue
             languageSwitch(language)
             path_i18n = [_(elt) for elt in path]
             languageSwitch()
--- a/src/plugins/plugin_xep_0050.py	Tue Feb 04 18:32:33 2014 +0100
+++ b/src/plugins/plugin_xep_0050.py	Tue Feb 04 18:32:39 2014 +0100
@@ -212,7 +212,7 @@
                               method=self._requestCommandsList,
                               async=True)
         self.__requesting_id = host.registerCallback(self._requestingEntity, with_data=True)
-        host.importMenu((D_("Service"), D_("commands")), self._commandsMenu, help_string=D_("Execute ad-hoc commands"))
+        host.importMenu((D_("Service"), D_("commands")), self._commandsMenu, security_limit=4, help_string=D_("Execute ad-hoc commands"))
 
     def getHandler(self, profile):
         return XEP_0050_handler(self)
--- a/src/plugins/plugin_xep_0055.py	Tue Feb 04 18:32:33 2014 +0100
+++ b/src/plugins/plugin_xep_0055.py	Tue Feb 04 18:32:39 2014 +0100
@@ -53,7 +53,7 @@
         self._sessions = Sessions()
         self.__menu_cb_id = host.registerCallback(self._menuCb, with_data=True)
         self.__search_request_id = host.registerCallback(self._xmluiSearchRequest, with_data=True)
-        host.importMenu((D_("Communication"), D_("Search directory")), self._searchMenu, help_string=D_("Search use directory"))
+        host.importMenu((D_("Communication"), D_("Search directory")), self._searchMenu, security_limit=1, help_string=D_("Search use directory"))
 
     def _menuCb(self, data, profile):
         entity = jid.JID(data[xml_tools.SAT_FORM_PREFIX+'jid'])
--- a/src/plugins/plugin_xep_0100.py	Tue Feb 04 18:32:33 2014 +0100
+++ b/src/plugins/plugin_xep_0100.py	Tue Feb 04 18:32:39 2014 +0100
@@ -62,7 +62,7 @@
         host.bridge.addMethod("gatewayRegister", ".plugin", in_sign='ss', out_sign='s', method=self._gatewayRegister)
         self.__menu_id = host.registerCallback(self._gatewaysMenu, with_data=True)
         self.__selected_id = host.registerCallback(self._gatewaySelectedCb, with_data=True)
-        host.importMenu((D_("Service"), D_("gateways")), self._gatewaysMenu, help_string=D_("Find gateways"))
+        host.importMenu((D_("Service"), D_("gateways")), self._gatewaysMenu, security_limit=2, help_string=D_("Find gateways"))
 
 
     def _gatewaysMenu(self, data, profile):