liquid_feedback_frontend

changeset 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 dd6c00eb215f
children e3887fea39fa
files app/main/draft/_action/add.lua app/main/initiative/_action/create.lua app/main/initiative/new.lua app/main/suggestion/_action/add.lua
line diff
     1.1 --- a/app/main/draft/_action/add.lua	Tue Aug 21 01:29:28 2012 +0200
     1.2 +++ b/app/main/draft/_action/add.lua	Sun Aug 26 22:37:49 2012 +0200
     1.3 @@ -1,9 +1,3 @@
     1.4 -local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     1.5 -if tmp and tmp.text_entries_left and tmp.text_entries_left < 1 then
     1.6 -  slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
     1.7 -  return false
     1.8 -end
     1.9 -
    1.10  local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
    1.11  
    1.12  -- TODO important m1 selectors returning result _SET_!
    1.13 @@ -22,6 +16,12 @@
    1.14    error("access denied")
    1.15  end
    1.16  
    1.17 +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")
    1.18 +if not tmp or tmp.text_entries_left < 1 then
    1.19 +  slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
    1.20 +  return false
    1.21 +end
    1.22 +
    1.23  local formatting_engine = param.get("formatting_engine")
    1.24  
    1.25  local formatting_engine_valid = false
     2.1 --- a/app/main/initiative/_action/create.lua	Tue Aug 21 01:29:28 2012 +0200
     2.2 +++ b/app/main/initiative/_action/create.lua	Sun Aug 26 22:37:49 2012 +0200
     2.3 @@ -1,15 +1,3 @@
     2.4 -local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     2.5 -if tmp then
     2.6 -  if tmp.initiatives_left and tmp.initiatives_left < 1 then
     2.7 -    slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
     2.8 -    return false
     2.9 -  end
    2.10 -  if tmp.text_entries_left and tmp.text_entries_left < 1 then
    2.11 -    slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
    2.12 -    return false
    2.13 -  end
    2.14 -end
    2.15 -
    2.16  local issue
    2.17  local area
    2.18  
    2.19 @@ -37,6 +25,46 @@
    2.20    error("access denied")
    2.21  end
    2.22  
    2.23 +local policy_id = param.get("policy_id", atom.integer)
    2.24 +local policy
    2.25 +if policy_id then
    2.26 +  policy = Policy:by_id(policy_id)
    2.27 +end
    2.28 +
    2.29 +if not issue then
    2.30 +  if policy_id == -1 then
    2.31 +    slot.put_into("error", _"Please choose a policy")
    2.32 +    return false
    2.33 +  end
    2.34 +  if not policy.active then
    2.35 +    slot.put_into("error", "Invalid policy.")
    2.36 +    return false
    2.37 +  end
    2.38 +  if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    2.39 +    error("no polling right for this unit")
    2.40 +  end
    2.41 +  
    2.42 +  if not area:get_reference_selector("allowed_policies")
    2.43 +    :add_where{ "policy.id = ?", policy_id }
    2.44 +    :optional_object_mode()
    2.45 +    :exec()
    2.46 +  then
    2.47 +    error("policy not allowed")
    2.48 +  end
    2.49 +end
    2.50 +
    2.51 +local is_polling = (issue and param.get("polling", atom.boolean)) or (policy and policy.polling) or false
    2.52 +
    2.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")
    2.54 +if not tmp or tmp.initiatives_left < 1 then
    2.55 +  slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
    2.56 +  return false
    2.57 +end
    2.58 +if tmp and tmp.text_entries_left < 1 then
    2.59 +  slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
    2.60 +  return false
    2.61 +end
    2.62 +
    2.63  local name = param.get("name")
    2.64  
    2.65  local name = util.trim(name)
    2.66 @@ -66,27 +94,6 @@
    2.67  local initiative = Initiative:new()
    2.68  
    2.69  if not issue then
    2.70 -  local policy_id = param.get("policy_id", atom.integer)
    2.71 -  if policy_id == -1 then
    2.72 -    slot.put_into("error", _"Please choose a policy")
    2.73 -    return false
    2.74 -  end
    2.75 -  local policy = Policy:by_id(policy_id)
    2.76 -  if not policy.active then
    2.77 -    slot.put_into("error", "Invalid policy.")
    2.78 -    return false
    2.79 -  end
    2.80 -  if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    2.81 -    error("no polling right for this unit")
    2.82 -  end
    2.83 -  
    2.84 -  if not area:get_reference_selector("allowed_policies")
    2.85 -    :add_where{ "policy.id = ?", policy_id }
    2.86 -    :optional_object_mode()
    2.87 -    :exec()
    2.88 -  then
    2.89 -    error("policy not allowed")
    2.90 -  end
    2.91    issue = Issue:new()
    2.92    issue.area_id = area.id
    2.93    issue.policy_id = policy_id
     3.1 --- a/app/main/initiative/new.lua	Tue Aug 21 01:29:28 2012 +0200
     3.2 +++ b/app/main/initiative/new.lua	Sun Aug 26 22:37:49 2012 +0200
     3.3 @@ -11,6 +11,8 @@
     3.4    area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
     3.5  end
     3.6  
     3.7 +local polling = param.get("polling", atom.boolean)
     3.8 +
     3.9  local policy_id = param.get("policy_id", atom.integer)
    3.10  local policy
    3.11  
    3.12 @@ -62,7 +64,7 @@
    3.13      slot.put("<br />")
    3.14      if issue_id then
    3.15        ui.field.text{ label = _"Issue",  value = issue_id }
    3.16 -    elseif policy_id then
    3.17 +    elseif policy then
    3.18        ui.field.hidden{ name = "policy_id", value = policy.id }
    3.19        ui.field.text{ label = _"Policy",  value = policy.name }
    3.20        if policy.free_timeable then
    3.21 @@ -89,7 +91,7 @@
    3.22      else
    3.23        tmp = { { id = -1, name = _"Please choose a policy" } }
    3.24        for i, allowed_policy in ipairs(area.allowed_policies) do
    3.25 -        if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    3.26 +        if not allowed_policy.polling then
    3.27            tmp[#tmp+1] = allowed_policy
    3.28          end
    3.29        end
    3.30 @@ -130,7 +132,7 @@
    3.31      end
    3.32      
    3.33      if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    3.34 -      ui.field.boolean{ name = "polling", label = _"Poll" }
    3.35 +      ui.field.boolean{ name = "polling", label = _"Poll", value = polling }
    3.36      end
    3.37      
    3.38      if preview then
     4.1 --- a/app/main/suggestion/_action/add.lua	Tue Aug 21 01:29:28 2012 +0200
     4.2 +++ b/app/main/suggestion/_action/add.lua	Sun Aug 26 22:37:49 2012 +0200
     4.3 @@ -1,5 +1,5 @@
     4.4 -local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     4.5 -if tmp and tmp.text_entries_left and tmp.text_entries_left < 1 then
     4.6 +local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND NOT polling", app.session.member.id }, "opt_object")
     4.7 +if not tmp or tmp.text_entries_left < 1 then
     4.8    slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
     4.9    return false
    4.10  end

Impressum / About Us