liquid_feedback_frontend

view app/main/suggestion/_action/add.lua @ 281:b77e6a17ca77

Check unit voting right where neccessary, hide action buttons for units without voting right
author bsw
date Thu Feb 16 15:01:49 2012 +0100 (2012-02-16)
parents 23c98752e697
children a176129ce282
line source
1 local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
2 if tmp and tmp.text_entries_left and tmp.text_entries_left < 1 then
3 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
4 return false
5 end
7 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
8 if not app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id) then
9 error("access denied")
10 end
13 local name = param.get("name")
14 local name = util.trim(name)
16 if #name < 3 then
17 slot.put_into("error", _"This title is really too short!")
18 return false
19 end
21 local formatting_engine = param.get("formatting_engine")
23 local formatting_engine_valid = false
24 for fe, dummy in pairs(config.formatting_engine_executeables) do
25 if formatting_engine == fe then
26 formatting_engine_valid = true
27 end
28 end
29 if not formatting_engine_valid then
30 error("invalid formatting engine!")
31 end
33 if param.get("preview") then
34 return
35 end
37 local suggestion = Suggestion:new()
39 suggestion.author_id = app.session.member.id
40 suggestion.name = name
41 suggestion.formatting_engine = formatting_engine
42 param.update(suggestion, "content", "initiative_id")
43 suggestion:save()
45 -- TODO important m1 selectors returning result _SET_!
46 local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
48 if issue.closed then
49 slot.put_into("error", _"This issue is already closed.")
50 return false
51 elseif issue.half_frozen then
52 slot.put_into("error", _"This issue is already frozen.")
53 return false
54 end
56 local opinion = Opinion:new()
58 opinion.suggestion_id = suggestion.id
59 opinion.member_id = app.session.member.id
60 opinion.degree = param.get("degree", atom.integer)
61 opinion.fulfilled = false
63 opinion:save()
65 slot.put_into("notice", _"Your suggestion has been added")

Impressum / About Us