Changeset 873 for trunk


Ignore:
Timestamp:
Mar 16, 2011, 9:50:39 AM (14 years ago)
Author:
gav
Message:

Refactor logic into TaskService.checkCreateEntry().
Prevent entry creation on recurring tasks altogether.
Prevent entry creation other than PM Entries on tasks with a procedure.

Location:
trunk/grails-app
Files:
3 edited

Legend:

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

    r865 r873  
    113113        def taskInstance = Task.read(params.taskId)
    114114
    115         if(!taskInstance) {
    116             params.errorMessage = g.message(code:"default.not.found", args:['Task',params.taskId])
    117             render(contentType:"text/json", status: 403, template: "/shared/messages")
    118             return
    119         }
    120 
    121         // Check for Complete task.
    122         if(taskInstance.taskStatus.id == 3) {
    123             params.errorMessage = g.message(code:"task.operationNotPermittedOnCompleteTask")
    124             render(contentType:"text/json", status: 403, template: "/shared/messages")
    125             return
    126         }
    127 
    128         // Success.
    129115        def entryInstance = new Entry()
    130116        entryInstance.task = taskInstance
    131117        entryInstance.entryType = EntryType.read(params.entryTypeId)
     118
     119        // Check if we should create this entry.
     120        def checkResult = taskService.checkCreateEntry(entryInstance)
     121        if(checkResult.error) {
     122            params.errorMessage = g.message(code: checkResult.error.code)
     123            render(contentType:"text/json", status: 403, template: "/shared/messages")
     124            return
     125        }
     126
     127        // Success.
    132128        def model = ['entryInstance': entryInstance]
    133129
  • trunk/grails-app/i18n/messages.properties

    r860 r873  
    156156task.operationNotPermittedOnCompleteTask=This operation is not permitted on a complete task.
    157157task.operationNotPermittedOnTaskInTrash=This operation is not permitted on a task that is in the trash.
     158task.operationNotPermittedOnRecurringTask=This operation is not permitted \
     159    on a recurring task, please see the Sub Tasks.
    158160task.operationNotPermittedOnRecurringTaskWithoutAuth=This operation is not permitted \
    159161    on a recurring task without authorisation.
     
    164166task.operationNotPermittedOnParentPmTask=This operation is not permitted \
    165167    on a Parent PM task.
     168task.createEntryNotPermittedOnTaskWithProcedure=This operation is not permitted \
     169    on a task with a procedure, please create entries on the procedure tab.
    166170task.failedToSave=Could not complete operation, task failed to save.
    167171task.modifications.failedToSave=Could not complete operation, as task modification record failed to save.
  • trunk/grails-app/services/TaskService.groovy

    r851 r873  
    338338            }
    339339
    340             if(!taskInstance)
    341                 return fail(field:"task", code:"task.notFound")
    342 
    343             if(taskInstance.taskStatus.id == 3)
    344                 return fail(field:"task", code:"task.operationNotPermittedOnCompleteTask")
    345 
    346             // Check for authorisation on recurring tasks.
    347             if(taskInstance.taskRecurringSchedule) {
    348                 if(!authenticateService.ifAnyGranted('ROLE_AppAdmin,ROLE_Manager,ROLE_TaskManager'))
    349                     return fail(field:"task", code:"task.operationNotPermittedOnRecurringTaskWithoutAuth")
    350             }
     340            // Check if we should create this entry.
     341            def checkResult = checkCreateEntry(result.entryInstance)
     342            if(checkResult.error)
     343                return fail(field:"task", code: checkResult.error.code)
    351344
    352345            if(result.entryInstance.hasErrors() || !result.entryInstance.save())
     
    10651058    } // end saveImmediateCallout()
    10661059
     1060    /**
     1061    * Check if we should create an entry.
     1062    * @param entryInstance The entry to check.
     1063    * @returns A map containing result.error (if any error) and result.taskInstance.
     1064    */
     1065    def checkCreateEntry(entryInstance) {
     1066        def result = [:]
     1067
     1068        def fail = { Map m ->
     1069            result.error = [ code: m.code, args: [] ]
     1070            return result
     1071        }
     1072
     1073        def taskInstance = entryInstance.task
     1074        if(!taskInstance)
     1075            return fail(code:"task.notFound")
     1076
     1077        // Check for tashed task.
     1078        if(taskInstance.trash)
     1079            return fail(code:"task.operationNotPermittedOnTaskInTrash")
     1080
     1081        // Check for Complete task.
     1082        if(taskInstance.taskStatus.id == 3)
     1083            return fail(code: "task.operationNotPermittedOnCompleteTask")
     1084
     1085        // Check for recurring schedule.
     1086        if(taskInstance.taskRecurringSchedule)
     1087            return fail(code:"task.operationNotPermittedOnRecurringTask")
     1088
     1089        // Check for procedure and ensure we are creating a PM Entry.
     1090        if(taskInstance.taskProcedureRevision && (entryInstance.entryType.id != 6) )
     1091            return fail(code:"task.createEntryNotPermittedOnTaskWithProcedure")
     1092
     1093        // Success.
     1094        return result
     1095
     1096    } // checkCreateEntry()
     1097
    10671098} // end TaskService
Note: See TracChangeset for help on using the changeset viewer.