# HG changeset patch # User bsw # Date 1346013469 -7200 # Node ID a176129ce282728ea5169ee8b6ad137b0353802f # Parent dd6c00eb215f289fe119542fe2586c2cf160861c Add support for poll mode; Forbid postings unless contingents are configured diff -r dd6c00eb215f -r a176129ce282 app/main/draft/_action/add.lua --- a/app/main/draft/_action/add.lua Tue Aug 21 01:29:28 2012 +0200 +++ b/app/main/draft/_action/add.lua Sun Aug 26 22:37:49 2012 +0200 @@ -1,9 +1,3 @@ -local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object") -if tmp and tmp.text_entries_left and tmp.text_entries_left < 1 then - slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") - return false -end - local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) -- TODO important m1 selectors returning result _SET_! @@ -22,6 +16,12 @@ error("access denied") end +local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", app.session.member.id, initiative.polling }, "opt_object") +if not tmp or tmp.text_entries_left < 1 then + slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") + return false +end + local formatting_engine = param.get("formatting_engine") local formatting_engine_valid = false diff -r dd6c00eb215f -r a176129ce282 app/main/initiative/_action/create.lua --- a/app/main/initiative/_action/create.lua Tue Aug 21 01:29:28 2012 +0200 +++ b/app/main/initiative/_action/create.lua Sun Aug 26 22:37:49 2012 +0200 @@ -1,15 +1,3 @@ -local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object") -if tmp then - if tmp.initiatives_left and tmp.initiatives_left < 1 then - slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.") - return false - end - if tmp.text_entries_left and tmp.text_entries_left < 1 then - slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") - return false - end -end - local issue local area @@ -37,6 +25,46 @@ error("access denied") end +local policy_id = param.get("policy_id", atom.integer) +local policy +if policy_id then + policy = Policy:by_id(policy_id) +end + +if not issue then + if policy_id == -1 then + slot.put_into("error", _"Please choose a policy") + return false + end + if not policy.active then + slot.put_into("error", "Invalid policy.") + return false + end + if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then + error("no polling right for this unit") + end + + if not area:get_reference_selector("allowed_policies") + :add_where{ "policy.id = ?", policy_id } + :optional_object_mode() + :exec() + then + error("policy not allowed") + end +end + +local is_polling = (issue and param.get("polling", atom.boolean)) or (policy and policy.polling) or false + +local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", app.session.member.id, is_polling }, "opt_object") +if not tmp or tmp.initiatives_left < 1 then + slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.") + return false +end +if tmp and tmp.text_entries_left < 1 then + slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") + return false +end + local name = param.get("name") local name = util.trim(name) @@ -66,27 +94,6 @@ local initiative = Initiative:new() if not issue then - local policy_id = param.get("policy_id", atom.integer) - if policy_id == -1 then - slot.put_into("error", _"Please choose a policy") - return false - end - local policy = Policy:by_id(policy_id) - if not policy.active then - slot.put_into("error", "Invalid policy.") - return false - end - if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then - error("no polling right for this unit") - end - - if not area:get_reference_selector("allowed_policies") - :add_where{ "policy.id = ?", policy_id } - :optional_object_mode() - :exec() - then - error("policy not allowed") - end issue = Issue:new() issue.area_id = area.id issue.policy_id = policy_id diff -r dd6c00eb215f -r a176129ce282 app/main/initiative/new.lua --- a/app/main/initiative/new.lua Tue Aug 21 01:29:28 2012 +0200 +++ b/app/main/initiative/new.lua Sun Aug 26 22:37:49 2012 +0200 @@ -11,6 +11,8 @@ area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec() end +local polling = param.get("polling", atom.boolean) + local policy_id = param.get("policy_id", atom.integer) local policy @@ -62,7 +64,7 @@ slot.put("
") if issue_id then ui.field.text{ label = _"Issue", value = issue_id } - elseif policy_id then + elseif policy then ui.field.hidden{ name = "policy_id", value = policy.id } ui.field.text{ label = _"Policy", value = policy.name } if policy.free_timeable then @@ -89,7 +91,7 @@ else tmp = { { id = -1, name = _"Please choose a policy" } } for i, allowed_policy in ipairs(area.allowed_policies) do - if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then + if not allowed_policy.polling then tmp[#tmp+1] = allowed_policy end end @@ -130,7 +132,7 @@ end if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then - ui.field.boolean{ name = "polling", label = _"Poll" } + ui.field.boolean{ name = "polling", label = _"Poll", value = polling } end if preview then diff -r dd6c00eb215f -r a176129ce282 app/main/suggestion/_action/add.lua --- a/app/main/suggestion/_action/add.lua Tue Aug 21 01:29:28 2012 +0200 +++ b/app/main/suggestion/_action/add.lua Sun Aug 26 22:37:49 2012 +0200 @@ -1,5 +1,5 @@ -local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object") -if tmp and tmp.text_entries_left and tmp.text_entries_left < 1 then +local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND NOT polling", app.session.member.id }, "opt_object") +if not tmp or tmp.text_entries_left < 1 then slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") return false end