bsw/jbe@1309: local members = param.get("members", "table") bsw/jbe@1309: bsw@1504: local include_unit_ids = param.get("include_unit_ids", atom.boolean) bsw@1504: local include_units = param.get("include_units", atom.boolean) bsw@1504: local include_roles = param.get("include_roles", atom.boolean) bsw/jbe@1309: local include_profile = param.get("include_profile", atom.boolean) bsw/jbe@1309: bsw/jbe@1309: if include_profile and not app.scopes.read_profiles then bsw/jbe@1309: return util.api_error(403, "Forbidden", "insufficient_scope", "Scope read_profiles required") bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: local fields = {} bsw/jbe@1309: bsw/jbe@1309: if app.scopes.read_authors or app.scopes.read_identities then bsw/jbe@1309: fields = { "id", "created", "last_activity", "admin", "name", "location" } bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: if app.scopes.read_identities then bsw/jbe@1309: fields[#fields+1] = "identification" bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: local r = json.array() bsw/jbe@1309: bsw/jbe@1309: if app.scopes.read_identities then bsw@1504: bsw@1504: if include_unit_ids or include_units or include_roles then bsw@1504: members:load("units") bsw@1504: end bsw@1504: bsw/jbe@1309: if include_profile then bsw/jbe@1309: members:load("profile") bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: for i, member in ipairs(members) do bsw/jbe@1309: local m = json.object() bsw/jbe@1309: for j, field in ipairs(fields) do bsw/jbe@1309: local value = member[field] bsw/jbe@1309: if value == nil then bsw/jbe@1309: value = json.null bsw/jbe@1309: else bsw/jbe@1309: value = tostring(value) bsw/jbe@1309: end bsw/jbe@1309: m[field] = value bsw/jbe@1309: end bsw@1504: if include_unit_ids or include_units or include_roles then bsw@1504: if include_unit_ids then bsw@1504: m.unit_ids = json.array() bsw@1504: end bsw@1504: if include_units then bsw@1504: m.units = json.array() bsw@1504: end bsw@1504: if include_roles then bsw@1504: m.roles = json.object() bsw@1504: end bsw@1504: for i, unit in ipairs(member.units) do bsw@1504: if unit.attr.hidden ~= true then bsw@1504: if include_unit_ids then bsw@1504: table.insert(m.unit_ids, unit.id) bsw@1504: end bsw@1504: if include_units then bsw@1504: table.insert(m.units, json.object{ bsw@1504: id = unit.id, bsw@1504: parent_id = unit.parent_id, bsw@1504: name = unit.name, bsw@1504: description = unit.description bsw@1504: }) bsw@1504: end bsw@1504: end bsw@1504: if include_roles then bsw@1504: if unit.attr.role then bsw@1504: if not unit.attr.only_visible_for_role bsw@1504: or app.access_token bsw@1504: and app.access_token.member:has_role(unit.attr.only_visible_for_role) bsw@1504: then bsw@1504: m.roles[unit.attr.role] = true bsw@1504: end bsw@1504: end bsw@1504: end bsw@1504: end bsw@1504: end bsw/jbe@1309: if include_profile then bsw/jbe@1309: m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } } bsw/jbe@1309: end bsw/jbe@1309: r[#r+1] = m bsw/jbe@1309: end bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: return r