liquid_feedback_frontend
diff app/main/api/_member.lua @ 1504:2a0d86117d54
Added hidden and role units
| author | bsw |
|---|---|
| date | Fri Jul 31 00:18:55 2020 +0200 (2020-07-31) |
| parents | 32cc544d5a5b |
| children |
line diff
1.1 --- a/app/main/api/_member.lua Thu Jul 30 23:15:49 2020 +0200 1.2 +++ b/app/main/api/_member.lua Fri Jul 31 00:18:55 2020 +0200 1.3 @@ -1,5 +1,8 @@ 1.4 local members = param.get("members", "table") 1.5 1.6 +local include_unit_ids = param.get("include_unit_ids", atom.boolean) 1.7 +local include_units = param.get("include_units", atom.boolean) 1.8 +local include_roles = param.get("include_roles", atom.boolean) 1.9 local include_profile = param.get("include_profile", atom.boolean) 1.10 1.11 if include_profile and not app.scopes.read_profiles then 1.12 @@ -19,7 +22,11 @@ 1.13 local r = json.array() 1.14 1.15 if app.scopes.read_identities then 1.16 - 1.17 + 1.18 + if include_unit_ids or include_units or include_roles then 1.19 + members:load("units") 1.20 + end 1.21 + 1.22 if include_profile then 1.23 members:load("profile") 1.24 end 1.25 @@ -35,6 +42,42 @@ 1.26 end 1.27 m[field] = value 1.28 end 1.29 + if include_unit_ids or include_units or include_roles then 1.30 + if include_unit_ids then 1.31 + m.unit_ids = json.array() 1.32 + end 1.33 + if include_units then 1.34 + m.units = json.array() 1.35 + end 1.36 + if include_roles then 1.37 + m.roles = json.object() 1.38 + end 1.39 + for i, unit in ipairs(member.units) do 1.40 + if unit.attr.hidden ~= true then 1.41 + if include_unit_ids then 1.42 + table.insert(m.unit_ids, unit.id) 1.43 + end 1.44 + if include_units then 1.45 + table.insert(m.units, json.object{ 1.46 + id = unit.id, 1.47 + parent_id = unit.parent_id, 1.48 + name = unit.name, 1.49 + description = unit.description 1.50 + }) 1.51 + end 1.52 + end 1.53 + if include_roles then 1.54 + if unit.attr.role then 1.55 + if not unit.attr.only_visible_for_role 1.56 + or app.access_token 1.57 + and app.access_token.member:has_role(unit.attr.only_visible_for_role) 1.58 + then 1.59 + m.roles[unit.attr.role] = true 1.60 + end 1.61 + end 1.62 + end 1.63 + end 1.64 + end 1.65 if include_profile then 1.66 m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } } 1.67 end