add check.command.permission and check.command.authenticated callbacks
This commit is contained in:
parent
e4a5bd01e9
commit
14c30c4c05
2 changed files with 21 additions and 11 deletions
|
@ -150,13 +150,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
raise ConfigSettingInexistent()
|
raise ConfigSettingInexistent()
|
||||||
|
|
||||||
@utils.hook("received.command.c", alias_of="config")
|
@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):
|
def config(self, event):
|
||||||
"""
|
|
||||||
:help: Change config options
|
|
||||||
:usage: <context>[:name] [-][setting [value]]
|
|
||||||
"""
|
|
||||||
|
|
||||||
arg_count = len(event["args_split"])
|
arg_count = len(event["args_split"])
|
||||||
context_desc, _, name = event["args_split"][0].partition(":")
|
context_desc, _, name = event["args_split"][0].partition(":")
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
raise utils.EventError("Unknown subcommand %s" % subcommand)
|
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")
|
@utils.hook("preprocess.command")
|
||||||
def preprocess_command(self, event):
|
def preprocess_command(self, event):
|
||||||
allowed = None
|
allowed = None
|
||||||
|
@ -326,9 +332,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
allowed = self._has_permission(event["user"], permission)
|
allowed = self._has_permission(event["user"], permission)
|
||||||
elif authenticated:
|
elif authenticated:
|
||||||
allowed = self._is_identified(event["user"])
|
allowed = self._is_identified(event["user"])
|
||||||
|
|
||||||
if not allowed == None:
|
|
||||||
if allowed:
|
|
||||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
|
||||||
else:
|
else:
|
||||||
return utils.consts.PERMISSION_ERROR, NO_PERMISSION
|
return
|
||||||
|
|
||||||
|
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"]))
|
||||||
|
|
Loading…
Reference in a new issue