source: trunk/grails-app/controllers/SiteDetailedController.groovy @ 289

Last change on this file since 289 was 289, checked in by gav, 14 years ago

Set some permissions on Site and Section controllers.
Detail some site views missed in last commit.

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