Changeset 185


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

Small refactor to use personService where appropriate.

Location:
trunk/grails-app
Files:
4 edited

Legend:

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

    r178 r185  
    33class AppCoreController extends BaseController {
    44
    5     def authenticateService
     5    def personService
    66    def createDataService
    77
     
    1717    */
    1818    def welcome = {
    19         def personInstance = Person.get(authenticateService.userDomain().id)
     19        def personInstance = personService.currentUser()
    2020        flash.message = "Welcome, ${personInstance.firstName} ${personInstance.lastName}."
    2121
     
    3030    def changeSessionTimeout = {
    3131        if (request.method == 'GET') {
    32             def personInstance = Person.get(authenticateService.userDomain().id)
     32            def personInstance = personService.currentUser()
    3333            return [ personInstance : personInstance ]       
    3434        }
    3535        if (request.method == 'POST') {
    36             def personInstance = Person.get(authenticateService.userDomain().id)
     36            def personInstance = personService.currentUser()
    3737                personInstance.properties = params
    3838                if (!personInstance.hasErrors() && personInstance.save(flush: true)) {
     
    5353
    5454        if (request.method == 'GET') {
    55             def personInstance = Person.get(authenticateService.userDomain().id)
     55            def personInstance = personService.currentUser()
    5656            return [ personInstance : personInstance ]       
    5757        }
    5858
    5959        if (request.method == 'POST') {
    60             def personInstance = Person.get(authenticateService.userDomain().id)
     60            def personInstance = personService.currentUser()
    6161
    6262            if(params.confirmPass == params.pass) {
  • 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"
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r181 r185  
    44class TaskDetailedController extends BaseController {
    55
    6     def authenticateService
     6    def personService
    77    def dateUtilService
    88    def taskService
     
    2929        {
    3030            def taskInstanceList = []
    31             def personInstance = Person.get(authenticateService.userDomain().id)
     31            def personInstance = personService.currentUser()
    3232
    3333            if(params.quickSearch == "searchMyTodays") {
     
    3939                taskInstanceList = taskSearchService.getInTheLastWeek(params)
    4040                if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." }
    41                 else { params.message = "No tasks found for today." }
     41                else { params.message = "No tasks found for the last week." }
    4242            }
    4343            else if(params.quickSearch == "searchMyInTheLastWeek") {
    4444                taskInstanceList = taskSearchService.getMyInTheLastWeek(params)
    4545                if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." }
    46                 else { params.message = "No tasks found for today." }
     46                else { params.message = "No tasks found for the last week." }
    4747            }
    4848            else {
     
    7070        {
    7171            def taskInstanceList = []
    72             def personInstance = Person.get(authenticateService.userDomain().id)
     72            def personInstance = personService.currentUser()
    7373
    7474            if(params.quickSearch == "searchMyTodays") {
     
    8181                taskInstanceList = taskSearchService.getInTheLastWeek(params)
    8282                if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." }
    83                 else { params.message = "No tasks found for today." }
     83                else { params.message = "No tasks found for the last week." }
    8484                if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" }
    8585            }
     
    8787                taskInstanceList = taskSearchService.getMyInTheLastWeek(params)
    8888                if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." }
    89                 else { params.message = "No tasks found for today." }
     89                else { params.message = "No tasks found for the last week." }
    9090                if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" }
    9191            }
     
    117117        {
    118118            def taskInstanceList = []
    119             def personInstance = Person.get(authenticateService.userDomain().id)
     119            def personInstance = personService.currentUser()
    120120
    121121            if(params.quickSearch == "budgetUnplanned") {
     
    456456        def taskInstance = new Task()
    457457        // Default leadPerson to current user.
    458         taskInstance.leadPerson = Person.get(authenticateService.userDomain().id)
     458        taskInstance.leadPerson = personService.currentUser()
    459459        taskInstance.properties = params
    460460        return ['taskInstance':taskInstance]
  • trunk/grails-app/services/CreateDataService.groovy

    r182 r185  
    754754                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
    755755                                                                                    inventoryLocation: InventoryLocation.get(1),
    756                                                                                     name: "J-Rope",
    757                                                                                     description: "Twine wound J-Rope",
     756                                                                                    name: "Hemp rope",
     757                                                                                    description: "Natural hemp rope.",
    758758                                                                                    unitsInStock: 2,
    759759                                                                                    reorderPoint: 0)
     
    765765                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
    766766                                                                                    inventoryLocation: InventoryLocation.get(1),
    767                                                                                     name: "L-Rope",
    768                                                                                     description: "Twine wound L-Rope",
     767                                                                                    name: "Cotton Rope 12mm",
     768                                                                                    description: "A soft natural rope made from cotton.",
    769769                                                                                    alternateItems: InventoryItem.get(1),
    770770                                                                                    unitsInStock: 2,
Note: See TracChangeset for help on using the changeset viewer.