001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.kra.budget.document;
017:
018: import java.util.Map;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.kuali.core.authorization.AuthorizationConstants;
023: import org.kuali.core.bo.user.UniversalUser;
024: import org.kuali.core.document.Document;
025: import org.kuali.core.document.authorization.DocumentActionFlags;
026: import org.kuali.core.workflow.service.KualiWorkflowDocument;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.kfs.service.ParameterService;
029: import org.kuali.kfs.service.impl.ParameterConstants;
030: import org.kuali.module.kra.KraConstants;
031: import org.kuali.module.kra.document.ResearchDocumentAuthorizer;
032: import org.kuali.module.kra.service.ResearchDocumentPermissionsService;
033: import org.kuali.workflow.KualiWorkflowUtils;
034:
035: /**
036: * DocumentAuthorizer class for KRA Budget Documents.
037: */
038: public class BudgetDocumentAuthorizer extends
039: ResearchDocumentAuthorizer {
040: private static Log LOG = LogFactory
041: .getLog(BudgetDocumentAuthorizer.class);
042:
043: /**
044: * @see org.kuali.core.authorization.DocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
045: * org.kuali.core.bo.user.KualiUser)
046: */
047: public Map getEditMode(Document d, UniversalUser u) {
048:
049: ParameterService parameterService = SpringContext
050: .getBean(ParameterService.class);
051: ResearchDocumentPermissionsService permissionsService = SpringContext
052: .getBean(ResearchDocumentPermissionsService.class);
053: BudgetDocument budgetDocument = (BudgetDocument) d;
054: String permissionCode = AuthorizationConstants.EditMode.UNVIEWABLE;
055: KualiWorkflowDocument workflowDocument = budgetDocument
056: .getDocumentHeader().getWorkflowDocument();
057:
058: // Check initiator
059: if (workflowDocument.getInitiatorNetworkId().equalsIgnoreCase(
060: u.getPersonUserIdentifier())) {
061: permissionCode = getPermissionCodeByPrecedence(
062: permissionCode,
063: AuthorizationConstants.EditMode.FULL_ENTRY);
064: return finalizeEditMode(budgetDocument, permissionCode);
065: }
066:
067: // Check project director
068: if (u.getPersonUniversalIdentifier().equals(
069: budgetDocument.getBudget()
070: .getBudgetProjectDirectorUniversalIdentifier())) {
071: permissionCode = getPermissionCodeByPrecedence(
072: permissionCode,
073: parameterService
074: .getParameterValue(
075: BudgetDocument.class,
076: KraConstants.PROJECT_DIRECTOR_BUDGET_PERMISSION));
077: }
078:
079: // Check default org permissions - project director
080: if (!budgetDocument.getBudget().getPersonnel().isEmpty()) {
081: if (permissionsService.isUserInOrgHierarchy(budgetDocument
082: .buildProjectDirectorReportXml(true),
083: KualiWorkflowUtils.KRA_BUDGET_DOC_TYPE, u
084: .getPersonUniversalIdentifier())) {
085: permissionCode = getPermissionCodeByPrecedence(
086: permissionCode,
087: parameterService
088: .getParameterValue(
089: BudgetDocument.class,
090: KraConstants.PROJECT_DIRECTOR_ORG_BUDGET_PERMISSION));
091: }
092: }
093:
094: // Check default org permissions - cost sharing orgs
095: if (permissionsService.isUserInOrgHierarchy(budgetDocument
096: .buildCostShareOrgReportXml(true),
097: KualiWorkflowUtils.KRA_BUDGET_DOC_TYPE, u
098: .getPersonUniversalIdentifier())) {
099: permissionCode = getPermissionCodeByPrecedence(
100: permissionCode,
101: parameterService
102: .getParameterValue(
103: ParameterConstants.RESEARCH_ADMINISTRATION_DOCUMENT.class,
104: KraConstants.COST_SHARE_ORGS_BUDGET_PERMISSION));
105: }
106:
107: permissionCode = getPermissionCodeByPrecedence(permissionCode,
108: getAdHocEditMode(budgetDocument, u));
109:
110: return finalizeEditMode(budgetDocument, permissionCode);
111: }
112:
113: /**
114: * Overrides most of the inherited flags so that the buttons behave exactly like they used to in the obsoleted
115: * budgetDocumentControls.tag
116: *
117: * @see org.kuali.core.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
118: * org.kuali.core.bo.user.KualiUser)
119: */
120: public DocumentActionFlags getDocumentActionFlags(
121: Document document, UniversalUser user) {
122: LOG
123: .debug("calling BudgetDocumentAuthorizer.getDocumentActionFlags");
124:
125: DocumentActionFlags flags = super .getDocumentActionFlags(
126: document, user);
127:
128: flags.setCanAcknowledge(false);
129: flags.setCanApprove(false);
130: flags.setCanBlanketApprove(false);
131: flags.setCanCancel(false);
132: flags.setCanDisapprove(false);
133: flags.setCanFYI(false);
134: flags.setCanClose(false);
135: flags.setCanSave(true);
136: flags.setCanAnnotate(true);
137:
138: BudgetDocument budgetDocument = (BudgetDocument) document;
139:
140: // use inherited canRoute, canAnnotate, and canReload values
141:
142: return flags;
143: }
144: }
|