Ignore:
Timestamp:
Mar 24, 2009, 2:49:44 PM (16 years ago)
Author:
gav
Message:

Re-arrange the way 'Detailed is used, much nicer and more secure.

Location:
branches/TaskRewrite/src/grails-app
Files:
1 added
2 edited
1 copied
4 moved

Legend:

Unmodified
Added
Removed
  • branches/TaskRewrite/src/grails-app/controllers/TaskController.groovy

    r84 r85  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22
     3@Secured(['ROLE_AppAdmin'])
    34class TaskController extends BaseController {
    45   
     
    67
    78    // the delete, save and update actions only accept POST requests
    8     static allowedMethods = [delete:'POST', deleteDetailed:'POST', save:'POST', saveDetailed:'POST', updateDetailed:'POST']
     9    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
    910
    10     @Secured(['ROLE_AppAdmin'])
    1111    def list = {
    1212        if(!params.max) params.max = 10
    1313        [ taskInstanceList: Task.list( params ) ]
    1414    }
    15 
    16     def listDetailed = {
    17         if(!params.max) params.max = 10
    18         [ taskInstanceList: Task.list( params ) ]
    19     }
    20 
    21     @Secured(['ROLE_AppAdmin'])
    2215    def show = {
    2316        def taskInstance = Task.get( params.id )
     
    2922        else { return [ taskInstance : taskInstance ] }
    3023    }
    31 
    32     def showDetailed = {
    33         def taskInstance = Task.get( params.id )
    34 
    35         if(!taskInstance) {
    36             flash.message = "Task not found with id ${params.id}"
    37             redirect(action:list)
    38         }
    39         else { return [ taskInstance : taskInstance ] }
    40     }
    41 
    42     @Secured(['ROLE_AppAdmin'])     
     24 
    4325    def delete = {
    4426        def taskInstance = Task.get( params.id )
     
    5436    }
    5537
    56     def deleteDetailed = {
    57         def taskInstance = Task.get( params.id )
    58         if(taskInstance) {
    59             taskInstance.delete()
    60             flash.message = "Task ${params.id} deleted"
    61             redirect(action:list)
    62         }
    63         else {
    64             flash.message = "Task not found with id ${params.id}"
    65             redirect(action:list)
    66         }
    67     }
    68 
    69     @Secured(['ROLE_AppAdmin'])
    7038    def edit = {
    7139        def taskInstance = Task.get( params.id )
     
    8048    }
    8149
    82     def editDetailed = {
    83         def taskInstance = Task.get( params.id )
    84 
    85         if(!taskInstance) {
    86             flash.message = "Task not found with id ${params.id}"
    87             redirect(action:list)
    88         }
    89         else {
    90             def criteria = taskInstance.createCriteria()
    91             def results = criteria {
    92                 and {
    93                     notEqual('id', taskInstance.id)
    94                     }
    95             }
    96             return [ taskInstance : taskInstance, possibleParentList: results ]
    97         }
    98     }
    99 
    100     @Secured(['ROLE_AppAdmin'])
    10150    def update = {
    10251        def taskInstance = Task.get( params.id )
     
    11766    }
    11867
    119     def updateDetailed = {
    120         def taskInstance = Task.get( params.id )
    121         if(taskInstance) {
    122             taskInstance.properties = params
    123             if(!taskInstance.hasErrors() && taskInstance.save()) {
    124                 flash.message = "Task ${params.id} updated"
    125                 redirect(action:show,id:taskInstance.id)
    126             }
    127             else {
    128                 render(view:'edit',model:[taskInstance:taskInstance])
    129             }
    130         }
    131         else {
    132             flash.message = "Task not found with id ${params.id}"
    133             redirect(action:edit,id:params.id)
    134         }
    135     }
    136 
    137     @Secured(['ROLE_AppAdmin'])
    13868    def create = {
    13969        def taskInstance = new Task()
     
    14272    }
    14373
    144     def createDetailed = {
    145         def taskInstance = new Task()
    146         taskInstance.properties = params
    147         return ['taskInstance':taskInstance]
    148     }
    149 
    150     @Secured(['ROLE_AppAdmin'])
    15174    def save = {
    15275        def taskInstance = new Task(params)
     
    16083    }
    16184
    162     def saveDetailed = {
    163         def taskInstance = new Task(params)
    164         if(!taskInstance.hasErrors() && taskInstance.save()) {
    165             flash.message = "Task ${taskInstance.id} created"
    166             redirect(action:showDetailed,id:taskInstance.id)
    167         }
    168         else {
    169             render(view:'createDetailed',model:[taskInstance:taskInstance])
    170         }
    171     }
    17285}
  • branches/TaskRewrite/src/grails-app/controllers/TaskDetailedController.groovy

    r84 r85  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22
    3 class TaskController extends BaseController {
     3class TaskDetailedController extends BaseController {
    44   
    55    def index = { redirect(action:list,params:params) }
    66
    77    // the delete, save and update actions only accept POST requests
    8     static allowedMethods = [delete:'POST', deleteDetailed:'POST', save:'POST', saveDetailed:'POST', updateDetailed:'POST']
     8    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
    99
    10     @Secured(['ROLE_AppAdmin'])
    1110    def list = {
    1211        if(!params.max) params.max = 10
     
    1413    }
    1514
    16     def listDetailed = {
    17         if(!params.max) params.max = 10
    18         [ taskInstanceList: Task.list( params ) ]
    19     }
    20 
    21     @Secured(['ROLE_AppAdmin'])
    2215    def show = {
    2316        def taskInstance = Task.get( params.id )
     
    3023    }
    3124
    32     def showDetailed = {
    33         def taskInstance = Task.get( params.id )
    34 
    35         if(!taskInstance) {
    36             flash.message = "Task not found with id ${params.id}"
    37             redirect(action:list)
    38         }
    39         else { return [ taskInstance : taskInstance ] }
    40     }
    41 
    42     @Secured(['ROLE_AppAdmin'])     
    4325    def delete = {
    4426        def taskInstance = Task.get( params.id )
     
    5436    }
    5537
    56     def deleteDetailed = {
    57         def taskInstance = Task.get( params.id )
    58         if(taskInstance) {
    59             taskInstance.delete()
    60             flash.message = "Task ${params.id} deleted"
    61             redirect(action:list)
    62         }
    63         else {
    64             flash.message = "Task not found with id ${params.id}"
    65             redirect(action:list)
    66         }
    67     }
    68 
    69     @Secured(['ROLE_AppAdmin'])
    7038    def edit = {
    71         def taskInstance = Task.get( params.id )
    72 
    73         if(!taskInstance) {
    74             flash.message = "Task not found with id ${params.id}"
    75             redirect(action:list)
    76         }
    77         else {
    78             return [ taskInstance : taskInstance ]
    79         }
    80     }
    81 
    82     def editDetailed = {
    8339        def taskInstance = Task.get( params.id )
    8440
     
    9854    }
    9955
    100     @Secured(['ROLE_AppAdmin'])
    10156    def update = {
    10257        def taskInstance = Task.get( params.id )
     
    11772    }
    11873
    119     def updateDetailed = {
    120         def taskInstance = Task.get( params.id )
    121         if(taskInstance) {
    122             taskInstance.properties = params
    123             if(!taskInstance.hasErrors() && taskInstance.save()) {
    124                 flash.message = "Task ${params.id} updated"
    125                 redirect(action:show,id:taskInstance.id)
    126             }
    127             else {
    128                 render(view:'edit',model:[taskInstance:taskInstance])
    129             }
    130         }
    131         else {
    132             flash.message = "Task not found with id ${params.id}"
    133             redirect(action:edit,id:params.id)
    134         }
    135     }
    136 
    137     @Secured(['ROLE_AppAdmin'])
    13874    def create = {
    13975        def taskInstance = new Task()
     
    14278    }
    14379
    144     def createDetailed = {
    145         def taskInstance = new Task()
    146         taskInstance.properties = params
    147         return ['taskInstance':taskInstance]
    148     }
    149 
    150     @Secured(['ROLE_AppAdmin'])
    15180    def save = {
    15281        def taskInstance = new Task(params)
     
    15988        }
    16089    }
    161 
    162     def saveDetailed = {
    163         def taskInstance = new Task(params)
    164         if(!taskInstance.hasErrors() && taskInstance.save()) {
    165             flash.message = "Task ${taskInstance.id} created"
    166             redirect(action:showDetailed,id:taskInstance.id)
    167         }
    168         else {
    169             render(view:'createDetailed',model:[taskInstance:taskInstance])
    170         }
    171     }
    17290}
  • branches/TaskRewrite/src/grails-app/views/appCore/home.gsp

    r84 r85  
    88    <body>
    99        <div class="nav">
    10             <span class="menuButton"><g:link class="list" controller="task" action="listDetailed">Tasks</g:link></span>
     10            <span class="menuButton"><g:link class="list" controller="taskDetailed" action="list">Tasks</g:link></span>
    1111
    1212        </div>
  • branches/TaskRewrite/src/grails-app/views/taskDetailed/create.gsp

    r84 r85  
    1010        <div class="nav">
    1111            <span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span>
    12             <span class="menuButton"><g:link class="list" action="listDetailed">Task List</g:link></span>
     12            <span class="menuButton"><g:link class="list" action="list">Task List</g:link></span>
    1313        </div>
    1414        <div class="body">
     
    148148                </div>
    149149                <div class="buttons">
    150                     <span class="button"><input class="save" type="submit" value="CreateDetailed" /></span>
     150                    <span class="button"><input class="save" type="submit" value="Create" /></span>
    151151                </div>
    152152            </g:form>
  • branches/TaskRewrite/src/grails-app/views/taskDetailed/edit.gsp

    r84 r85  
    1010        <div class="nav">
    1111            <span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span>
    12             <span class="menuButton"><g:link class="list" action="listDetailed">Task List</g:link></span>
    13             <span class="menuButton"><g:link class="create" action="createDetailed">New Task</g:link></span>
     12            <span class="menuButton"><g:link class="list" action="list">Task List</g:link></span>
     13            <span class="menuButton"><g:link class="create" action="create">New Task</g:link></span>
    1414        </div>
    1515        <div class="body">
  • branches/TaskRewrite/src/grails-app/views/taskDetailed/list.gsp

    r84 r85  
    5656                            <td>${fieldValue(bean:taskInstance, field:'taskStatus')}</td>
    5757
    58                             <td><g:link action="editDetailed" id="${taskInstance.id}">Edit</g:link></td>
     58                            <td><g:link action="edit" id="${taskInstance.id}">Edit</g:link></td>
    5959
    60                             <td><g:link action="showDetailed" id="${taskInstance.id}">Show</g:link></td>
     60                            <td><g:link action="show" id="${taskInstance.id}">Show</g:link></td>
    6161                       
    6262                        </tr>
  • branches/TaskRewrite/src/grails-app/views/taskDetailed/show.gsp

    r84 r85  
    88        <div class="nav">
    99            <span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span>
    10             <span class="menuButton"><g:link class="listDetailed" action="listDetailed">Task List</g:link></span>
    11             <span class="menuButton"><g:link class="createDetailed" action="createDetailed">New Task</g:link></span>
     10            <span class="menuButton"><g:link class="list" action="list">Task List</g:link></span>
     11            <span class="menuButton"><g:link class="create" action="create">New Task</g:link></span>
    1212        </div>
    1313        <div class="body">
Note: See TracChangeset for help on using the changeset viewer.