# HG changeset patch # User bsw # Date 1596147535 -7200 # Node ID 2a0d86117d548f39dbb953d0154e3a8c26c7ebf8 # Parent 64229f002a4771954282584656816104a08b4bbe Added hidden and role units diff -r 64229f002a47 -r 2a0d86117d54 app/main/admin/_action/unit_update.lua --- a/app/main/admin/_action/unit_update.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/admin/_action/unit_update.lua Fri Jul 31 00:18:55 2020 +0200 @@ -2,4 +2,6 @@ param.update(unit, "parent_id", "name", "description", "external_reference", "active") +unit.attr = param.get("attr") + unit:save() diff -r 64229f002a47 -r 2a0d86117d54 app/main/admin/index.lua --- a/app/main/admin/index.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/admin/index.lua Fri Jul 31 00:18:55 2020 +0200 @@ -1,6 +1,6 @@ local inactive = param.get("inactive", atom.boolean) -local units = Unit:get_flattened_tree{ include_inactive = inactive } +local units = Unit:get_flattened_tree{ include_inactive = inactive, include_hidden = true } local policies = Policy:build_selector{ active = not inactive }:exec() --local policies = Policy:build_selector{}:add_order_by("index"):exec() diff -r 64229f002a47 -r 2a0d86117d54 app/main/admin/unit_edit.lua --- a/app/main/admin/unit_edit.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/admin/unit_edit.lua Fri Jul 31 00:18:55 2020 +0200 @@ -47,6 +47,7 @@ ui.field.text{ label = _"Name", name = "name" } ui.field.text{ label = _"Description", name = "description", multiline = true } ui.field.text{ label = _"External reference", name = "external_reference" } + ui.field.text{ label = _"Attr", name = "attr" } ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil } slot.put("
") diff -r 64229f002a47 -r 2a0d86117d54 app/main/api/_member.lua --- a/app/main/api/_member.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/api/_member.lua Fri Jul 31 00:18:55 2020 +0200 @@ -1,5 +1,8 @@ local members = param.get("members", "table") +local include_unit_ids = param.get("include_unit_ids", atom.boolean) +local include_units = param.get("include_units", atom.boolean) +local include_roles = param.get("include_roles", atom.boolean) local include_profile = param.get("include_profile", atom.boolean) if include_profile and not app.scopes.read_profiles then @@ -19,7 +22,11 @@ local r = json.array() if app.scopes.read_identities then - + + if include_unit_ids or include_units or include_roles then + members:load("units") + end + if include_profile then members:load("profile") end @@ -35,6 +42,42 @@ end m[field] = value end + if include_unit_ids or include_units or include_roles then + if include_unit_ids then + m.unit_ids = json.array() + end + if include_units then + m.units = json.array() + end + if include_roles then + m.roles = json.object() + end + for i, unit in ipairs(member.units) do + if unit.attr.hidden ~= true then + if include_unit_ids then + table.insert(m.unit_ids, unit.id) + end + if include_units then + table.insert(m.units, json.object{ + id = unit.id, + parent_id = unit.parent_id, + name = unit.name, + description = unit.description + }) + end + end + if include_roles then + if unit.attr.role then + if not unit.attr.only_visible_for_role + or app.access_token + and app.access_token.member:has_role(unit.attr.only_visible_for_role) + then + m.roles[unit.attr.role] = true + end + end + end + end + end if include_profile then m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } } end diff -r 64229f002a47 -r 2a0d86117d54 app/main/api/member.lua --- a/app/main/api/member.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/api/member.lua Fri Jul 31 00:18:55 2020 +0200 @@ -13,7 +13,13 @@ end local members = selector:exec() -local r.result = execute.chunk{ module = "api", chunk = "_member", params = { members = members } } +local r = json.object() +r.result = execute.chunk{ module = "api", chunk = "_member", params = { + members = members, + include_unit_ids = param.get("include_unit_ids") and true or false, + include_units = param.get("include_units") and true or false, + include_roles = param.get("include_roles") and true or false +} } slot.put_into("data", json.export(r)) diff -r 64229f002a47 -r 2a0d86117d54 app/main/index/index.lua --- a/app/main/index/index.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/index/index.lua Fri Jul 31 00:18:55 2020 +0200 @@ -19,6 +19,11 @@ if unit_id then unit = Unit:by_id(unit_id) + if not unit or unit.attr.hidden then + execute.view { module = "index", view = "404" } + request.set_status("404 Not Found") + return + end end if area_id then diff -r 64229f002a47 -r 2a0d86117d54 app/main/issue/_filters.lua --- a/app/main/issue/_filters.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/issue/_filters.lua Fri Jul 31 00:18:55 2020 +0200 @@ -33,14 +33,22 @@ -- units if not config.single_unit_id then - - local units + + local units_selector + if app.session.member then - units = app.session.member:get_reference_selector("units"):add_order_by("name"):add_where("active"):exec() + units_selector = app.session.member:get_reference_selector("units") + :add_order_by("name") else - units = Unit:new_selector():add_where("active"):add_order_by("name"):exec() + units_selector = Unit:new_selector() + :add_order_by("name") end + local units = units_selector + :add_where("attr->'hidden' ISNULL OR NOT (attr->'hidden' = 'true')") + :add_where("active") + :exec() + units:load_delegation_info_once_for_member_id(app.session.member_id) diff -r 64229f002a47 -r 2a0d86117d54 app/main/unit/_list.lua --- a/app/main/unit/_list.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/unit/_list.lua Fri Jul 31 00:18:55 2020 +0200 @@ -1,5 +1,5 @@ local for_admin = param.get("for_admin", atom.boolean) -local units = Unit:get_flattened_tree{ active = true } +local units = Unit:get_flattened_tree{} ui.container{ attr = { class = "box" }, content = function() diff -r 64229f002a47 -r 2a0d86117d54 app/main/unit/list.lua --- a/app/main/unit/list.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/unit/list.lua Fri Jul 31 00:18:55 2020 +0200 @@ -1,10 +1,19 @@ ui.title(_"Unit list") -ui.section( function() - ui.sectionRow( function() - execute.view{ module = "unit", view = "_list" } - end) -end ) +ui.grid{ content = function() + ui.cell_main{ content = function() + + ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function() + ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() + ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Unit list" } + end } + ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function() + + execute.view{ module = "unit", view = "_list" } + end } + end } + end } +end } diff -r 64229f002a47 -r 2a0d86117d54 app/main/unit/show.lua --- a/app/main/unit/show.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/app/main/unit/show.lua Fri Jul 31 00:18:55 2020 +0200 @@ -2,7 +2,7 @@ local unit = Unit:by_id(unit_id) -if not unit then +if not unit or unit.attr.hidden then execute.view { module = "index", view = "404" } request.set_status("404 Not Found") return diff -r 64229f002a47 -r 2a0d86117d54 model/member.lua --- a/model/member.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/model/member.lua Fri Jul 31 00:18:55 2020 +0200 @@ -839,6 +839,16 @@ return selector:exec() end +function Member.object:has_role(role) + member:load("units") + for i, unit in ipairs(member.units) do + if unit.attr.role == role then + return true + end + end + return false +end + function Member.object:delete() db:query{ "SELECT delete_member(?)", self.id } end diff -r 64229f002a47 -r 2a0d86117d54 model/unit.lua --- a/model/unit.lua Thu Jul 30 23:15:49 2020 +0200 +++ b/model/unit.lua Fri Jul 31 00:18:55 2020 +0200 @@ -101,6 +101,9 @@ if not args or not args.include_inactive then units_selector:add_where("active") end + if not args or not args.include_hidden then + units_selector:add_where("attr->'hidden' ISNULL OR NOT (attr->'hidden' = 'true')") + end local units = units_selector:exec() local unit_tree = {} for i, unit in ipairs(units) do