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