source: trunk/grails-app/controllers/InventoryLocationDetailedController.groovy @ 298

Last change on this file since 298 was 298, checked in by gav, 10 years ago

Set base authorisations on all controllers.

File size: 4.2 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
4class InventoryLocationDetailedController extends BaseController {
5
6    // the delete, save and update actions only accept POST requests
7    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
8
9    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
10    def index = { redirect(action:list,params:params) }
11
12    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
13    def list = {
14        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
15        [ inventoryLocationInstanceList: InventoryLocation.list( params ), inventoryLocationInstanceTotal: InventoryLocation.count() ]
16    }
17
18    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
19    def show = {
20        def inventoryLocationInstance = InventoryLocation.get( params.id )
21
22        if(!inventoryLocationInstance) {
23            flash.message = "InventoryLocation not found with id ${params.id}"
24            redirect(action:list)
25        }
26        else { return [ inventoryLocationInstance : inventoryLocationInstance ] }
27    }
28
29    def delete = {
30        def inventoryLocationInstance = InventoryLocation.get( params.id )
31        if(inventoryLocationInstance) {
32            try {
33                inventoryLocationInstance.delete(flush:true)
34                flash.message = "InventoryLocation ${params.id} deleted"
35                redirect(action:list)
36            }
37            catch(org.springframework.dao.DataIntegrityViolationException e) {
38                flash.message = "InventoryLocation ${params.id} could not be deleted"
39                redirect(action:show,id:params.id)
40            }
41        }
42        else {
43            flash.message = "InventoryLocation not found with id ${params.id}"
44            redirect(action:list)
45        }
46    }
47
48    def edit = {
49        def inventoryLocationInstance = InventoryLocation.get( params.id )
50
51        if(!inventoryLocationInstance) {
52            flash.message = "InventoryLocation not found with id ${params.id}"
53            redirect(action:list)
54        }
55        else {
56            return [ inventoryLocationInstance : inventoryLocationInstance ]
57        }
58    }
59
60    def update = {
61        def inventoryLocationInstance = InventoryLocation.get( params.id )
62        if(inventoryLocationInstance) {
63            if(params.version) {
64                def version = params.version.toLong()
65                if(inventoryLocationInstance.version > version) {
66                   
67                    inventoryLocationInstance.errors.rejectValue("version", "inventoryLocation.optimistic.locking.failure", "Another user has updated this InventoryLocation while you were editing.")
68                    render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
69                    return
70                }
71            }
72            inventoryLocationInstance.properties = params
73            if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
74                flash.message = "InventoryLocation ${params.id} updated"
75                redirect(action:show,id:inventoryLocationInstance.id)
76            }
77            else {
78                render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
79            }
80        }
81        else {
82            flash.message = "InventoryLocation not found with id ${params.id}"
83            redirect(action:list)
84        }
85    }
86
87    def create = {
88        def inventoryLocationInstance = new InventoryLocation()
89        inventoryLocationInstance.properties = params
90        return ['inventoryLocationInstance':inventoryLocationInstance]
91    }
92
93    def save = {
94        def inventoryLocationInstance = new InventoryLocation(params)
95        if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
96            flash.message = "InventoryLocation ${inventoryLocationInstance.id} created"
97            redirect(action:show,id:inventoryLocationInstance.id)
98        }
99        else {
100            render(view:'create',model:[inventoryLocationInstance:inventoryLocationInstance])
101        }
102    }
103}
Note: See TracBrowser for help on using the repository browser.