liquid_feedback_frontend

view app/main/registration_admin/_action/update_verification.lua @ 1364:291db816e078

Fixed record access
author bsw
date Mon Aug 06 14:14:02 2018 +0200 (2018-08-06)
parents 4664e021473f
children c52286bd8d98
line source
1 local verification = Verification:by_id(param.get_id())
3 local function update_data()
4 local old_verification_data = verification.verification_data or {}
5 verification.verification_data = json.object()
7 for i, field in ipairs(config.self_registration.fields) do
8 local value = param.get(field.name)
9 if field.name == "fiscal_code" then
10 value = string.gsub(value, "[^A-Z0-9]", "")
11 elseif field.name == "mobile_phone" then
12 value = string.gsub(value, "[^0-9]", "")
13 elseif field.name == "unit" then
14 value = string.gsub(value, "[^0-9]", "")
15 if old_verification_data.unit and old_verification_data.unit ~= "" then
16 local old_unit_privilege = Privilege:by_pk(old_verification_data.unit, verification.verified_member_id)
17 if old_unit_privilege then
18 old_unit_privilege:destroy()
19 end
20 end
21 if value ~= old_verification_data.unit and value ~= "" then
22 local unit_privilege = Privilege:new()
23 unit_privilege.member_id = verification.verified_member_id
24 unit_privilege.unit_id = tonumber(value)
25 unit_privilege.voting_right = true
26 unit_privilege.initiative_right = true
27 unit_privilege:save()
28 end
29 elseif field.name == "sequential_number" then
30 value = old_verification_data.sequential_number
31 if not value then
32 local last_sequential_number = 0
33 db:query('LOCK TABLE "verification" IN SHARE ROW EXCLUSIVE MODE')
34 local record = Verification:new_selector()
35 :reset_fields()
36 :add_field("max((verification_data->>'sequential_number')::int8)", "max_sequential_number")
37 :optional_object_mode()
38 :exec()
39 if record then
40 last_sequential_number = record.max_sequential_number
41 end
42 value = last_sequential_number + 1
43 end
44 elseif field.type ~= "image" then
45 value = string.gsub(value, "^%s+", "")
46 value = string.gsub(value, "%s+$", "")
47 value = string.gsub(value, "%s+", " ")
48 end
49 verification.verification_data[field.name] = value
50 end
51 end
53 if verification.verified_member_id then
55 local member = Member:by_id(verification.verified_member_id)
57 if param.get("cancel") then
58 db:query({ "SELECT delete_member(?)", member.id })
59 return
60 end
62 member.identification = param.get("identification")
63 member.notify_email = param.get("email")
64 member:save()
66 update_data()
68 verification:save()
70 if param.get("invite") then
71 member:send_invitation()
72 end
74 elseif param.get("drop") then
76 verification.denied = "now"
77 verification:save()
78 return
80 elseif param.get("accredit") then
82 local member = Member:by_id(verification.requesting_member_id)
83 member.identification = param.get("identification")
84 member.notify_email = param.get("email")
85 member:save()
86 member:send_invitation()
88 for i, unit_id in ipairs(config.self_registration.grant_privileges_for_unit_ids) do
89 local privilege = Privilege:new()
90 privilege.member_id = member.id
91 privilege.unit_id = unit_id
92 privilege.initiative_right = true
93 privilege.voting_right = true
94 privilege:save()
95 end
97 update_data()
99 verification.verified_member_id = verification.requesting_member_id
100 verification.verifying_member_id = app.session.member_id
101 verification.verified = "now"
103 verification:save()
106 else
108 update_data()
109 verification:save()
111 end

Impressum / About Us