liquid_feedback_frontend

view app/main/api/member.lua @ 1525:628e1b9126c0

Handle no valid session in session filter correctly
author bsw
date Thu Aug 20 15:55:04 2020 +0200 (2020-08-20)
parents 103ed34037ed
children 1e5c1edf7388
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 if param.get("id") then
12 selector:add_where{ "id = ?", param.get("id") }
13 end
15 local role = param.get("role")
16 if role then
17 local units = Unit:new_selector()
18 :add_where{ "attr->>'role' = ?", role }
19 :exec()
20 if #units ~= 1 then
21 request.set_status("400 Bad Request")
22 slot.put_into("data", json.export{
23 error = "invalid_role",
24 error_description = "role not available"
25 })
26 return
27 end
28 local unit = units[1]
29 if unit.attr.only_visible_for_role
30 and (
31 not app.access_token
32 or not app.access_token.member:has_role(unit.attr.only_visible_for_role)
33 )
34 then
35 request.set_status("400 Bad Request")
36 slot.put_into("data", json.export{
37 error = "no_priv",
38 error_description = "no privileges to access this role"
39 })
40 return
41 end
42 selector:join("privilege", nil, "privilege.member_id = member.id")
43 selector:join("unit", nil, { "unit.id = privilege.unit_id AND unit.attr->>'role' = ?", role })
44 end
46 local members = selector:exec()
47 local r = json.object()
48 r.result = execute.chunk{ module = "api", chunk = "_member", params = {
49 members = members,
50 include_unit_ids = param.get("include_unit_ids") and true or false,
51 include_units = param.get("include_units") and true or false,
52 include_roles = param.get("include_roles") and true or false
53 } }
56 slot.put_into("data", json.export(r))
57 slot.put_into("data", "\n")

Impressum / About Us