Software /
code /
prosody
Comparison
plugins/mod_authz_internal.lua @ 12663:cf88f6b03942
mod_authz_internal: Expose convenience method to test if user can assume role
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 18 Aug 2022 10:37:59 +0100 |
parent | 12662:07424992d7fc |
child | 12730:427dd01f0864 |
comparison
equal
deleted
inserted
replaced
12662:07424992d7fc | 12663:cf88f6b03942 |
---|---|
177 stored_roles._default = nil; | 177 stored_roles._default = nil; |
178 for role_name in pairs(stored_roles) do | 178 for role_name in pairs(stored_roles) do |
179 stored_roles[role_name] = role_registry[role_name]; | 179 stored_roles[role_name] = role_registry[role_name]; |
180 end | 180 end |
181 return stored_roles; | 181 return stored_roles; |
182 end | |
183 | |
184 function user_can_assume_role(user, role_name) | |
185 local primary_role = get_user_role(user); | |
186 if primary_role and primary_role.role_name == role_name then | |
187 return true; | |
188 end | |
189 local secondary_roles = get_user_secondary_roles(user); | |
190 if secondary_roles and secondary_roles[role_name] then | |
191 return true; | |
192 end | |
193 return false; | |
182 end | 194 end |
183 | 195 |
184 -- This function is *expensive* | 196 -- This function is *expensive* |
185 function get_users_with_role(role_name) | 197 function get_users_with_role(role_name) |
186 local function role_filter(username, default_role) --luacheck: ignore 212/username | 198 local function role_filter(username, default_role) --luacheck: ignore 212/username |