rev |
line source |
bsw/jbe@0
|
1 local truster_id = app.session.member.id
|
bsw/jbe@0
|
2
|
bsw/jbe@0
|
3 local trustee_id = param.get("trustee_id", atom.integer)
|
bsw/jbe@0
|
4
|
bsw@248
|
5 local unit_id = param.get("unit_id", atom.integer)
|
bsw@248
|
6
|
bsw/jbe@0
|
7 local area_id = param.get("area_id", atom.integer)
|
bsw/jbe@0
|
8
|
bsw/jbe@0
|
9 local issue_id = param.get("issue_id", atom.integer)
|
bsw/jbe@0
|
10
|
bsw/jbe@0
|
11 if issue_id then
|
bsw/jbe@0
|
12 area_id = nil
|
bsw/jbe@0
|
13 end
|
bsw/jbe@0
|
14
|
bsw@529
|
15 local preview = param.get("preview")
|
bsw@529
|
16
|
bsw@529
|
17 if preview == "1" then
|
bsw@529
|
18 request.redirect{ module = "delegation", view = "show", params = {
|
bsw@529
|
19 unit_id = unit_id, area_id = area_id, issue_id = issue_id, preview_trustee_id = trustee_id
|
bsw@529
|
20 } }
|
bsw@529
|
21 return
|
bsw@529
|
22 end
|
bsw@529
|
23
|
bsw@529
|
24
|
bsw@293
|
25 local delegation = Delegation:by_pk(truster_id, unit_id, area_id, issue_id)
|
bsw@293
|
26
|
bsw@293
|
27
|
bsw/jbe@4
|
28 if param.get("delete") or trustee_id == -1 then
|
bsw/jbe@0
|
29
|
bsw/jbe@0
|
30 if delegation then
|
bsw/jbe@0
|
31 delegation:destroy()
|
bsw/jbe@0
|
32 end
|
bsw/jbe@5
|
33
|
bsw/jbe@0
|
34 else
|
bsw@296
|
35
|
bsw@300
|
36 local trustee
|
bsw@300
|
37
|
bsw@300
|
38 if trustee_id then
|
bsw@300
|
39 trustee = Member:by_id(trustee_id)
|
bsw@300
|
40 end
|
bsw/jbe@0
|
41
|
bsw@281
|
42 local check_unit_id
|
bsw@281
|
43 if unit_id then
|
bsw@281
|
44 check_unit_id = unit_id
|
bsw@281
|
45 elseif area_id then
|
bsw@281
|
46 local area = Area:by_id(area_id)
|
bsw@281
|
47 check_unit_id = area.unit_id
|
bsw@281
|
48 else
|
bsw@281
|
49 local issue = Issue:by_id(issue_id)
|
bsw@281
|
50 local area = Area:by_id(issue.area_id)
|
bsw@281
|
51 check_unit_id = area.unit_id
|
bsw@281
|
52 end
|
bsw@296
|
53
|
bsw@300
|
54 if trustee and not trustee:has_voting_right_for_unit_id(check_unit_id) then
|
bsw@296
|
55 slot.put_into("error", _"Trustee has no voting right in this unit")
|
bsw@296
|
56 return false
|
bsw@296
|
57 end
|
bsw@281
|
58
|
bsw@281
|
59 if not app.session.member:has_voting_right_for_unit_id(check_unit_id) then
|
bsw@281
|
60 error("access denied")
|
bsw@281
|
61 end
|
bsw@281
|
62
|
bsw/jbe@0
|
63 if not delegation then
|
bsw/jbe@0
|
64 delegation = Delegation:new()
|
bsw/jbe@0
|
65 delegation.truster_id = truster_id
|
bsw@248
|
66 delegation.unit_id = unit_id
|
bsw/jbe@0
|
67 delegation.area_id = area_id
|
bsw/jbe@0
|
68 delegation.issue_id = issue_id
|
bsw/jbe@5
|
69 if issue_id then
|
bsw/jbe@5
|
70 delegation.scope = "issue"
|
bsw/jbe@5
|
71 elseif area_id then
|
bsw/jbe@5
|
72 delegation.scope = "area"
|
bsw@248
|
73 elseif unit_id then
|
bsw@248
|
74 delegation.scope = "unit"
|
bsw/jbe@5
|
75 end
|
bsw/jbe@0
|
76 end
|
bsw@180
|
77 if trustee_id == 0 then
|
bsw@180
|
78 delegation.trustee_id = nil
|
bsw@180
|
79 else
|
bsw@180
|
80 delegation.trustee_id = trustee_id
|
bsw@180
|
81 end
|
bsw/jbe@0
|
82
|
bsw/jbe@0
|
83 delegation:save()
|
bsw@529
|
84
|
bsw/jbe@0
|
85 end
|
bsw/jbe@0
|
86
|