liquid_feedback_frontend

annotate app/main/api/_member.lua @ 1855:080f4112b8a9

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

Impressum / About Us