comparison mod_invites_adhoc/mod_invites_adhoc.lua @ 5000:8b6fe33d1c9b

mod_invites_adhoc: Update for Prosody's new role API (backwards-compatible)
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 Jul 2022 11:23:55 +0100
parents ea93b204104e
children fa99279f9d40
comparison
equal deleted inserted replaced
4999:65cdbbf9703a 5000:8b6fe33d1c9b
11 -- Who can see and use the contact invite command. It is strongly recommended to 11 -- Who can see and use the contact invite command. It is strongly recommended to
12 -- keep this available to all local users. To allow/disallow invite-registration 12 -- keep this available to all local users. To allow/disallow invite-registration
13 -- on the server, use the option above instead. 13 -- on the server, use the option above instead.
14 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); 14 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true);
15 15
16 -- These options are deprecated since module:may()
16 local allow_user_invite_roles = module:get_option_set("allow_user_invites_by_roles"); 17 local allow_user_invite_roles = module:get_option_set("allow_user_invites_by_roles");
17 local deny_user_invite_roles = module:get_option_set("deny_user_invites_by_roles"); 18 local deny_user_invite_roles = module:get_option_set("deny_user_invites_by_roles");
19
20 if module.may then
21 if allow_user_invites then
22 module:default_permission("prosody:user", ":invite-new-users");
23 end
24 if not allow_user_invite_roles:empty() or not deny_user_invite_roles:empty() then
25 return error("allow_user_invites_by_roles and deny_user_invites_by_roles are deprecated options");
26 end
27 end
18 28
19 local invites; 29 local invites;
20 if prosody.shutdown then -- COMPAT hack to detect prosodyctl 30 if prosody.shutdown then -- COMPAT hack to detect prosodyctl
21 invites = module:depends("invites"); 31 invites = module:depends("invites");
22 end 32 end
40 }, 50 },
41 }); 51 });
42 52
43 -- This is for checking if the specified JID may create invites 53 -- This is for checking if the specified JID may create invites
44 -- that allow people to register accounts on this host. 54 -- that allow people to register accounts on this host.
45 local function may_invite_new_users(jid) 55 local function may_invite_new_users(jid, context)
46 if usermanager.get_roles then 56 if module.may then
57 return module:may(":invite-new-users", context);
58 elseif usermanager.get_roles then -- COMPAT w/0.12
47 local user_roles = usermanager.get_roles(jid, module.host); 59 local user_roles = usermanager.get_roles(jid, module.host);
48 if not user_roles then return; end 60 if not user_roles then return; end
49 if user_roles["prosody:admin"] then 61 if user_roles["prosody:admin"] then
50 return true; 62 return true;
51 end 63 end
85 error = { 97 error = {
86 message = "This command is only available to users of "..module.host; 98 message = "This command is only available to users of "..module.host;
87 }; 99 };
88 }; 100 };
89 end 101 end
90 local invite = invites.create_contact(username, may_invite_new_users(data.from), { 102 local invite = invites.create_contact(username, may_invite_new_users(data.from, data), {
91 source = data.from 103 source = data.from
92 }); 104 });
93 --TODO: check errors 105 --TODO: check errors
94 return { 106 return {
95 status = "completed"; 107 status = "completed";