liquid_feedback_frontend
diff app/main/api/_member.lua @ 1309:32cc544d5a5b
Cumulative patch for upcoming frontend version 4
author | bsw/jbe |
---|---|
date | Sun Jul 15 14:07:29 2018 +0200 (2018-07-15) |
parents | |
children | 2a0d86117d54 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/api/_member.lua Sun Jul 15 14:07:29 2018 +0200 1.3 @@ -0,0 +1,45 @@ 1.4 +local members = param.get("members", "table") 1.5 + 1.6 +local include_profile = param.get("include_profile", atom.boolean) 1.7 + 1.8 +if include_profile and not app.scopes.read_profiles then 1.9 + return util.api_error(403, "Forbidden", "insufficient_scope", "Scope read_profiles required") 1.10 +end 1.11 + 1.12 +local fields = {} 1.13 + 1.14 +if app.scopes.read_authors or app.scopes.read_identities then 1.15 + fields = { "id", "created", "last_activity", "admin", "name", "location" } 1.16 +end 1.17 + 1.18 +if app.scopes.read_identities then 1.19 + fields[#fields+1] = "identification" 1.20 +end 1.21 + 1.22 +local r = json.array() 1.23 + 1.24 +if app.scopes.read_identities then 1.25 + 1.26 + if include_profile then 1.27 + members:load("profile") 1.28 + end 1.29 + 1.30 + for i, member in ipairs(members) do 1.31 + local m = json.object() 1.32 + for j, field in ipairs(fields) do 1.33 + local value = member[field] 1.34 + if value == nil then 1.35 + value = json.null 1.36 + else 1.37 + value = tostring(value) 1.38 + end 1.39 + m[field] = value 1.40 + end 1.41 + if include_profile then 1.42 + m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } } 1.43 + end 1.44 + r[#r+1] = m 1.45 + end 1.46 +end 1.47 + 1.48 +return r