diff options
author | Jonas Schäfer <jonas@wielicki.name> | 2021-03-22 21:24:57 +0100 |
---|---|---|
committer | Jonas Schäfer <jonas@wielicki.name> | 2021-03-22 21:24:57 +0100 |
commit | 0ca317cd0b62dff77bc48969407efc1d19277c14 (patch) | |
tree | b39560e5fa65abfc7b0daa52a0fe5ada92fa495e | |
parent | 03d38b2a67ad7d210820d94bff9ca1b052e65ab6 (diff) | |
download | prosody-0ca317cd0b62dff77bc48969407efc1d19277c14.tar.gz prosody-0ca317cd0b62dff77bc48969407efc1d19277c14.zip |
usermanager: expose set_roles through API
-rw-r--r-- | core/usermanager.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/usermanager.lua b/core/usermanager.lua index 11707450..b51833cc 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -158,6 +158,23 @@ local function get_roles(jid, host) return roles; end +local function set_roles(jid, host, roles) + if host and not hosts[host] then return false; end + if type(jid) ~= "string" then return false; end + + jid = jid_bare(jid); + host = host or "*"; + + local actor_user, actor_host = jid_split(jid); + + local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider; + if actor_user and actor_host == host then -- Local user + return authz_provider.set_user_roles(actor_user, roles) + else -- Remote entity + return authz_provider.set_jid_roles(jid, roles) + end +end + local function is_admin(jid, host) local roles = get_roles(jid, host); return roles and roles["prosody:admin"]; @@ -176,5 +193,6 @@ return { get_sasl_handler = get_sasl_handler; get_provider = get_provider; get_roles = get_roles; + set_roles = set_roles; is_admin = is_admin; }; |