/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.osedu.org/licenses/ECL-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kra.award.document.authorizer;

import org.kuali.kra.award.document.authorization.AwardTask;
import org.kuali.kra.award.home.Award;
import org.kuali.kra.infrastructure.AwardPermissionConstants;

/**
 * The Modify Award Authorizer checks to see if the user has 
 * permission to modify a award. Authorization depends upon whether
 * the award is being created or modified.  For creation, the
 * user needs the CREATE_AWARD permission.  If the award is being
 * modified, the user only needs to have the MODIFY_AWARD permission 
 * for that award.
 */
public class ModifyAwardAuthorizer extends AwardAuthorizer {

    /**
     * @see org.kuali.kra.irb.document.authorizer.AwardAuthorizer#isAuthorized(java.lang.String, org.kuali.kra.irb.document.authorization.AwardTask)
     */
    public boolean isAuthorized(String username, AwardTask task) {
        
        Award award = task.getAward();
        return award.isNew() ? canUserCreateAward(username, award) : canUserModifyAward(username, award);
    }
    
    /**
     * 
     * We have to consider the case when we are saving the award for the first time.
     * 
     * @param username
     * @param award
     * @return
     */
    protected boolean canUserCreateAward(String username, Award award){
        return hasUnitPermission(username, AwardPermissionConstants.CREATE_AWARD.getAwardPermission());
    }
    
    /**
     * 
     * After the initial save, the award can only be modified has the required permission.
     * 
     * @param username
     * @param award
     * @return
     */
    protected boolean canUserModifyAward(String username, Award award){
        return !award.getAwardDocument().isViewOnly() &&
               hasPermission(username, award, AwardPermissionConstants.MODIFY_AWARD.getAwardPermission());
    }
}

@@ -661,16 +661,67 @@
 rizer;%0A%0A
+import org.kuali.kra.award.document.AwardDocument;%0A
 import o
@@ -1529,24 +1529,88 @@
  %7B%0A        %0A
+        AwardDocument doc = task.getAward().getAwardDocument();%0A
         Awar
@@ -1739,16 +1739,21 @@
 e, award
+, doc
 );%0A    %7D
@@ -2362,32 +2362,51 @@
 ame, Award award
+, AwardDocument doc
 )%7B%0A        retur
@@ -2449,16 +2449,20 @@
 ly() &&%0A
+    
         
@@ -2550,26 +2550,90 @@
 ardPermission())
+ &&%0A                       !kraWorkflowService.isInWorkflow(doc)
 ;%0A    %7D%0A%7D%0A

Save button still showing up when Award is in Final state. ModifyAwardAuthorizer needed changed to test if document is in workflow.