liquid_feedback_frontend

annotate app/main/initiative/_action/add_support.lua @ 1499:f8a4260841df

Removed auto-support
author bsw
date Tue Mar 24 16:50:16 2020 +0100 (2020-03-24)
parents 32cc544d5a5b
children 71f54c43d7cb
rev   line source
bsw/jbe@0 1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
bsw/jbe@0 2
bsw@1045 3 local draft_id = param.get("draft_id", atom.integer)
bsw@1045 4
bsw/jbe@5 5 -- TODO important m1 selectors returning result _SET_!
bsw/jbe@5 6 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
bsw/jbe@5 7
bsw@281 8 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
bsw/jbe@1309 9 return execute.view { module = "index", view = "403" }
bsw@281 10 end
bsw@281 11
bsw/jbe@5 12 if issue.closed then
bsw/jbe@5 13 slot.put_into("error", _"This issue is already closed.")
bsw/jbe@5 14 return false
bsw@964 15 elseif issue.fully_frozen then
bsw/jbe@5 16 slot.put_into("error", _"Voting for this issue has already begun.")
bsw/jbe@5 17 return false
bsw@964 18 elseif
bsw@964 19 (issue.half_frozen and issue.phase_finished) or
bsw@964 20 (not issue.accepted and issue.phase_finished)
bsw@964 21 then
bsw@964 22 slot.put_into("error", _"Current phase is already closed.")
bsw@964 23 return false
bsw/jbe@5 24 end
bsw/jbe@5 25
bsw@10 26 if initiative.revoked then
bsw@10 27 slot.put_into("error", _"This initiative is revoked")
bsw@10 28 return false
bsw@10 29 end
bsw@10 30
bsw/jbe@0 31 local member = app.session.member
bsw/jbe@0 32
bsw/jbe@0 33 local supporter = Supporter:by_pk(initiative.id, member.id)
bsw/jbe@0 34
bsw/jbe@0 35 local last_draft = Draft:new_selector()
bsw/jbe@0 36 :add_where{ "initiative_id = ?", initiative.id }
bsw/jbe@0 37 :add_order_by("id DESC")
bsw/jbe@0 38 :limit(1)
bsw/jbe@0 39 :single_object_mode()
bsw/jbe@0 40 :exec()
bsw@1045 41
bsw@1045 42 if draft_id and draft_id ~= last_draft.id then
bsw@1045 43 slot.select("error", function()
bsw@1045 44 ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" }
bsw@1045 45 end)
bsw@1045 46 return false
bsw@1045 47 end
bsw/jbe@0 48
bsw/jbe@0 49 if not supporter then
bsw/jbe@0 50 supporter = Supporter:new()
bsw/jbe@0 51 supporter.member_id = member.id
bsw/jbe@0 52 supporter.initiative_id = initiative.id
bsw/jbe@0 53 supporter.draft_id = last_draft.id
bsw/jbe@0 54 supporter:save()
bsw/jbe@0 55 elseif supporter.draft_id ~= last_draft.id then
bsw/jbe@0 56 supporter.draft_id = last_draft.id
bsw/jbe@0 57 supporter:save()
bsw@1045 58 slot.put_into("notice", _"Your support has been updated to the latest draft")
bsw/jbe@0 59 else
bsw@1045 60 slot.put_into("notice", _"You are already supporting the latest draft")
poelzi@148 61 end
poelzi@148 62

Impressum / About Us