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