liquid_feedback_frontend

annotate app/main/initiative/_action/create.lua @ 1190:9700ce0d5541

Update installation instructions regarding Moonbridge command line options; Typo in heading of installation instructions fixed
author jbe
date Sun Mar 29 20:31:32 2015 +0200 (2015-03-29)
parents 9604ba51624a
children 32cc544d5a5b
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@1045 76 slot.put_into("error", _"Please enter a meaningful title for your initiative!")
bsw@1045 77 return false
bsw@1045 78 end
bsw@1045 79
bsw@1045 80 if #name > 140 then
bsw@1045 81 slot.put_into("error", _"This title is too long!")
bsw/jbe@6 82 return false
bsw/jbe@6 83 end
bsw/jbe@6 84
bsw@1045 85 local formatting_engine
bsw@1045 86 if config.enforce_formatting_engine then
bsw@1045 87 formatting_engine = config.enforce_formatting_engine
bsw@1045 88 else
bsw@1045 89 formatting_engine = param.get("formatting_engine")
bsw@1045 90 local formatting_engine_valid = false
bsw@1045 91 for i, fe in ipairs(config.formatting_engines) do
bsw@1045 92 if formatting_engine == fe.id then
bsw@1045 93 formatting_engine_valid = true
bsw@1045 94 end
bsw@1045 95 end
bsw@1045 96 if not formatting_engine_valid then
bsw@1045 97 error("invalid formatting engine!")
bsw@81 98 end
bsw@81 99 end
bsw@81 100
bsw@1092 101 local timing
bsw@1096 102 if not issue and policy.free_timeable then
bsw@1092 103 local free_timing_string = util.trim(param.get("free_timing"))
bsw@1092 104 if not free_timing_string or #free_timing_string < 1 then
bsw@1092 105 slot.put_into("error", _"Choose timing")
bsw@1092 106 return false
bsw@1092 107 end
bsw@1092 108 local available_timings
bsw@1092 109 if config.free_timing and config.free_timing.available_func then
bsw@1092 110 available_timings = config.free_timing.available_func(policy)
bsw@1092 111 if available_timings == false then
bsw@1092 112 error("error in free timing config")
bsw@1092 113 end
bsw@1092 114 end
bsw@1092 115 if available_timings then
bsw@1092 116 local timing_available = false
bsw@1092 117 for i, available_timing in ipairs(available_timings) do
bsw@1092 118 if available_timing.id == free_timing_string then
bsw@1092 119 timing_available = true
bsw@1092 120 end
bsw@1092 121 end
bsw@1092 122 if not timing_available then
bsw@1092 123 slot.put_into("error", _"Invalid timing")
bsw@1092 124 return false
bsw@1092 125 end
bsw@1092 126 end
bsw@1092 127 timing = config.free_timing.calculate_func(policy, free_timing_string)
bsw@1092 128 if not timing then
bsw@1092 129 error("error in free timing config")
bsw@1092 130 end
bsw@1092 131 end
bsw@1092 132
bsw@1045 133 if param.get("preview") or param.get("edit") then
bsw@95 134 return
bsw@95 135 end
bsw@81 136
bsw/jbe@0 137 local initiative = Initiative:new()
bsw/jbe@0 138
bsw/jbe@0 139 if not issue then
bsw/jbe@0 140 issue = Issue:new()
bsw/jbe@0 141 issue.area_id = area.id
bsw@7 142 issue.policy_id = policy_id
bsw@898 143
bsw@898 144 if policy.polling then
bsw@898 145 issue.accepted = 'now'
bsw@898 146 issue.state = 'discussion'
bsw@898 147 initiative.polling = true
bsw@901 148
bsw@901 149 if policy.free_timeable then
bsw@901 150 issue.discussion_time = timing.discussion
bsw@901 151 issue.verification_time = timing.verification
bsw@901 152 issue.voting_time = timing.voting
bsw@901 153 end
bsw@901 154
bsw@898 155 end
bsw@898 156
bsw/jbe@0 157 issue:save()
bsw@286 158
bsw@286 159 if config.etherpad then
bsw@286 160 local result = net.curl(
bsw@286 161 config.etherpad.api_base
bsw@286 162 .. "api/1/createGroupPad?apikey=" .. config.etherpad.api_key
bsw@286 163 .. "&groupID=" .. config.etherpad.group_id
bsw@286 164 .. "&padName=Issue" .. tostring(issue.id)
jbe@326 165 .. "&text=" .. request.get_absolute_baseurl() .. "issue/show/" .. tostring(issue.id) .. ".html"
bsw@286 166 )
bsw@286 167 end
bsw/jbe@0 168 end
bsw/jbe@0 169
bsw@898 170 if param.get("polling", atom.boolean) and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
bsw@898 171 initiative.polling = true
bsw@898 172 end
bsw/jbe@0 173 initiative.issue_id = issue.id
bsw/jbe@6 174 initiative.name = name
bsw/jbe@0 175 initiative:save()
bsw/jbe@0 176
bsw/jbe@0 177 local draft = Draft:new()
bsw/jbe@0 178 draft.initiative_id = initiative.id
bsw/jbe@4 179 draft.formatting_engine = formatting_engine
bsw/jbe@0 180 draft.content = param.get("draft")
bsw/jbe@0 181 draft.author_id = app.session.member.id
bsw/jbe@0 182 draft:save()
bsw/jbe@0 183
bsw/jbe@0 184 local initiator = Initiator:new()
bsw/jbe@0 185 initiator.initiative_id = initiative.id
bsw/jbe@0 186 initiator.member_id = app.session.member.id
bsw@10 187 initiator.accepted = true
bsw/jbe@0 188 initiator:save()
bsw/jbe@0 189
bsw@944 190 if not is_polling then
bsw@944 191 local supporter = Supporter:new()
bsw@944 192 supporter.initiative_id = initiative.id
bsw@944 193 supporter.member_id = app.session.member.id
bsw@944 194 supporter.draft_id = draft.id
bsw@944 195 supporter:save()
bsw@944 196 end
bsw/jbe@0 197
bsw/jbe@0 198 slot.put_into("notice", _"Initiative successfully created")
bsw/jbe@0 199
bsw/jbe@0 200 request.redirect{
bsw/jbe@0 201 module = "initiative",
bsw/jbe@0 202 view = "show",
bsw/jbe@0 203 id = initiative.id
jbe@326 204 }

Impressum / About Us