Mercurial > prosody-hg
comparison plugins/mod_invites_adhoc.lua @ 12674:72f431b4dc2c
Merge role-auth->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 22 Aug 2022 13:53:35 +0100 |
| parents | 9061f9621330 |
| children | 74b9e05af71e |
comparison
equal
deleted
inserted
replaced
| 12639:6d9ee0a3eb4b | 12674:72f431b4dc2c |
|---|---|
| 1 -- XEP-0401: Easy User Onboarding | 1 -- XEP-0401: Easy User Onboarding |
| 2 local dataforms = require "util.dataforms"; | 2 local dataforms = require "util.dataforms"; |
| 3 local datetime = require "util.datetime"; | 3 local datetime = require "util.datetime"; |
| 4 local split_jid = require "util.jid".split; | 4 local split_jid = require "util.jid".split; |
| 5 local usermanager = require "core.usermanager"; | |
| 6 | 5 |
| 7 local new_adhoc = module:require("adhoc").new; | 6 local new_adhoc = module:require("adhoc").new; |
| 8 | 7 |
| 9 -- Whether local users can invite other users to create an account on this server | 8 -- Whether local users can invite other users to create an account on this server |
| 10 local allow_user_invites = module:get_option_boolean("allow_user_invites", false); | 9 local allow_user_invites = module:get_option_boolean("allow_user_invites", false); |
| 11 -- Who can see and use the contact invite command. It is strongly recommended to | 10 -- 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 | 11 -- keep this available to all local users. To allow/disallow invite-registration |
| 13 -- on the server, use the option above instead. | 12 -- on the server, use the option above instead. |
| 14 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); | 13 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); |
| 15 | 14 |
| 16 local allow_user_invite_roles = module:get_option_set("allow_user_invites_by_roles"); | 15 module:default_permission(allow_user_invites and "prosody:user" or "prosody:admin", ":invite-users"); |
| 17 local deny_user_invite_roles = module:get_option_set("deny_user_invites_by_roles"); | |
| 18 | 16 |
| 19 local invites; | 17 local invites; |
| 20 if prosody.shutdown then -- COMPAT hack to detect prosodyctl | 18 if prosody.shutdown then -- COMPAT hack to detect prosodyctl |
| 21 invites = module:depends("invites"); | 19 invites = module:depends("invites"); |
| 22 end | 20 end |
| 40 }, | 38 }, |
| 41 }); | 39 }); |
| 42 | 40 |
| 43 -- This is for checking if the specified JID may create invites | 41 -- This is for checking if the specified JID may create invites |
| 44 -- that allow people to register accounts on this host. | 42 -- that allow people to register accounts on this host. |
| 45 local function may_invite_new_users(jid) | 43 local function may_invite_new_users(context) |
| 46 if usermanager.get_roles then | 44 return module:may(":invite-users", context); |
| 47 local user_roles = usermanager.get_roles(jid, module.host); | |
| 48 if not user_roles then | |
| 49 -- User has no roles we can check, just return default | |
| 50 return allow_user_invites; | |
| 51 end | |
| 52 | |
| 53 if user_roles["prosody:admin"] then | |
| 54 return true; | |
| 55 end | |
| 56 if allow_user_invite_roles then | |
| 57 for allowed_role in allow_user_invite_roles do | |
| 58 if user_roles[allowed_role] then | |
| 59 return true; | |
| 60 end | |
| 61 end | |
| 62 end | |
| 63 if deny_user_invite_roles then | |
| 64 for denied_role in deny_user_invite_roles do | |
| 65 if user_roles[denied_role] then | |
| 66 return false; | |
| 67 end | |
| 68 end | |
| 69 end | |
| 70 elseif usermanager.is_admin(jid, module.host) then -- COMPAT w/0.11 | |
| 71 return true; -- Admins may always create invitations | |
| 72 end | |
| 73 -- No role matches, so whatever the default is | |
| 74 return allow_user_invites; | |
| 75 end | 45 end |
| 76 | 46 |
| 77 module:depends("adhoc"); | 47 module:depends("adhoc"); |
| 78 | 48 |
| 79 -- This command is available to all local users, even if allow_user_invites = false | 49 -- This command is available to all local users, even if allow_user_invites = false |
| 89 error = { | 59 error = { |
| 90 message = "This command is only available to users of "..module.host; | 60 message = "This command is only available to users of "..module.host; |
| 91 }; | 61 }; |
| 92 }; | 62 }; |
| 93 end | 63 end |
| 94 local invite = invites.create_contact(username, may_invite_new_users(data.from), { | 64 local invite = invites.create_contact(username, may_invite_new_users(data), { |
| 95 source = data.from | 65 source = data.from |
| 96 }); | 66 }); |
| 97 --TODO: check errors | 67 --TODO: check errors |
| 98 return { | 68 return { |
| 99 status = "completed"; | 69 status = "completed"; |
