liquid_feedback_frontend
view app/main/initiative/_action/create.lua @ 466:e15e8b15ccf5
Show all issues as default in issue list
| author | bsw | 
|---|---|
| date | Tue Mar 13 20:21:48 2012 +0100 (2012-03-13) | 
| parents | 75ce92899049 | 
| children | ae9ab3edff89 | 
 line source
     1 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     2 if tmp then
     3   if tmp.initiatives_left and tmp.initiatives_left < 1 then
     4     slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
     5     return false
     6   end
     7   if tmp.text_entries_left and tmp.text_entries_left < 1 then
     8     slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
     9     return false
    10   end
    11 end
    13 local issue
    14 local area
    16 local issue_id = param.get("issue_id", atom.integer)
    17 if issue_id then
    18   issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
    19   if issue.closed then
    20     slot.put_into("error", _"This issue is already closed.")
    21     return false
    22   elseif issue.fully_frozen then 
    23     slot.put_into("error", _"Voting for this issue has already begun.")
    24     return false
    25   end
    26   area = issue.area
    27 else
    28   local area_id = param.get("area_id", atom.integer)
    29   area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
    30   if not area.active then
    31     slot.put_into("error", "Invalid area.")
    32     return false
    33   end
    34 end
    36 if not app.session.member:has_voting_right_for_unit_id(area.unit_id) then
    37   error("access denied")
    38 end
    40 local name = param.get("name")
    42 local name = util.trim(name)
    44 if #name < 3 then
    45   slot.put_into("error", _"This name is really too short!")
    46   return false
    47 end
    49 local formatting_engine = param.get("formatting_engine")
    51 local formatting_engine_valid = false
    52 for fe, dummy in pairs(config.formatting_engine_executeables) do
    53   if formatting_engine == fe then
    54     formatting_engine_valid = true
    55   end
    56 end
    57 if not formatting_engine_valid then
    58   error("invalid formatting engine!")
    59 end
    61 if param.get("preview") then
    62   return
    63 end
    66 local initiative = Initiative:new()
    68 if not issue then
    69   local policy_id = param.get("policy_id", atom.integer)
    70   if policy_id == -1 then
    71     slot.put_into("error", _"Please choose a policy")
    72     return false
    73   end
    74   local policy = Policy:by_id(policy_id)
    75   if not policy.active then
    76     slot.put_into("error", "Invalid policy.")
    77     return false
    78   end
    79   if not area:get_reference_selector("allowed_policies")
    80     :add_where{ "policy.id = ?", policy_id }
    81     :optional_object_mode()
    82     :exec()
    83   then
    84     error("policy not allowed")
    85   end
    86   issue = Issue:new()
    87   issue.area_id = area.id
    88   issue.policy_id = policy_id
    89   issue:save()
    91   if config.etherpad then
    92     local result = net.curl(
    93       config.etherpad.api_base 
    94       .. "api/1/createGroupPad?apikey=" .. config.etherpad.api_key
    95       .. "&groupID=" .. config.etherpad.group_id
    96       .. "&padName=Issue" .. tostring(issue.id)
    97       .. "&text=" .. request.get_absolute_baseurl() .. "issue/show/" .. tostring(issue.id) .. ".html"
    98     )
    99   end
   100 end
   102 initiative.issue_id = issue.id
   103 initiative.name = name
   104 param.update(initiative, "discussion_url")
   105 initiative:save()
   107 local draft = Draft:new()
   108 draft.initiative_id = initiative.id
   109 draft.formatting_engine = formatting_engine
   110 draft.content = param.get("draft")
   111 draft.author_id = app.session.member.id
   112 draft:save()
   114 local initiator = Initiator:new()
   115 initiator.initiative_id = initiative.id
   116 initiator.member_id = app.session.member.id
   117 initiator.accepted = true
   118 initiator:save()
   120 local supporter = Supporter:new()
   121 supporter.initiative_id = initiative.id
   122 supporter.member_id = app.session.member.id
   123 supporter.draft_id = draft.id
   124 supporter:save()
   126 slot.put_into("notice", _"Initiative successfully created")
   128 request.redirect{
   129   module = "initiative",
   130   view = "show",
   131   id = initiative.id
   132 }
