bsw/jbe@0: local member_id = app.session.member.id bsw/jbe@0: bsw/jbe@0: local suggestion_id = param.get("suggestion_id", atom.integer) bsw/jbe@0: bsw/jbe@0: local opinion = Opinion:by_pk(member_id, suggestion_id) bsw/jbe@0: bsw/jbe@6: local suggestion = Suggestion:by_id(suggestion_id) bsw/jbe@6: bsw@1045: local degree = param.get("degree", atom.number) bsw@1045: local fulfilled = param.get("fulfilled", atom.boolean) bsw@1045: bsw@1045: bsw/jbe@6: if not suggestion then bsw/jbe@6: slot.put_into("error", _"This suggestion has been meanwhile deleted") bsw/jbe@6: return false bsw/jbe@6: end bsw/jbe@6: bsw/jbe@5: -- TODO important m1 selectors returning result _SET_! bsw/jbe@6: 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/jbe@5: elseif issue.fully_frozen then bsw/jbe@5: slot.put_into("error", _"Voting for this issue has already begun.") 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@1045: if degree == 0 then bsw@3: if opinion then bsw@3: opinion:destroy() bsw@3: end bsw@280: --slot.put_into("notice", _"Your rating has been deleted") bsw/jbe@0: return bsw/jbe@0: end bsw/jbe@0: bsw@281: if degree ~= 0 and not app.session.member:has_voting_right_for_unit_id(suggestion.initiative.issue.area.unit_id) then bsw/jbe@1309: return execute.view { module = "index", view = "403" } bsw@281: end bsw@281: bsw/jbe@0: if not opinion then bsw/jbe@0: opinion = Opinion:new() bsw/jbe@0: opinion.member_id = member_id bsw/jbe@0: opinion.suggestion_id = suggestion_id bsw/jbe@0: opinion.fulfilled = false bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: bsw/jbe@0: if degree ~= nil then bsw/jbe@0: opinion.degree = degree bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: if fulfilled ~= nil then bsw/jbe@0: opinion.fulfilled = fulfilled bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: opinion:save() bsw/jbe@0: bsw@280: --slot.put_into("notice", _"Your rating has been updated")