From fbbb08142502c80159b8113dbb7229ab435e2705 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 14 Nov 2015 19:21:56 +0100 Subject: [PATCH] backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument --- frontends/src/quick_frontend/quick_app.py | 2 +- src/bridge/DBus.py | 8 ++++---- src/bridge/bridge_constructor/bridge_template.ini | 13 +++++++++++-- src/core/constants.py | 5 +++++ src/core/sat_main.py | 5 +++-- src/plugins/plugin_misc_watched.py | 2 +- src/tools/xml_tools.py | 9 +++++---- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index b4542117..0cd3c6f7 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -464,7 +464,7 @@ class QuickApp(object): self.contact_lists[profile].clearContacts() self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) - def actionNewHandler(self, action_data, id_, profile): + def actionNewHandler(self, action_data, id_, security_limit, profile): self.actionManager(action_data, profile=profile) def newContactHandler(self, jid_s, attributes, groups, profile): diff --git a/src/bridge/DBus.py b/src/bridge/DBus.py index 4c34ff6a..2545a8ce 100755 --- a/src/bridge/DBus.py +++ b/src/bridge/DBus.py @@ -126,8 +126,8 @@ class DbusObject(dbus.service.Object): pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='a{ss}ss') - def actionNew(self, action_data, id, profile): + signature='a{ss}sis') + def actionNew(self, action_data, id, security_limit, profile): pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, @@ -590,8 +590,8 @@ class DBusBridge(Bridge): self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) - def actionNew(self, action_data, id, profile): - self.dbus_bridge.actionNew(action_data, id, profile) + def actionNew(self, action_data, id, security_limit, profile): + self.dbus_bridge.actionNew(action_data, id, security_limit, profile) def actionResult(self, answer_type, id, data, profile): self.dbus_bridge.actionResult(answer_type, id, data, profile) diff --git a/src/bridge/bridge_constructor/bridge_template.ini b/src/bridge/bridge_constructor/bridge_template.ini index 9fd24969..ae633b62 100644 --- a/src/bridge/bridge_constructor/bridge_template.ini +++ b/src/bridge/bridge_constructor/bridge_template.ini @@ -112,14 +112,23 @@ doc_param_3=%(doc_profile)s [actionNew] type=signal category=core -sig_in=a{ss}ss +sig_in=a{ss}sis doc=A frontend action is requested doc_param_0=action_data: a dict where key can be: - xmlui: a XMLUI need to be displayed + - progress: a progress id + - meta_*: meta information on the action, used to make automation more easy, + some are defined below + - meta_from_jid: origin of the request + - meta_type: type of the request, can be one of: + - C.META_TYPE_FILE: a file transfer request validation + - C.META_TYPE_OVERWRITE: a file overwriting confirmation + - meta_progress_id: progress id linked to this action doc_param_1=id: action id This id can be used later by frontends to announce to other ones That the action is managed and can now be ignored. -doc_param_2=%(doc_profile)s +doc_param_2=%(doc_security_limit)s +doc_param_3=%(doc_profile)s [actionResult] deprecated= diff --git a/src/core/constants.py b/src/core/constants.py index a018ecf1..877d5c29 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -211,6 +211,11 @@ class Const(object): LOG_LEVELS = (LOG_LVL_DEBUG, LOG_LVL_INFO, LOG_LVL_WARNING, LOG_LVL_ERROR, LOG_LVL_CRITICAL) + ## action constants ## + META_TYPE_FILE = "file" + META_TYPE_OVERWRITE = "overwrite" + + ## HARD-CODED ACTIONS IDS (generated with uuid.uuid4) ## AUTHENTICATE_PROFILE_ID = u'b03bbfa8-a4ae-4734-a248-06ce6c7cf562' CHANGE_XMPP_PASSWD_ID = u'878b9387-de2b-413b-950f-e424a147bcd0' diff --git a/src/core/sat_main.py b/src/core/sat_main.py index 09d8a85b..c1f460b1 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -785,14 +785,15 @@ class SAT(service.Service): del client._waiting_conf[conf_id] cb(conf_id, accepted, data, profile) - def actionNew(self, action_data, profile): + def actionNew(self, action_data, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): """Shortcut to bridge.actionNew which generate and id @param action_data(dict): action data (see bridge documentation) + @param security_limit: %(doc_security_limit)s @param profile: %(doc_profile)s """ id_ = unicode(uuid.uuid4()) - self.bridge.actionNew(action_data, id_, profile) + self.bridge.actionNew(action_data, id_, security_limit, profile) def registerProgressCb(self, progress_id, callback, profile): """Register a callback called when progress is requested for id""" diff --git a/src/plugins/plugin_misc_watched.py b/src/plugins/plugin_misc_watched.py index 00d76dc1..a2ea3136 100755 --- a/src/plugins/plugin_misc_watched.py +++ b/src/plugins/plugin_misc_watched.py @@ -76,6 +76,6 @@ class Watched(object): if old_show == C.PRESENCE_UNAVAILABLE: watched = self.host.memory.getParamA(NAME, CATEGORY, profile_key=profile) if entity in watched or entity.userhostJID() in watched: - self.host.actionNew({'xmlui': xml_tools.note(_(NOTIF).format(entity=entity.full())).toXml()}, profile) + self.host.actionNew({'xmlui': xml_tools.note(_(NOTIF).format(entity=entity.full())).toXml()}, profile=profile) return True diff --git a/src/tools/xml_tools.py b/src/tools/xml_tools.py index d72644ef..00b1d658 100644 --- a/src/tools/xml_tools.py +++ b/src/tools/xml_tools.py @@ -1249,12 +1249,13 @@ def note(message, title='', level=C.XMLUI_DATA_LVL_INFO): ) return note_xmlui -def deferXMLUI(host, xmlui, profile): +def deferXMLUI(host, xmlui, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): """Create a deferred linked to XMLUI @param xmlui(XMLUI): instance of the XMLUI Must be an XMLUI that you can submit, with submit_id set to '' @param profile: %(doc_profile)s + @param security_limit: %(doc_security_limit)s @return (data): a deferred which fire the data """ assert xmlui.submit_id == '' @@ -1265,10 +1266,10 @@ def deferXMLUI(host, xmlui, profile): return {} xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) - host.actionNew({'xmlui': xmlui.toXml()}, profile) + host.actionNew({'xmlui': xmlui.toXml()}, profile=profile) return xmlui_d -def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, profile=None): +def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): """Create a submitable dialog and manage it with a deferred @param message(unicode): message to display @@ -1283,7 +1284,7 @@ def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CON if options is not None: dialog_opt.update(options) dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='') - return deferXMLUI(host, dialog, profile) + return deferXMLUI(host, dialog, security_limit, profile) def deferConfirm(*args, **kwargs): """call deferDialog and return a boolean instead of the whole data dict"""