liquid_feedback_frontend

view app/main/api/member.lua @ 1668:6d75df24e66e

Updated German translation
author bsw
date Sun Mar 07 09:52:36 2021 +0100 (2021-03-07)
parents be96623e575a
children ddbd46a34b6a
line source
1 slot.set_layout(nil, "application/json")
3 local r = json.object{
4 result = json.array()
5 }
7 local selector = Member:new_selector()
8 :add_where("activated NOTNULL")
9 :add_order_by("id")
11 local id = param.get("id")
12 if id then
13 local ids = { sep = ", " }
14 for match in string.gmatch(id, "[^,]+") do
15 table.insert(ids, { "?", match })
16 end
17 selector:add_where{ "id IN ($)", ids }
18 end
20 local role = param.get("role")
21 if role then
22 local units = Unit:new_selector()
23 :add_where{ "attr->>'role' = ?", role }
24 :exec()
25 if #units ~= 1 then
26 request.set_status("400 Bad Request")
27 slot.put_into("data", json.export{
28 error = "invalid_role",
29 error_description = "role not available"
30 })
31 return
32 end
33 local unit = units[1]
34 if unit.attr.only_visible_for_role
35 and (
36 not app.access_token
37 or not app.access_token.member:has_role(unit.attr.only_visible_for_role)
38 )
39 then
40 request.set_status("400 Bad Request")
41 slot.put_into("data", json.export{
42 error = "no_priv",
43 error_description = "no privileges to access this role"
44 })
45 return
46 end
47 selector:join("privilege", nil, "privilege.member_id = member.id")
48 selector:join("unit", nil, { "unit.id = privilege.unit_id AND unit.attr->>'role' = ?", role })
49 end
51 local search = param.get("q")
52 if app.scopes.read_identities and search then
53 search = "%" .. search .. "%"
54 selector:add_where{ "name ILIKE ? OR identification ILIKE ?", search, search }
55 end
57 local members = selector:exec()
58 local r = json.object()
59 r.result = execute.chunk{ module = "api", chunk = "_member", params = {
60 members = members,
61 include_unit_ids = param.get("include_unit_ids") and true or false,
62 include_units = param.get("include_units") and true or false,
63 include_roles = param.get("include_roles") and true or false
64 } }
67 slot.put_into("data", json.export(r))
68 slot.put_into("data", "\n")

Impressum / About Us