liquid_feedback_frontend

view app/main/api/_member.lua @ 1858:3d1f0464a3ea

Handle missing ldap.member.allowed function
author bsw
date Tue Sep 20 17:35:29 2022 +0200 (20 months ago)
parents 2a0d86117d54
children
line source
1 local members = param.get("members", "table")
3 local include_unit_ids = param.get("include_unit_ids", atom.boolean)
4 local include_units = param.get("include_units", atom.boolean)
5 local include_roles = param.get("include_roles", atom.boolean)
6 local include_profile = param.get("include_profile", atom.boolean)
8 if include_profile and not app.scopes.read_profiles then
9 return util.api_error(403, "Forbidden", "insufficient_scope", "Scope read_profiles required")
10 end
12 local fields = {}
14 if app.scopes.read_authors or app.scopes.read_identities then
15 fields = { "id", "created", "last_activity", "admin", "name", "location" }
16 end
18 if app.scopes.read_identities then
19 fields[#fields+1] = "identification"
20 end
22 local r = json.array()
24 if app.scopes.read_identities then
26 if include_unit_ids or include_units or include_roles then
27 members:load("units")
28 end
30 if include_profile then
31 members:load("profile")
32 end
34 for i, member in ipairs(members) do
35 local m = json.object()
36 for j, field in ipairs(fields) do
37 local value = member[field]
38 if value == nil then
39 value = json.null
40 else
41 value = tostring(value)
42 end
43 m[field] = value
44 end
45 if include_unit_ids or include_units or include_roles then
46 if include_unit_ids then
47 m.unit_ids = json.array()
48 end
49 if include_units then
50 m.units = json.array()
51 end
52 if include_roles then
53 m.roles = json.object()
54 end
55 for i, unit in ipairs(member.units) do
56 if unit.attr.hidden ~= true then
57 if include_unit_ids then
58 table.insert(m.unit_ids, unit.id)
59 end
60 if include_units then
61 table.insert(m.units, json.object{
62 id = unit.id,
63 parent_id = unit.parent_id,
64 name = unit.name,
65 description = unit.description
66 })
67 end
68 end
69 if include_roles then
70 if unit.attr.role then
71 if not unit.attr.only_visible_for_role
72 or app.access_token
73 and app.access_token.member:has_role(unit.attr.only_visible_for_role)
74 then
75 m.roles[unit.attr.role] = true
76 end
77 end
78 end
79 end
80 end
81 if include_profile then
82 m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } }
83 end
84 r[#r+1] = m
85 end
86 end
88 return r

Impressum / About Us