Software / code / prosody
Comparison
plugins/mod_invites_register.lua @ 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 |
| parent | 12977:74b9e05af71e |
| child | 13843:87dd8639f08f |
comparison
equal
deleted
inserted
replaced
| 13010:3e454af3615d | 13011:16b47c3b44f3 |
|---|---|
| 145 end | 145 end |
| 146 | 146 |
| 147 if validated_invite.additional_data then | 147 if validated_invite.additional_data then |
| 148 module:log("debug", "Importing roles from invite"); | 148 module:log("debug", "Importing roles from invite"); |
| 149 local roles = validated_invite.additional_data.roles; | 149 local roles = validated_invite.additional_data.roles; |
| 150 if roles then | 150 if roles and roles[1] ~= nil then |
| 151 local um = require "prosody.core.usermanager"; | |
| 152 local ok, err = um.set_user_role(event.username, module.host, roles[1]); | |
| 153 if not ok then | |
| 154 module:log("error", "Could not set role %s for newly registered user %s: %s", roles[1], event.username, err); | |
| 155 end | |
| 156 for i = 2, #roles do | |
| 157 local ok, err = um.add_user_secondary_role(event.username, module.host, roles[i]); | |
| 158 if not ok then | |
| 159 module:log("warn", "Could not add secondary role %s for newly registered user %s: %s", roles[i], event.username, err); | |
| 160 end | |
| 161 end | |
| 162 elseif roles and type(next(roles)) == "string" then | |
| 163 module:log("warn", "Invite carries legacy, migration required for user '%s' for role set %q to take effect", event.username, roles); | |
| 151 module:open_store("roles"):set(contact_username, roles); | 164 module:open_store("roles"):set(contact_username, roles); |
| 152 end | 165 end |
| 153 end | 166 end |
| 154 end); | 167 end); |
| 155 | 168 |