liquid_feedback_frontend

view app/main/initiative/_action/create.lua @ 944:9d82c11a93b1

Do not add own support when creating issue/initiative in poll mode
author bsw
date Tue Nov 06 21:28:25 2012 +0100 (2012-11-06)
parents a176129ce282
children a1970614203a
line source
1 local issue
2 local area
4 local issue_id = param.get("issue_id", atom.integer)
5 if issue_id then
6 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
7 if issue.closed then
8 slot.put_into("error", _"This issue is already closed.")
9 return false
10 elseif issue.fully_frozen then
11 slot.put_into("error", _"Voting for this issue has already begun.")
12 return false
13 end
14 area = issue.area
15 else
16 local area_id = param.get("area_id", atom.integer)
17 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
18 if not area.active then
19 slot.put_into("error", "Invalid area.")
20 return false
21 end
22 end
24 if not app.session.member:has_voting_right_for_unit_id(area.unit_id) then
25 error("access denied")
26 end
28 local policy_id = param.get("policy_id", atom.integer)
29 local policy
30 if policy_id then
31 policy = Policy:by_id(policy_id)
32 end
34 if not issue then
35 if policy_id == -1 then
36 slot.put_into("error", _"Please choose a policy")
37 return false
38 end
39 if not policy.active then
40 slot.put_into("error", "Invalid policy.")
41 return false
42 end
43 if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
44 error("no polling right for this unit")
45 end
47 if not area:get_reference_selector("allowed_policies")
48 :add_where{ "policy.id = ?", policy_id }
49 :optional_object_mode()
50 :exec()
51 then
52 error("policy not allowed")
53 end
54 end
56 local is_polling = (issue and param.get("polling", atom.boolean)) or (policy and policy.polling) or false
58 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")
59 if not tmp or tmp.initiatives_left < 1 then
60 slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
61 return false
62 end
63 if tmp and tmp.text_entries_left < 1 then
64 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
65 return false
66 end
68 local name = param.get("name")
70 local name = util.trim(name)
72 if #name < 3 then
73 slot.put_into("error", _"This name is really too short!")
74 return false
75 end
77 local formatting_engine = param.get("formatting_engine")
79 local formatting_engine_valid = false
80 for fe, dummy in pairs(config.formatting_engine_executeables) do
81 if formatting_engine == fe then
82 formatting_engine_valid = true
83 end
84 end
85 if not formatting_engine_valid then
86 error("invalid formatting engine!")
87 end
89 if param.get("preview") then
90 return
91 end
94 local initiative = Initiative:new()
96 if not issue then
97 issue = Issue:new()
98 issue.area_id = area.id
99 issue.policy_id = policy_id
101 if policy.polling then
102 issue.accepted = 'now'
103 issue.state = 'discussion'
104 initiative.polling = true
106 if policy.free_timeable then
107 local free_timing_string = util.trim(param.get("free_timing"))
108 local available_timings
109 if config.free_timing and config.free_timing.available_func then
110 available_timings = config.free_timing.available_func(policy)
111 if available_timings == false then
112 error("error in free timing config")
113 end
114 end
115 if available_timings then
116 local timing_available = false
117 for i, available_timing in ipairs(available_timings) do
118 if available_timing.id == free_timing_string then
119 timing_available = true
120 end
121 end
122 if not timing_available then
123 error('Invalid timing')
124 end
125 end
126 local timing = config.free_timing.calculate_func(policy, free_timing_string)
127 if not timing then
128 error("error in free timing config")
129 end
130 issue.discussion_time = timing.discussion
131 issue.verification_time = timing.verification
132 issue.voting_time = timing.voting
133 end
135 end
137 issue:save()
139 if config.etherpad then
140 local result = net.curl(
141 config.etherpad.api_base
142 .. "api/1/createGroupPad?apikey=" .. config.etherpad.api_key
143 .. "&groupID=" .. config.etherpad.group_id
144 .. "&padName=Issue" .. tostring(issue.id)
145 .. "&text=" .. request.get_absolute_baseurl() .. "issue/show/" .. tostring(issue.id) .. ".html"
146 )
147 end
148 end
150 if param.get("polling", atom.boolean) and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
151 initiative.polling = true
152 end
153 initiative.issue_id = issue.id
154 initiative.name = name
155 param.update(initiative, "discussion_url")
156 initiative:save()
158 local draft = Draft:new()
159 draft.initiative_id = initiative.id
160 draft.formatting_engine = formatting_engine
161 draft.content = param.get("draft")
162 draft.author_id = app.session.member.id
163 draft:save()
165 local initiator = Initiator:new()
166 initiator.initiative_id = initiative.id
167 initiator.member_id = app.session.member.id
168 initiator.accepted = true
169 initiator:save()
171 if not is_polling then
172 local supporter = Supporter:new()
173 supporter.initiative_id = initiative.id
174 supporter.member_id = app.session.member.id
175 supporter.draft_id = draft.id
176 supporter:save()
177 end
179 slot.put_into("notice", _"Initiative successfully created")
181 request.redirect{
182 module = "initiative",
183 view = "show",
184 id = initiative.id
185 }

Impressum / About Us