comparison mod_invites_adhoc/mod_invites_adhoc.lua @ 4767:ea93b204104e

mod_invites_adhoc: Allow role-based permissions to override default policy
author Matthew Wild <mwild1@gmail.com>
date Tue, 09 Nov 2021 11:39:18 +0000
parents abac64f71698
children 8b6fe33d1c9b
comparison
equal deleted inserted replaced
4766:abac64f71698 4767:ea93b204104e
38 name = "expire"; 38 name = "expire";
39 label = "Invite valid until"; 39 label = "Invite valid until";
40 }, 40 },
41 }); 41 });
42 42
43 -- This is for checking if username (on the current host) 43 -- This is for checking if the specified JID may create invites
44 -- may create invites that allow people to register accounts 44 -- that allow people to register accounts on this host.
45 -- on this host.
46 local function may_invite_new_users(jid) 45 local function may_invite_new_users(jid)
47 if allow_user_invites then
48 return true;
49 end
50 if usermanager.get_roles then 46 if usermanager.get_roles then
51 local user_roles = usermanager.get_roles(jid, module.host); 47 local user_roles = usermanager.get_roles(jid, module.host);
52 if not user_roles then return; end 48 if not user_roles then return; end
53 if user_roles["prosody:admin"] then 49 if user_roles["prosody:admin"] then
54 return true; 50 return true;
55 elseif deny_user_invite_roles then 51 end
56 for denied_role in deny_user_invite_roles do 52 if allow_user_invite_roles then
57 if user_roles[denied_role] then
58 return false;
59 end
60 end
61 elseif allow_user_invite_roles then
62 for allowed_role in allow_user_invite_roles do 53 for allowed_role in allow_user_invite_roles do
63 if user_roles[allowed_role] then 54 if user_roles[allowed_role] then
64 return true; 55 return true;
65 end 56 end
66 end 57 end
67 end 58 end
68 elseif usermanager.is_admin(jid, module.host) then 59 if deny_user_invite_roles then
69 return true; 60 for denied_role in deny_user_invite_roles do
61 if user_roles[denied_role] then
62 return false;
63 end
64 end
65 end
66 elseif usermanager.is_admin(jid, module.host) then -- COMPAT w/0.11
67 return true; -- Admins may always create invitations
70 end 68 end
71 return false; 69 -- No role matches, so whatever the default is
70 return allow_user_invites;
72 end 71 end
73 72
74 module:depends("adhoc"); 73 module:depends("adhoc");
75 74
76 -- This command is available to all local users, even if allow_user_invites = false 75 -- This command is available to all local users, even if allow_user_invites = false