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