# HG changeset patch # User Kim Alvefur # Date 1680167140 -7200 # Node ID 16b47c3b44f3bf56b0f2872fbc41ed34feaab56f # Parent 3e454af3615d790a84969c6248109dee15d40b02 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. diff -r 3e454af3615d -r 16b47c3b44f3 plugins/mod_invites_register.lua --- 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