1 local usermanager = require "core.usermanager"; |
1 local usermanager = require "core.usermanager"; |
2 |
2 |
|
3 local it = require "util.iterators"; |
3 local json = require "util.json"; |
4 local json = require "util.json"; |
4 local st = require "util.stanza"; |
5 local st = require "util.stanza"; |
5 local array = require "util.array"; |
6 local array = require "util.array"; |
6 local statsmanager = require "core.statsmanager"; |
7 local statsmanager = require "core.statsmanager"; |
7 |
8 |
176 if ok and nick_item then |
177 if ok and nick_item then |
177 display_name = nick_item:get_child_text("nick", xmlns_nick); |
178 display_name = nick_item:get_child_text("nick", xmlns_nick); |
178 end |
179 end |
179 end |
180 end |
180 |
181 |
181 local roles = array(); |
182 local primary_role, secondary_roles, legacy_roles; |
182 local roles_map = usermanager.get_user_roles(username, module.host); |
183 if usermanager.get_user_role then |
183 for role_name in pairs(roles_map) do |
184 primary_role = usermanager.get_user_role(username, module.host); |
184 roles:push(role_name); |
185 secondary_roles = array.collect(it.keys(usermanager.get_user_secondary_roles(username, module.host))); |
|
186 elseif usermanager.get_user_roles then -- COMPAT w/0.12 |
|
187 legacy_roles = array(); |
|
188 local roles_map = usermanager.get_user_roles(username, module.host); |
|
189 for role_name in pairs(roles_map) do |
|
190 legacy_roles:push(role_name); |
|
191 end |
185 end |
192 end |
186 |
193 |
187 return { |
194 return { |
188 username = username; |
195 username = username; |
189 display_name = display_name; |
196 display_name = display_name; |
190 roles = roles; |
197 role = primary_role and primary_role.name or nil; |
|
198 secondary_roles = secondary_roles; |
|
199 roles = legacy_roles; -- COMPAT w/0.12 |
191 }; |
200 }; |
192 end |
201 end |
193 |
202 |
194 local function get_session_debug_info(session) |
203 local function get_session_debug_info(session) |
195 local info = { |
204 local info = { |
407 }) then |
416 }) then |
408 final_user.display_name = new_user.display_name; |
417 final_user.display_name = new_user.display_name; |
409 end |
418 end |
410 end |
419 end |
411 |
420 |
412 if new_user.roles then |
421 if new_user.role then |
|
422 if not usermanager.set_user_role then |
|
423 return 500, "feature-not-implemented"; |
|
424 end |
|
425 if not usermanager.set_user_role(username, module.host, new_user.role) then |
|
426 module:log("error", "failed to set role %s for %s", new_user.role, username); |
|
427 return 500; |
|
428 end |
|
429 end |
|
430 |
|
431 if new_user.roles then -- COMPAT w/0.12 |
413 if not usermanager.set_user_roles then |
432 if not usermanager.set_user_roles then |
414 return 500, "feature-not-implemented" |
433 return 500, "feature-not-implemented" |
415 end |
434 end |
416 |
435 |
417 local backend_roles = {}; |
436 local backend_roles = {}; |