liquid_feedback_frontend
view app/main/registration_admin/_action/update_verification.lua @ 1362:f6c0681aad68
Added generation of sequential number
author | bsw |
---|---|
date | Mon Aug 06 14:12:03 2018 +0200 (2018-08-06) |
parents | 7532831a7618 |
children | 4664e021473f |
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.type ~= "image" then
30 value = string.gsub(value, "^%s+", "")
31 value = string.gsub(value, "%s+$", "")
32 value = string.gsub(value, "%s+", " ")
33 elseif field.name == "sequential_number" then
34 value = old_verification_data.sequential_number
35 if not value then
36 local last_sequential_number = 0
37 db:query('LOCK TABLE "verification" IN SHARE ROW EXCLUSIVE MODE')
38 local max_record = Verification:new_selector()
39 :reset_fields()
40 :add_field("max((verification_data->>'sequential_number')::int8)")
41 :optional_object_mode()
42 :exec()
43 if max_record then
44 last_sequential_number = max_record.verification_data.sequential_number
45 end
46 value = last_sequential_number + 1
47 end
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