bsw/jbe@5: local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object") bsw/jbe@5: if tmp and tmp.text_entries_left and 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@281: error("access denied") 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@279: local formatting_engine = param.get("formatting_engine") bsw@279: bsw@279: local formatting_engine_valid = false bsw@279: for fe, dummy in pairs(config.formatting_engine_executeables) do bsw@279: if formatting_engine == fe then bsw@279: formatting_engine_valid = true bsw@279: end bsw@279: end bsw@279: if not formatting_engine_valid then bsw@279: error("invalid formatting engine!") 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/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@0: slot.put_into("notice", _"Your suggestion has been added")