liquid_feedback_frontend
diff app/main/initiative/_action/create.lua @ 904:a176129ce282
Add support for poll mode; Forbid postings unless contingents are configured
author | bsw |
---|---|
date | Sun Aug 26 22:37:49 2012 +0200 (2012-08-26) |
parents | f3d6d08b0125 |
children | 9d82c11a93b1 |
line diff
1.1 --- a/app/main/initiative/_action/create.lua Tue Aug 21 01:29:28 2012 +0200 1.2 +++ b/app/main/initiative/_action/create.lua Sun Aug 26 22:37:49 2012 +0200 1.3 @@ -1,15 +1,3 @@ 1.4 -local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object") 1.5 -if tmp then 1.6 - if tmp.initiatives_left and tmp.initiatives_left < 1 then 1.7 - slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.") 1.8 - return false 1.9 - end 1.10 - if tmp.text_entries_left and tmp.text_entries_left < 1 then 1.11 - slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") 1.12 - return false 1.13 - end 1.14 -end 1.15 - 1.16 local issue 1.17 local area 1.18 1.19 @@ -37,6 +25,46 @@ 1.20 error("access denied") 1.21 end 1.22 1.23 +local policy_id = param.get("policy_id", atom.integer) 1.24 +local policy 1.25 +if policy_id then 1.26 + policy = Policy:by_id(policy_id) 1.27 +end 1.28 + 1.29 +if not issue then 1.30 + if policy_id == -1 then 1.31 + slot.put_into("error", _"Please choose a policy") 1.32 + return false 1.33 + end 1.34 + if not policy.active then 1.35 + slot.put_into("error", "Invalid policy.") 1.36 + return false 1.37 + end 1.38 + if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then 1.39 + error("no polling right for this unit") 1.40 + end 1.41 + 1.42 + if not area:get_reference_selector("allowed_policies") 1.43 + :add_where{ "policy.id = ?", policy_id } 1.44 + :optional_object_mode() 1.45 + :exec() 1.46 + then 1.47 + error("policy not allowed") 1.48 + end 1.49 +end 1.50 + 1.51 +local is_polling = (issue and param.get("polling", atom.boolean)) or (policy and policy.polling) or false 1.52 + 1.53 +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") 1.54 +if not tmp or tmp.initiatives_left < 1 then 1.55 + slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.") 1.56 + return false 1.57 +end 1.58 +if tmp and tmp.text_entries_left < 1 then 1.59 + slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") 1.60 + return false 1.61 +end 1.62 + 1.63 local name = param.get("name") 1.64 1.65 local name = util.trim(name) 1.66 @@ -66,27 +94,6 @@ 1.67 local initiative = Initiative:new() 1.68 1.69 if not issue then 1.70 - local policy_id = param.get("policy_id", atom.integer) 1.71 - if policy_id == -1 then 1.72 - slot.put_into("error", _"Please choose a policy") 1.73 - return false 1.74 - end 1.75 - local policy = Policy:by_id(policy_id) 1.76 - if not policy.active then 1.77 - slot.put_into("error", "Invalid policy.") 1.78 - return false 1.79 - end 1.80 - if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then 1.81 - error("no polling right for this unit") 1.82 - end 1.83 - 1.84 - if not area:get_reference_selector("allowed_policies") 1.85 - :add_where{ "policy.id = ?", policy_id } 1.86 - :optional_object_mode() 1.87 - :exec() 1.88 - then 1.89 - error("policy not allowed") 1.90 - end 1.91 issue = Issue:new() 1.92 issue.area_id = area.id 1.93 issue.policy_id = policy_id