Ignore:
Timestamp:
Nov 10, 2009, 9:56:28 PM (14 years ago)
Author:
gav
Message:

Small refactor to use personService where appropriate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/EntryDetailedController.groovy

    r178 r185  
    33class EntryDetailedController extends BaseController {
    44
    5     def authenticateService
     5    def personService
    66
    77    def index = { redirect(action:list,params:params) }
     
    2828        def entryInstance = Entry.get( params.id )
    2929        if(entryInstance) {
    30             if(entryInstance.enteredBy.loginName == authenticateService.userDomain().loginName) {
    31                 entryInstance.delete()
     30            if(entryInstance.enteredBy.loginName == personService.currentUser().loginName) {
     31                def taskID = entryInstance.task.id
     32                entryInstance.delete(flush:true)
    3233                flash.message = "Entry ${params.id} deleted"
    33                 redirect(action:list)
     34                redirect(controller: 'taskDetailed', action: 'show', id: taskID)
    3435            }
    3536            else {
     
    5354        else {
    5455
    55             if(entryInstance.enteredBy.loginName == authenticateService.userDomain().loginName) {
     56            if(entryInstance.enteredBy.loginName == personService.currentUser().loginName) {
    5657                return [ entryInstance : entryInstance ]
    5758            }
     
    6768        def entryInstance = Entry.get( params.id )
    6869        if(entryInstance) {
    69             entryInstance.properties = params
    70             if(!entryInstance.hasErrors() && entryInstance.save(flush: true)) {
    71                 flash.message = "Entry ${params.id} updated"
    72                 redirect(action:show,id:entryInstance.id)
     70            // The update method only accepts post requests, so this is just in case.
     71            if(entryInstance.enteredBy.loginName == personService.currentUser().loginName) {
     72                entryInstance.properties = params
     73                if(!entryInstance.hasErrors() && entryInstance.save(flush: true)) {
     74                    flash.message = "Entry ${params.id} updated"
     75                    redirect(action:show,id:entryInstance.id)
     76                }
     77                else {
     78                    render(view:'edit',model:[entryInstance:entryInstance])
     79                }
    7380            }
    7481            else {
    75                 render(view:'edit',model:[entryInstance:entryInstance])
     82                flash.message = "You may only edit your own entries."
     83                redirect(action:show,id:entryInstance.id)
    7684            }
    7785        }
     
    98106        def entryInstance = new Entry(params)
    99107
    100         entryInstance.enteredBy = Person.get(authenticateService.userDomain().id)
     108        entryInstance.enteredBy = personService.currentUser()
    101109        if(!entryInstance.hasErrors() && entryInstance.save(flush: true)) {
    102110            flash.message = "Entry ${entryInstance.id} created"
Note: See TracChangeset for help on using the changeset viewer.