bsw@904: local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND NOT polling", app.session.member.id }, "opt_object") bsw@904: if not tmp or tmp.text_entries_left < 1 then bsw/jbe@5: slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...") bsw/jbe@5: return false bsw/jbe@5: end bsw/jbe@0: bsw@281: local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) bsw@281: if not app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id) then bsw/jbe@1309: return execute.view { module = "index", view = "403" } bsw@281: end bsw@281: bsw@281: bsw/jbe@6: local name = param.get("name") bsw/jbe@6: local name = util.trim(name) bsw/jbe@6: bsw/jbe@6: if #name < 3 then bsw/jbe@6: slot.put_into("error", _"This title is really too short!") bsw/jbe@6: return false bsw/jbe@6: end bsw/jbe@6: bsw@1045: local formatting_engine = param.get("formatting_engine") or config.enforce_formatting_engine bsw@279: bsw@279: local formatting_engine_valid = false bsw@1045: for i, fe in ipairs(config.formatting_engines) do bsw@1045: if formatting_engine == fe.id then bsw@279: formatting_engine_valid = true bsw@279: end bsw@279: end bsw@279: if not formatting_engine_valid then bsw/jbe@1309: slot.put_into("error", "invalid formatting engine!") bsw/jbe@1309: return false bsw@279: end bsw@279: bsw@279: if param.get("preview") then bsw@279: return bsw@279: end bsw@279: bsw/jbe@0: local suggestion = Suggestion:new() bsw/jbe@0: bsw/jbe@0: suggestion.author_id = app.session.member.id bsw/jbe@6: suggestion.name = name bsw@279: suggestion.formatting_engine = formatting_engine bsw@279: param.update(suggestion, "content", "initiative_id") bsw/jbe@0: suggestion:save() bsw/jbe@0: bsw/jbe@5: -- TODO important m1 selectors returning result _SET_! bsw/jbe@5: local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec() bsw/jbe@5: bsw/jbe@5: if issue.closed then bsw/jbe@5: slot.put_into("error", _"This issue is already closed.") bsw/jbe@5: return false bsw@41: elseif issue.half_frozen then bsw@41: slot.put_into("error", _"This issue is already frozen.") bsw/jbe@5: return false bsw@964: elseif bsw@964: (issue.half_frozen and issue.phase_finished) or bsw@964: (not issue.accepted and issue.phase_finished) bsw@964: then bsw@964: slot.put_into("error", _"Current phase is already closed.") bsw@964: return false bsw/jbe@5: end bsw/jbe@5: bsw/jbe@0: local opinion = Opinion:new() bsw/jbe@0: bsw/jbe@0: opinion.suggestion_id = suggestion.id bsw/jbe@0: opinion.member_id = app.session.member.id bsw/jbe@0: opinion.degree = param.get("degree", atom.integer) bsw/jbe@0: opinion.fulfilled = false bsw/jbe@0: bsw/jbe@0: opinion:save() bsw/jbe@0: bsw/jbe@1309: slot.put_into("notice", _"Your suggestion has been added")