liquid_feedback_frontend

view app/main/draft/_action/add.lua @ 904:a176129ce282

Add support for poll mode; Forbid postings unless contingents are configured
author bsw
date Sun Aug 26 22:37:49 2012 +0200 (2012-08-26)
parents cda574707b1c
children 1997cf1da04b
line source
1 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
3 -- TODO important m1 selectors returning result _SET_!
4 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
6 if issue.closed then
7 slot.put_into("error", _"This issue is already closed.")
8 return false
9 elseif issue.half_frozen then
10 slot.put_into("error", _"This issue is already frozen.")
11 return false
12 end
14 local initiator = Initiator:by_pk(initiative.id, app.session.member.id)
15 if not initiator or not initiator.accepted then
16 error("access denied")
17 end
19 local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", app.session.member.id, initiative.polling }, "opt_object")
20 if not tmp or tmp.text_entries_left < 1 then
21 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
22 return false
23 end
25 local formatting_engine = param.get("formatting_engine")
27 local formatting_engine_valid = false
28 for fe, dummy in pairs(config.formatting_engine_executeables) do
29 if formatting_engine == fe then
30 formatting_engine_valid = true
31 end
32 end
33 if not formatting_engine_valid then
34 error("invalid formatting engine!")
35 end
37 if param.get("preview") then
38 return false
39 end
41 local draft = Draft:new()
42 draft.author_id = app.session.member.id
43 draft.initiative_id = initiative.id
44 draft.formatting_engine = formatting_engine
45 draft.content = param.get("content")
46 draft:save()
48 local supporter = Supporter:by_pk(initiative.id, app.session.member.id)
50 if supporter then
51 supporter.draft_id = draft.id
52 supporter:save()
53 end
55 draft:render_content()
57 slot.put_into("notice", _"New draft has been added to initiative")

Impressum / About Us