liquid_feedback_frontend
changeset 1504:2a0d86117d54
Added hidden and role units
author | bsw |
---|---|
date | Fri Jul 31 00:18:55 2020 +0200 (2020-07-31) |
parents | 64229f002a47 |
children | 3f5758f325db |
files | app/main/admin/_action/unit_update.lua app/main/admin/index.lua app/main/admin/unit_edit.lua app/main/api/_member.lua app/main/api/member.lua app/main/index/index.lua app/main/issue/_filters.lua app/main/unit/_list.lua app/main/unit/list.lua app/main/unit/show.lua model/member.lua model/unit.lua |
line diff
1.1 --- a/app/main/admin/_action/unit_update.lua Thu Jul 30 23:15:49 2020 +0200 1.2 +++ b/app/main/admin/_action/unit_update.lua Fri Jul 31 00:18:55 2020 +0200 1.3 @@ -2,4 +2,6 @@ 1.4 1.5 param.update(unit, "parent_id", "name", "description", "external_reference", "active") 1.6 1.7 +unit.attr = param.get("attr") 1.8 + 1.9 unit:save()
2.1 --- a/app/main/admin/index.lua Thu Jul 30 23:15:49 2020 +0200 2.2 +++ b/app/main/admin/index.lua Fri Jul 31 00:18:55 2020 +0200 2.3 @@ -1,6 +1,6 @@ 2.4 local inactive = param.get("inactive", atom.boolean) 2.5 2.6 -local units = Unit:get_flattened_tree{ include_inactive = inactive } 2.7 +local units = Unit:get_flattened_tree{ include_inactive = inactive, include_hidden = true } 2.8 2.9 local policies = Policy:build_selector{ active = not inactive }:exec() 2.10 --local policies = Policy:build_selector{}:add_order_by("index"):exec()
3.1 --- a/app/main/admin/unit_edit.lua Thu Jul 30 23:15:49 2020 +0200 3.2 +++ b/app/main/admin/unit_edit.lua Fri Jul 31 00:18:55 2020 +0200 3.3 @@ -47,6 +47,7 @@ 3.4 ui.field.text{ label = _"Name", name = "name" } 3.5 ui.field.text{ label = _"Description", name = "description", multiline = true } 3.6 ui.field.text{ label = _"External reference", name = "external_reference" } 3.7 + ui.field.text{ label = _"Attr", name = "attr" } 3.8 ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil } 3.9 3.10 slot.put("<br />")
4.1 --- a/app/main/api/_member.lua Thu Jul 30 23:15:49 2020 +0200 4.2 +++ b/app/main/api/_member.lua Fri Jul 31 00:18:55 2020 +0200 4.3 @@ -1,5 +1,8 @@ 4.4 local members = param.get("members", "table") 4.5 4.6 +local include_unit_ids = param.get("include_unit_ids", atom.boolean) 4.7 +local include_units = param.get("include_units", atom.boolean) 4.8 +local include_roles = param.get("include_roles", atom.boolean) 4.9 local include_profile = param.get("include_profile", atom.boolean) 4.10 4.11 if include_profile and not app.scopes.read_profiles then 4.12 @@ -19,7 +22,11 @@ 4.13 local r = json.array() 4.14 4.15 if app.scopes.read_identities then 4.16 - 4.17 + 4.18 + if include_unit_ids or include_units or include_roles then 4.19 + members:load("units") 4.20 + end 4.21 + 4.22 if include_profile then 4.23 members:load("profile") 4.24 end 4.25 @@ -35,6 +42,42 @@ 4.26 end 4.27 m[field] = value 4.28 end 4.29 + if include_unit_ids or include_units or include_roles then 4.30 + if include_unit_ids then 4.31 + m.unit_ids = json.array() 4.32 + end 4.33 + if include_units then 4.34 + m.units = json.array() 4.35 + end 4.36 + if include_roles then 4.37 + m.roles = json.object() 4.38 + end 4.39 + for i, unit in ipairs(member.units) do 4.40 + if unit.attr.hidden ~= true then 4.41 + if include_unit_ids then 4.42 + table.insert(m.unit_ids, unit.id) 4.43 + end 4.44 + if include_units then 4.45 + table.insert(m.units, json.object{ 4.46 + id = unit.id, 4.47 + parent_id = unit.parent_id, 4.48 + name = unit.name, 4.49 + description = unit.description 4.50 + }) 4.51 + end 4.52 + end 4.53 + if include_roles then 4.54 + if unit.attr.role then 4.55 + if not unit.attr.only_visible_for_role 4.56 + or app.access_token 4.57 + and app.access_token.member:has_role(unit.attr.only_visible_for_role) 4.58 + then 4.59 + m.roles[unit.attr.role] = true 4.60 + end 4.61 + end 4.62 + end 4.63 + end 4.64 + end 4.65 if include_profile then 4.66 m.profile = execute.chunk{ module = "api", chunk = "_profile", params = { profile = member.profile } } 4.67 end
5.1 --- a/app/main/api/member.lua Thu Jul 30 23:15:49 2020 +0200 5.2 +++ b/app/main/api/member.lua Fri Jul 31 00:18:55 2020 +0200 5.3 @@ -13,7 +13,13 @@ 5.4 end 5.5 5.6 local members = selector:exec() 5.7 -local r.result = execute.chunk{ module = "api", chunk = "_member", params = { members = members } } 5.8 +local r = json.object() 5.9 +r.result = execute.chunk{ module = "api", chunk = "_member", params = { 5.10 + members = members, 5.11 + include_unit_ids = param.get("include_unit_ids") and true or false, 5.12 + include_units = param.get("include_units") and true or false, 5.13 + include_roles = param.get("include_roles") and true or false 5.14 +} } 5.15 5.16 5.17 slot.put_into("data", json.export(r))
6.1 --- a/app/main/index/index.lua Thu Jul 30 23:15:49 2020 +0200 6.2 +++ b/app/main/index/index.lua Fri Jul 31 00:18:55 2020 +0200 6.3 @@ -19,6 +19,11 @@ 6.4 6.5 if unit_id then 6.6 unit = Unit:by_id(unit_id) 6.7 + if not unit or unit.attr.hidden then 6.8 + execute.view { module = "index", view = "404" } 6.9 + request.set_status("404 Not Found") 6.10 + return 6.11 + end 6.12 end 6.13 6.14 if area_id then
7.1 --- a/app/main/issue/_filters.lua Thu Jul 30 23:15:49 2020 +0200 7.2 +++ b/app/main/issue/_filters.lua Fri Jul 31 00:18:55 2020 +0200 7.3 @@ -33,14 +33,22 @@ 7.4 -- units 7.5 7.6 if not config.single_unit_id then 7.7 - 7.8 - local units 7.9 + 7.10 + local units_selector 7.11 + 7.12 if app.session.member then 7.13 - units = app.session.member:get_reference_selector("units"):add_order_by("name"):add_where("active"):exec() 7.14 + units_selector = app.session.member:get_reference_selector("units") 7.15 + :add_order_by("name") 7.16 else 7.17 - units = Unit:new_selector():add_where("active"):add_order_by("name"):exec() 7.18 + units_selector = Unit:new_selector() 7.19 + :add_order_by("name") 7.20 end 7.21 7.22 + local units = units_selector 7.23 + :add_where("attr->'hidden' ISNULL OR NOT (attr->'hidden' = 'true')") 7.24 + :add_where("active") 7.25 + :exec() 7.26 + 7.27 units:load_delegation_info_once_for_member_id(app.session.member_id) 7.28 7.29
8.1 --- a/app/main/unit/_list.lua Thu Jul 30 23:15:49 2020 +0200 8.2 +++ b/app/main/unit/_list.lua Fri Jul 31 00:18:55 2020 +0200 8.3 @@ -1,5 +1,5 @@ 8.4 local for_admin = param.get("for_admin", atom.boolean) 8.5 -local units = Unit:get_flattened_tree{ active = true } 8.6 +local units = Unit:get_flattened_tree{} 8.7 8.8 ui.container{ attr = { class = "box" }, content = function() 8.9
9.1 --- a/app/main/unit/list.lua Thu Jul 30 23:15:49 2020 +0200 9.2 +++ b/app/main/unit/list.lua Fri Jul 31 00:18:55 2020 +0200 9.3 @@ -1,10 +1,19 @@ 9.4 ui.title(_"Unit list") 9.5 9.6 -ui.section( function() 9.7 - ui.sectionRow( function() 9.8 - execute.view{ module = "unit", view = "_list" } 9.9 - end) 9.10 -end ) 9.11 +ui.grid{ content = function() 9.12 + ui.cell_main{ content = function() 9.13 + 9.14 + ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function() 9.15 + ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() 9.16 + ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Unit list" } 9.17 + end } 9.18 + ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function() 9.19 + 9.20 + execute.view{ module = "unit", view = "_list" } 9.21 + end } 9.22 + end } 9.23 + end } 9.24 +end } 9.25 9.26 9.27
10.1 --- a/app/main/unit/show.lua Thu Jul 30 23:15:49 2020 +0200 10.2 +++ b/app/main/unit/show.lua Fri Jul 31 00:18:55 2020 +0200 10.3 @@ -2,7 +2,7 @@ 10.4 10.5 local unit = Unit:by_id(unit_id) 10.6 10.7 -if not unit then 10.8 +if not unit or unit.attr.hidden then 10.9 execute.view { module = "index", view = "404" } 10.10 request.set_status("404 Not Found") 10.11 return
11.1 --- a/model/member.lua Thu Jul 30 23:15:49 2020 +0200 11.2 +++ b/model/member.lua Fri Jul 31 00:18:55 2020 +0200 11.3 @@ -839,6 +839,16 @@ 11.4 return selector:exec() 11.5 end 11.6 11.7 +function Member.object:has_role(role) 11.8 + member:load("units") 11.9 + for i, unit in ipairs(member.units) do 11.10 + if unit.attr.role == role then 11.11 + return true 11.12 + end 11.13 + end 11.14 + return false 11.15 +end 11.16 + 11.17 function Member.object:delete() 11.18 db:query{ "SELECT delete_member(?)", self.id } 11.19 end
12.1 --- a/model/unit.lua Thu Jul 30 23:15:49 2020 +0200 12.2 +++ b/model/unit.lua Fri Jul 31 00:18:55 2020 +0200 12.3 @@ -101,6 +101,9 @@ 12.4 if not args or not args.include_inactive then 12.5 units_selector:add_where("active") 12.6 end 12.7 + if not args or not args.include_hidden then 12.8 + units_selector:add_where("attr->'hidden' ISNULL OR NOT (attr->'hidden' = 'true')") 12.9 + end 12.10 local units = units_selector:exec() 12.11 local unit_tree = {} 12.12 for i, unit in ipairs(units) do