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