Software /
code /
prosody
Changeset
11473:afe80b64e209
usermanager: expose set_roles through API
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Mon, 22 Mar 2021 21:24:57 +0100 |
parents | 11472:c32753ceb0f0 |
children | 11474:8fba807e5256 |
files | core/usermanager.lua |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/usermanager.lua Mon Mar 22 21:24:43 2021 +0100 +++ b/core/usermanager.lua Mon Mar 22 21:24:57 2021 +0100 @@ -158,6 +158,23 @@ 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 @@ get_sasl_handler = get_sasl_handler; get_provider = get_provider; get_roles = get_roles; + set_roles = set_roles; is_admin = is_admin; };