plugins/mod_authz_internal.lua
author Jonas Schäfer <jonas@wielicki.name>
Mon, 22 Mar 2021 21:24:43 +0100
changeset 11476 c32753ceb0f0
parent 10663 8f95308c3c45
child 11478 8fba807e5256
permissions -rw-r--r--
mod_authz_internal: add support for setting roles of a local user

local normalize = require "util.jid".prep;
local admin_jids = module:get_option_inherited_set("admins", {}) / normalize;
local host = module.host;
local role_store = module:open_store("roles");

local admin_role = { ["prosody:admin"] = true };

function get_user_roles(user)
	if admin_jids:contains(user.."@"..host) then
		return admin_role;
	end
	return role_store:get(user);
end

function set_user_roles(user, roles)
	role_store:set(user, roles)
	return true;
end

function get_jid_roles(jid)
	if admin_jids:contains(jid) then
		return admin_role;
	end
	return nil;
end

function set_jid_roles(jid)
	return false;
end