aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-30 11:05:40 +0200
committerKim Alvefur <zash@zash.se>2023-03-30 11:05:40 +0200
commit0d140811589f55eac962980bceed6c33b2f18649 (patch)
tree54775257edd139ff732fd659f7c4760287f8850c
parent24fa8c5d6031de8a3738cc7a7532a831f9fe0775 (diff)
downloadprosody-0d140811589f55eac962980bceed6c33b2f18649.tar.gz
prosody-0d140811589f55eac962980bceed6c33b2f18649.zip
mod_invites_register: Allow roles to be an ordered list, first being primary
Part of an update to mod_invites and friends to the new authz and roles. Invites with roles in the old way will need to be migrated, but with invites often being short lived it is probably not a long-lived problem.
-rw-r--r--plugins/mod_invites_register.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua
index 81bb378e..d9274ce4 100644
--- a/plugins/mod_invites_register.lua
+++ b/plugins/mod_invites_register.lua
@@ -147,7 +147,20 @@ module:hook("user-registered", function (event)
if validated_invite.additional_data then
module:log("debug", "Importing roles from invite");
local roles = validated_invite.additional_data.roles;
- if roles then
+ if roles and roles[1] ~= nil then
+ local um = require "prosody.core.usermanager";
+ local ok, err = um.set_user_role(event.username, module.host, roles[1]);
+ if not ok then
+ module:log("error", "Could not set role %s for newly registered user %s: %s", roles[1], event.username, err);
+ end
+ for i = 2, #roles do
+ local ok, err = um.add_user_secondary_role(event.username, module.host, roles[i]);
+ if not ok then
+ module:log("warn", "Could not add secondary role %s for newly registered user %s: %s", roles[i], event.username, err);
+ end
+ end
+ elseif roles and type(next(roles)) == "string" then
+ module:log("warn", "Invite carries legacy, migration required for user '%s' for role set %q to take effect", event.username, roles);
module:open_store("roles"):set(contact_username, roles);
end
end