/**
   * @see
   *     org.kuali.kra.protocol.document.authorizer.CommitteeAuthorizerBase#isAuthorized(java.lang.String,
   *     org.kuali.kra.protocol.document.authorization.CommitteeTaskBase)
   */
  public boolean isAuthorized(String userId, CommitteeTaskBase task) {
    boolean hasPermission = true;
    CommitteeBase committee = task.getCommittee();
    if (committee.getId() == null) {

      // We have to consider the case when we are saving the committee for the first time.

      hasPermission =
          hasUnitPermission(
              userId, getModuleNamespaceCodeHook(), getPermissionNameForAddCommiteeHook());
    } else {
      /*
       * After the initial save, the committee can only be modified has the required permission.
       */
      hasPermission =
          !committee.getCommitteeDocument().isViewOnly()
              && !isPessimisticLocked(committee.getCommitteeDocument())
              && hasPermission(userId, committee, getPermissionNameForModifyCommitteeHook());
    }

    // Verify that document is not locked
    if (isPessimisticLocked(committee.getCommitteeDocument())) {
      hasPermission = false;
    }

    return hasPermission;
  }