1 | |
---|
2 | |
---|
3 | |
---|
4 | /** |
---|
5 | * Authority Controller. |
---|
6 | */ |
---|
7 | class AuthorityController { |
---|
8 | |
---|
9 | // the delete, save and update actions only accept POST requests |
---|
10 | static Map allowedMethods = [delete: 'POST', save: 'POST', update: 'POST'] |
---|
11 | |
---|
12 | def authenticateService |
---|
13 | |
---|
14 | def index = { |
---|
15 | redirect action: list, params: params |
---|
16 | } |
---|
17 | |
---|
18 | /** |
---|
19 | * Display the list authority page. |
---|
20 | */ |
---|
21 | def list = { |
---|
22 | if (!params.max) { |
---|
23 | params.max = 10 |
---|
24 | } |
---|
25 | [authorityList: Authority.list(params)] |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * Display the show authority page. |
---|
30 | */ |
---|
31 | def show = { |
---|
32 | def authority = Authority.get(params.id) |
---|
33 | if (!authority) { |
---|
34 | flash.message = "Authority not found with id $params.id" |
---|
35 | redirect action: list |
---|
36 | return |
---|
37 | } |
---|
38 | |
---|
39 | [authority: authority] |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * Delete an authority. |
---|
44 | */ |
---|
45 | def delete = { |
---|
46 | def authority = Authority.get(params.id) |
---|
47 | if (!authority) { |
---|
48 | flash.message = "Authority not found with id $params.id" |
---|
49 | redirect action: list |
---|
50 | return |
---|
51 | } |
---|
52 | |
---|
53 | authenticateService.deleteRole(authority) |
---|
54 | |
---|
55 | flash.message = "Authority $params.id deleted." |
---|
56 | redirect action: list |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Display the edit authority page. |
---|
61 | */ |
---|
62 | def edit = { |
---|
63 | def authority = Authority.get(params.id) |
---|
64 | if (!authority) { |
---|
65 | flash.message = "Authority not found with id $params.id" |
---|
66 | redirect action: list |
---|
67 | return |
---|
68 | } |
---|
69 | |
---|
70 | [authority: authority] |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Authority update action. |
---|
75 | */ |
---|
76 | def update = { |
---|
77 | |
---|
78 | def authority = Authority.get(params.id) |
---|
79 | if (!authority) { |
---|
80 | flash.message = "Authority not found with id $params.id" |
---|
81 | redirect action: edit, id: params.id |
---|
82 | return |
---|
83 | } |
---|
84 | |
---|
85 | long version = params.version.toLong() |
---|
86 | if (authority.version > version) { |
---|
87 | authority.errors.rejectValue 'version', 'authority.optimistic.locking.failure', |
---|
88 | 'Another user has updated this Authority while you were editing.' |
---|
89 | render view: 'edit', model: [authority: authority] |
---|
90 | return |
---|
91 | } |
---|
92 | |
---|
93 | if (authenticateService.updateRole(authority, params)) { |
---|
94 | authenticateService.clearCachedRequestmaps() |
---|
95 | redirect action: show, id: authority.id |
---|
96 | } |
---|
97 | else { |
---|
98 | render view: 'edit', model: [authority: authority] |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Display the create new authority page. |
---|
104 | */ |
---|
105 | def create = { |
---|
106 | [authority: new Authority()] |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * Save a new authority. |
---|
111 | */ |
---|
112 | def save = { |
---|
113 | |
---|
114 | def authority = new Authority() |
---|
115 | authority.properties = params |
---|
116 | if (authority.save()) { |
---|
117 | redirect action: show, id: authority.id |
---|
118 | } |
---|
119 | else { |
---|
120 | render view: 'create', model: [authority: authority] |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|