aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-26 15:32:24 +0000
committerGravatar jesopo2019-11-26 15:32:24 +0000
commit14c30c4c054a9f20a4d7374c4d3ebbaa6d9f00cd (patch)
tree9e8629fbb5809908a61c7f9095e2017c35cd44b5 /modules
parentexplicitly use "lxml" for finding page encoding (diff)
signature
add check.command.permission and check.command.authenticated callbacks
Diffstat (limited to 'modules')
-rw-r--r--modules/config.py10
-rw-r--r--modules/permissions/__init__.py22
2 files changed, 21 insertions, 11 deletions
diff --git a/modules/config.py b/modules/config.py
index 0a24e139..48e3eb62 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -150,13 +150,11 @@ class Module(ModuleManager.BaseModule):
raise ConfigSettingInexistent()
@utils.hook("received.command.c", alias_of="config")
- @utils.hook("received.command.config", min_args=1)
+ @utils.hook("received.command.config")
+ @utils.kwarg("min_args", 1)
+ @utils.kwarg("help", "Change config options")
+ @utils.kwarg("usage", "<context>[:name] [-][setting [value]]")
def config(self, event):
- """
- :help: Change config options
- :usage: <context>[:name] [-][setting [value]]
- """
-
arg_count = len(event["args_split"])
context_desc, _, name = event["args_split"][0].partition(":")
diff --git a/modules/permissions/__init__.py b/modules/permissions/__init__.py
index 55cc4a68..20ef55dc 100644
--- a/modules/permissions/__init__.py
+++ b/modules/permissions/__init__.py
@@ -317,6 +317,12 @@ class Module(ModuleManager.BaseModule):
else:
raise utils.EventError("Unknown subcommand %s" % subcommand)
+ def _assert(self, allowed):
+ if allowed:
+ return utils.consts.PERMISSION_FORCE_SUCCESS, None
+ else:
+ return utils.consts.PERMISSION_ERROR, NO_PERMISSION
+
@utils.hook("preprocess.command")
def preprocess_command(self, event):
allowed = None
@@ -326,9 +332,15 @@ class Module(ModuleManager.BaseModule):
allowed = self._has_permission(event["user"], permission)
elif authenticated:
allowed = self._is_identified(event["user"])
+ else:
+ return
- if not allowed == None:
- if allowed:
- return utils.consts.PERMISSION_FORCE_SUCCESS, None
- else:
- return utils.consts.PERMISSION_ERROR, NO_PERMISSION
+ return self._assert(allowed)
+
+ @utils.hook("check.command.permission")
+ def check_permission(self, event):
+ return self._assert(
+ self._has_permission(event["user"], event["request_args"][0]))
+ @utils.hook("check.command.authenticated")
+ def check_authenticated(self, event):
+ return self._assert(self._is_identified(event["user"]))