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