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 |