liquid_feedback_frontend
changeset 988:81bde33c2256
Added support for regular delegation check, fixed css for pagination
author | bsw |
---|---|
date | Sat Apr 20 18:40:34 2013 +0200 (2013-04-20) |
parents | 0d75cd1cdcd5 |
children | 5a712ec1a7f1 |
files | app/main/_filter/21_auth.lua app/main/_filter_view/30_navigation.lua app/main/index/_action/check_delegations.lua app/main/index/_action/login.lua app/main/index/_menu.lua app/main/index/_notifications.lua app/main/index/check_delegations.lua config/example.lua config/init.lua model/delegation.lua model/member.lua static/style.css |
line diff
1.1 --- a/app/main/_filter/21_auth.lua Wed Mar 20 09:26:11 2013 +0100 1.2 +++ b/app/main/_filter/21_auth.lua Sat Apr 20 18:40:34 2013 +0200 1.3 @@ -89,6 +89,19 @@ 1.4 trace.debug("Member locked.") 1.5 request.redirect{ module = 'index', view = 'login' } 1.6 else 1.7 + if config.check_delegations_interval_hard and app.session.member_id and app.session.needs_delegation_check 1.8 + and not (module == "admin" or (module == "index" and ( 1.9 + view == "check_delegations" 1.10 + or action == "check_delegations" 1.11 + or action == "logout" 1.12 + or view == "about" 1.13 + or view == "usage_terms" 1.14 + or action == "set_lang") 1.15 + )) 1.16 + and not (module == "member_image" and view == "show") then 1.17 + request.redirect{ module = 'index', view = 'check_delegations' } 1.18 + return 1.19 + end 1.20 if auth_needed then 1.21 trace.debug("Authentication accepted.") 1.22 else
2.1 --- a/app/main/_filter_view/30_navigation.lua Wed Mar 20 09:26:11 2013 +0100 2.2 +++ b/app/main/_filter_view/30_navigation.lua Sat Apr 20 18:40:34 2013 +0200 2.3 @@ -10,7 +10,7 @@ 2.4 view = 'index' 2.5 } 2.6 2.7 - if app.session:has_access("anonymous") then 2.8 + if app.session:has_access("anonymous") and not (app.session.needs_delegation_check) then 2.9 2.10 ui.link{ 2.11 content = _"Search",
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/app/main/index/_action/check_delegations.lua Sat Apr 20 18:40:34 2013 +0200 3.3 @@ -0,0 +1,38 @@ 3.4 +local delegations = Delegation:delegations_to_check_for_member_id(app.session.member_id, true) 3.5 + 3.6 + 3.7 +-- check if for any unit/area delegation an option is choosen 3.8 +for i, delegation in ipairs(delegations) do 3.9 + 3.10 + local option = param.get("delegation_" .. delegation.id) 3.11 + 3.12 + if option == "confirm" then 3.13 + elseif option == "revoke" then 3.14 + else 3.15 + slot.put_into("error", _"Please decide for each delegation to confirm or to revoke it!") 3.16 + return false 3.17 + end 3.18 + 3.19 +end 3.20 + 3.21 +-- revoke delegations 3.22 +for i, delegation in ipairs(delegations) do 3.23 + 3.24 + local option = param.get("delegation_" .. delegation.id) 3.25 + 3.26 + if option == "revoke" then 3.27 + local d = Delegation:by_id(delegation.id) 3.28 + if d.truster_id == app.session.member_id then 3.29 + d:destroy() 3.30 + end 3.31 + end 3.32 +end 3.33 + 3.34 +-- set delegation check as done 3.35 +app.session.member.last_delegation_check = "now" 3.36 +app.session.member.last_activity = "now" 3.37 +app.session.member.active = true 3.38 +app.session.member:save() 3.39 + 3.40 +app.session.needs_delegation_check = false 3.41 +app.session:save()
4.1 --- a/app/main/index/_action/login.lua Wed Mar 20 09:26:11 2013 +0100 4.2 +++ b/app/main/index/_action/login.lua Sat Apr 20 18:40:34 2013 +0200 4.3 @@ -55,8 +55,12 @@ 4.4 4.5 if member then 4.6 member.last_login = "now" 4.7 - member.last_activity = "now" 4.8 - member.active = true 4.9 + if config.check_delegations_interval_hard and member.needs_delegation_check_hard then 4.10 + app.session.needs_delegation_check = true 4.11 + else 4.12 + member.last_activity = "now" 4.13 + member.active = true 4.14 + end 4.15 if member.lang == nil then 4.16 member.lang = app.session.lang 4.17 else
5.1 --- a/app/main/index/_menu.lua Wed Mar 20 09:26:11 2013 +0100 5.2 +++ b/app/main/index/_menu.lua Sat Apr 20 18:40:34 2013 +0200 5.3 @@ -1,6 +1,6 @@ 5.4 ui.tag{ tag = "ul", content = function() 5.5 5.6 - if app.session.member_id then 5.7 + if app.session.member_id and not app.session.needs_delegation_check then 5.8 ui.tag{ tag = "li", content = function() 5.9 5.10 ui.link{ 5.11 @@ -55,7 +55,9 @@ 5.12 } 5.13 5.14 end } 5.15 - 5.16 + end 5.17 + 5.18 + if app.session.member_id then 5.19 ui.tag{ tag = "li", content = function() 5.20 5.21 ui.link{
6.1 --- a/app/main/index/_notifications.lua Wed Mar 20 09:26:11 2013 +0100 6.2 +++ b/app/main/index/_notifications.lua Sat Apr 20 18:40:34 2013 +0200 6.3 @@ -14,6 +14,21 @@ 6.4 } 6.5 end 6.6 6.7 +if config.check_delegations_interval_soft then 6.8 + local member = Member:new_selector() 6.9 + :add_where({ "id = ?", app.session.member_id }) 6.10 + :add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_soft }, "needs_delegation_check_soft") 6.11 + :single_object_mode() 6.12 + :exec() 6.13 + 6.14 + if member.needs_delegation_check_soft then 6.15 + notification_links[#notification_links+1] = { 6.16 + module = "index", view = "check_delegations", 6.17 + text = _"Check your delegations!" 6.18 + } 6.19 + end 6.20 +end 6.21 + 6.22 local broken_delegations_count = Delegation:selector_for_broken(app.session.member_id):count() 6.23 6.24 if broken_delegations_count > 0 then
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/app/main/index/check_delegations.lua Sat Apr 20 18:40:34 2013 +0200 7.3 @@ -0,0 +1,110 @@ 7.4 +local delegations = Delegation:delegations_to_check_for_member_id(app.session.member_id) 7.5 + 7.6 +ui.title(_"Current unit and area delegations need confirmation") 7.7 + 7.8 +ui.actions(function() 7.9 + if not app.session.needs_delegation_check then 7.10 + ui.link{ module = "index", view = "index", text = _"Cancel" } 7.11 + end 7.12 +end) 7.13 + 7.14 +util.help("index.check_delegations", _"Check delegations") 7.15 + 7.16 +ui.form{ 7.17 + module = "index", action = "check_delegations", 7.18 + routing = { 7.19 + default = { mode = "redirect", module = "index", view = "index" }, 7.20 + error = { mode = "redirect", module = "index", view = "check_delegations" } 7.21 + }, 7.22 + content = function() 7.23 + 7.24 + ui.tag{ tag = "table", attr = { class = "striped" }, content = function() 7.25 + 7.26 + ui.tag{ tag = "tr", content = function() 7.27 + 7.28 + ui.tag{ tag = "th", content = _"unit / area" } 7.29 + ui.tag{ tag = "th", content = _"delegated to" } 7.30 + ui.tag{ tag = "th", content = _"action" } 7.31 + 7.32 + end } 7.33 + 7.34 + for i, delegation in ipairs(delegations) do 7.35 + 7.36 + local unit = Unit:by_id(delegation.unit_id) 7.37 + local area = Area:by_id(delegation.area_id) 7.38 + local member = Member:by_id(delegation.trustee_id) 7.39 + local info 7.40 + if area then 7.41 + area:load_delegation_info_once_for_member_id(app.session.member_id) 7.42 + info = area.delegation_info 7.43 + else 7.44 + unit:load_delegation_info_once_for_member_id(app.session.member_id) 7.45 + info = unit.delegation_info 7.46 + end 7.47 + 7.48 + ui.tag{ tag = "tr", content = function () 7.49 + 7.50 + ui.tag { tag = "td", content = function() 7.51 + ui.tag{ tag = "span", attr = { class = "unit_link" }, content = delegation.unit_name } 7.52 + ui.tag{ tag = "span", attr = { class = "area_link" }, content = delegation.area_name } 7.53 + end } 7.54 + 7.55 + ui.tag { tag = "td", content = function() 7.56 + if (member) then 7.57 + local text = _"delegates to" 7.58 + ui.image{ 7.59 + attr = { class = "delegation_arrow", alt = text, title = text }, 7.60 + static = "delegation_arrow_24_horizontal.png" 7.61 + } 7.62 + execute.view{ module = "member_image", view = "_show", params = { 7.63 + member = member, class = "micro_avatar", popup_text = member.name, 7.64 + image_type = "avatar", show_dummy = true, 7.65 + } } 7.66 + slot.put(" ") 7.67 + ui.tag { tag = "span", content = delegation.member_name } 7.68 + else 7.69 + ui.tag{ tag = "span", content = _"Abandon unit delegation" } 7.70 + end 7.71 + end } 7.72 + 7.73 + ui.tag { tag = "td", content = function() 7.74 + local checked = config.check_delegations_default 7.75 + ui.tag{ tag = "input", attr = { 7.76 + type = "radio", 7.77 + id = "delegation_" .. delegation.id .. "_confirm", 7.78 + name = "delegation_" .. delegation.id, 7.79 + value = "confirm", 7.80 + checked = checked == "confirm" and "checked" or nil 7.81 + } } 7.82 + ui.tag{ 7.83 + tag = "label", 7.84 + attr = { ["for"] = "delegation_" .. delegation.id .. "_confirm" }, 7.85 + content = _"confirm" 7.86 + } 7.87 + ui.tag{ tag = "input", attr = { 7.88 + type = "radio", 7.89 + id = "delegation_" .. delegation.id .. "_revoke", 7.90 + name = "delegation_" .. delegation.id, 7.91 + value = "revoke", 7.92 + checked = checked == "revoke" and "checked" or nil 7.93 + } } 7.94 + ui.tag{ 7.95 + tag = "label", 7.96 + attr = { ["for"] = "delegation_" .. delegation.id .. "_revoke" }, 7.97 + content = _"revoke" 7.98 + } 7.99 + end} 7.100 + 7.101 + end } 7.102 + 7.103 + end 7.104 + 7.105 + end} 7.106 + 7.107 + 7.108 + slot.put("<br />") 7.109 + 7.110 + ui.submit{ text = "Finish delegation check" } 7.111 + 7.112 + end 7.113 +}
8.1 --- a/config/example.lua Wed Mar 20 09:26:11 2013 +0100 8.2 +++ b/config/example.lua Sat Apr 20 18:40:34 2013 +0200 8.3 @@ -89,6 +89,17 @@ 8.4 -- ------------------------------------------------------------------------ 8.5 -- config.delegation_warning_time = '6 months' 8.6 8.7 +-- after which time a user is advised (_soft) or forced (_hard) to check 8.8 +-- unit and area delegations. default: no check at all 8.9 +-- ------------------------------------------------------------------------ 8.10 +-- config.check_delegations_interval_hard = "6 months" 8.11 +-- config.check_delegations_interval_soft = "3 months" 8.12 + 8.13 +-- default option when checking delegations 8.14 +-- available options: "confirm", "revoke" and "none", default: "confirm" 8.15 +-- ------------------------------------------------------------------------ 8.16 +-- config.check_delegations_default = "confirm" 8.17 + 8.18 -- Prefix of all automatic mails, defaults to "[Liquid Feedback] " 8.19 -- ------------------------------------------------------------------------ 8.20 -- config.mail_subject_prefix = "[LiquidFeedback] "
9.1 --- a/config/init.lua Wed Mar 20 09:26:11 2013 +0100 9.2 +++ b/config/init.lua Sat Apr 20 18:40:34 2013 +0200 9.3 @@ -44,6 +44,10 @@ 9.4 config.locked_profile_fields = {} 9.5 end 9.6 9.7 +if config.check_delegations_default == nil then 9.8 + config.check_delegations_default = "confirm" 9.9 +end 9.10 + 9.11 if not config.database then 9.12 config.database = { engine='postgresql', dbname='liquid_feedback' } 9.13 end
10.1 --- a/model/delegation.lua Wed Mar 20 09:26:11 2013 +0100 10.2 +++ b/model/delegation.lua Sat Apr 20 18:40:34 2013 +0200 10.3 @@ -70,4 +70,25 @@ 10.4 :add_where{"delegation.truster_id = ?", member_id} 10.5 :add_where{"member.active = 'f' OR (member.last_activity IS NULL OR age(member.last_activity) > ?::interval)", config.delegation_warning_time } 10.6 end 10.7 - 10.8 \ No newline at end of file 10.9 + 10.10 +function Delegation:delegations_to_check_for_member_id(member_id, for_update) 10.11 + 10.12 + Member:new_selector():add_where({ "id = ?", member_id }):for_update():exec() 10.13 + 10.14 + local selector = Delegation:new_selector() 10.15 + :add_field("member.name", "member_name") 10.16 + :add_field("unit.name", "unit_name") 10.17 + :add_field("area.name", "area_name") 10.18 + :left_join("area", nil, "area.active AND area.id = delegation.area_id") 10.19 + :join("unit", nil, "unit.active AND (unit.id = delegation.unit_id OR unit.id = area.unit_id)") 10.20 + :left_join("member", nil, "member.id = delegation.trustee_id") 10.21 + :add_where({ "delegation.truster_id = ?", member_id }) 10.22 + :add_order_by("unit.name, area.name NULLS FIRST") 10.23 + 10.24 + if for_update then 10.25 + selector:for_update_of("delegation") 10.26 + end 10.27 + 10.28 + return selector:exec() 10.29 + 10.30 +end 10.31 \ No newline at end of file
11.1 --- a/model/member.lua Wed Mar 20 09:26:11 2013 +0100 11.2 +++ b/model/member.lua Sat Apr 20 18:40:34 2013 +0200 11.3 @@ -373,6 +373,7 @@ 11.4 11.5 function Member:by_login_and_password(login, password) 11.6 local selector = self:new_selector() 11.7 + selector:add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_hard }, "needs_delegation_check_hard") 11.8 selector:add_where{'"login" = ?', login } 11.9 selector:add_where('NOT "locked"') 11.10 selector:optional_object_mode()
12.1 --- a/static/style.css Wed Mar 20 09:26:11 2013 +0100 12.2 +++ b/static/style.css Sat Apr 20 18:40:34 2013 +0200 12.3 @@ -64,6 +64,16 @@ 12.4 margin: 0; 12.5 } 12.6 12.7 +table.striped tr:nth-child(even) td { 12.8 + background-color: #ddd; 12.9 +} 12.10 +table.striped td, table.striped label { 12.11 + vertical-align: middle; 12.12 +} 12.13 +table.striped label { 12.14 + vertical-align: top; 12.15 +} 12.16 + 12.17 .page, 12.18 .topbar_content { 12.19 max-width: 1130px; 12.20 @@ -125,6 +135,10 @@ 12.21 display: inline; 12.22 } 12.23 12.24 +input[type=submit] { 12.25 + border-radius: 4px; 12.26 +} 12.27 + 12.28 /************************************************************************* 12.29 * Notices, warnings and errors 12.30 */ 12.31 @@ -483,6 +497,11 @@ 12.32 margin-right: 8px; 12.33 } 12.34 12.35 +table .unit_link, 12.36 +table .area_link { 12.37 + margin-top: 1px; 12.38 +} 12.39 + 12.40 .unit_link { 12.41 background-color: #44a; 12.42 color: #fff; 12.43 @@ -660,8 +679,15 @@ 12.44 .ui_paginate_select a { 12.45 padding: 0.5em; 12.46 border-radius: 4px; 12.47 + line-height: 250%; 12.48 + background: #eee; 12.49 } 12.50 12.51 +.ui_paginate_select a.active { 12.52 + background: #444; 12.53 +} 12.54 + 12.55 + 12.56 /************************************************************************* 12.57 * ui.bargraph 12.58 */