コード例 #1
0
  public boolean isAuthorized(String userId, BudgetTask task) {
    BudgetDocument budgetDocument = task.getBudgetDocument();
    ProposalDevelopmentDocument doc =
        (ProposalDevelopmentDocument) budgetDocument.getParentDocument();

    return !doc.isViewOnly()
        && hasParentPermission(userId, doc, PermissionConstants.MAINTAIN_PROPOSAL_HIERARCHY);
  }
 /**
  * This method checks if the user has full (pre-workflow/pre-submission) proposal access
  * maintenance rights
  *
  * @param user the user requesting access
  * @param document the document object
  * @return true if the user has full (pre-workflow/pre-submission) proposal access maintenance
  *     rights
  */
 protected boolean hasFullAuthorization(Document document, Person user) {
   final ProposalDevelopmentDocument pdDocument = ((ProposalDevelopmentDocument) document);
   return !pdDocument.isViewOnly()
       && getKcAuthorizationService()
           .hasPermission(
               user.getPrincipalId(), pdDocument, PermissionConstants.MAINTAIN_PROPOSAL_ACCESS)
       && !getKcWorkflowService().isInWorkflow(pdDocument)
       && !pdDocument.getDevelopmentProposal().getSubmitFlag();
 }
  protected boolean isAuthorizedToAddBudget(Document document, Person user) {
    final ProposalDevelopmentDocument pdDocument = ((ProposalDevelopmentDocument) document);

    boolean rejectedDocument =
        getKcDocumentRejectionService()
            .isDocumentOnInitialNode(pdDocument.getDocumentHeader().getWorkflowDocument());

    return (!getKcWorkflowService().isInWorkflow(pdDocument) || rejectedDocument)
        && !pdDocument.isViewOnly()
        && !pdDocument.getDevelopmentProposal().getSubmitFlag()
        && !pdDocument.getDevelopmentProposal().isParent();
  }
  protected boolean isAuthorizedToModify(Document document, Person user) {
    DocumentRequestAuthorizationCache documentRequestAuthorizationCache =
        getDocumentRequestAuthorizationCache(document);

    final String resultCacheKey = buildPermissionCacheKey(document, user, IS_AUTHORIZED_TO_MODIFY);
    if (documentRequestAuthorizationCache.hasPermissionResult(resultCacheKey)) {
      return documentRequestAuthorizationCache.getPermissionResult(resultCacheKey);
    }

    final ProposalDevelopmentDocument pdDocument = ((ProposalDevelopmentDocument) document);
    final DevelopmentProposal proposal = pdDocument.getDevelopmentProposal();

    if (!isEditableState(proposal.getProposalStateTypeCode())) {
      return false;
    }

    final String proposalNbr = proposal.getProposalNumber();

    boolean hasPermission;
    if (proposalNbr == null) {
      hasPermission = hasPermissionByOwnedByUnit(document, user);
    } else {
      /*
       * After the initial save, the proposal can only be modified if it is not in workflow
       * and the user has the require permission.
       */

      final boolean hasBeenRejected =
          ProposalState.REVISIONS_REQUESTED.equals(proposal.getProposalStateTypeCode());

      hasPermission =
          !pdDocument.isViewOnly()
              && getKcAuthorizationService()
                  .hasPermission(
                      user.getPrincipalId(), pdDocument, PermissionConstants.MODIFY_PROPOSAL)
              && (!getKcWorkflowService().isInWorkflow(document) || hasBeenRejected)
              && !proposal.getSubmitFlag();
    }

    if (proposal.isChild() && hasPermission) {
      final Document parent = proposal.getParent().getDocument();
      final String parentResultCacheKey =
          buildPermissionCacheKey(parent, user, IS_AUTHORIZED_TO_MODIFY);
      documentRequestAuthorizationCache.getPermissionResultCache().remove(parentResultCacheKey);
      hasPermission = isAuthorizedToModify(parent, user);
    }

    documentRequestAuthorizationCache.addPermissionResult(resultCacheKey, hasPermission);

    return hasPermission;
  }
  protected boolean isAuthorizedToAddNarrative(Document document, Person user) {
    final ProposalDevelopmentDocument pdDocument = ((ProposalDevelopmentDocument) document);

    boolean rejectedDocument =
        getKcDocumentRejectionService()
            .isDocumentOnInitialNode(pdDocument.getDocumentHeader().getWorkflowDocument());
    boolean hasPermission = false;
    if ((!getKcWorkflowService().isInWorkflow(pdDocument) || rejectedDocument)
        && !pdDocument.isViewOnly()
        && !pdDocument.getDevelopmentProposal().getSubmitFlag()) {
      hasPermission = getModifyNarrativePermission(pdDocument, user);
    }
    return hasPermission;
  }