Software /
code /
prosody
Changeset
13011:16b47c3b44f3
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 30 Mar 2023 11:05:40 +0200 |
parents | 13010:3e454af3615d |
children | 13012:c2616274bef7 |
files | plugins/mod_invites_register.lua |
diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_invites_register.lua Wed Mar 29 17:15:33 2023 +0100 +++ b/plugins/mod_invites_register.lua Thu Mar 30 11:05:40 2023 +0200 @@ -147,7 +147,20 @@ 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