All files / lib/packages/shared-utils/package-actions rules.ts

100% Statements 42/42
99.06% Branches 106/107
100% Functions 14/14
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163                    273x     1498x                 273x     1498x           273x     1498x           273x     1509x 331x                       1178x                         273x     1500x                 273x     1499x                             273x     1496x                       273x   1491x     273x     1498x 951x     547x 1x     546x 1x     545x 98x     447x 140x 1x     139x     307x                                
import {
  Action,
  ActionRule,
  Authority,
  finalDispositionStatuses,
  SEATOOL_STATUS,
} from "shared-types";
 
import { isCmsWriteUser, isStateUser } from "../user-helper";
 
export const arRespondToRai: ActionRule = {
  action: Action.RESPOND_TO_RAI,
  check: (checker, user) =>
    !checker.isTempExtension &&
    checker.hasStatus(SEATOOL_STATUS.PENDING_RAI) &&
    checker.hasLatestRai &&
    // safety; prevent bad status from causing overwrite
    (!checker.hasRaiResponse || checker.hasRaiWithdrawal) &&
    isStateUser(user) &&
    !checker.isLocked,
};
 
export const arTempExtension: ActionRule = {
  action: Action.TEMP_EXTENSION,
  check: (checker, user) =>
    checker.hasStatus(SEATOOL_STATUS.APPROVED) &&
    checker.isWaiver &&
    checker.isInitialOrRenewal &&
    isStateUser(user),
};
 
export const arAmend: ActionRule = {
  action: Action.AMEND_WAIVER,
  check: (checker, user) =>
    checker.hasStatus(SEATOOL_STATUS.APPROVED) &&
    checker.isWaiver &&
    checker.isInitialOrRenewal &&
    isStateUser(user),
};
 
export const arEnableWithdrawRaiResponse: ActionRule = {
  action: Action.ENABLE_RAI_WITHDRAW,
  check: (checker, user) => {
    if (checker.authorityIs([Authority["CHIP_SPA"]])) {
      return (
        !checker.isTempExtension &&
        checker.isNotWithdrawn &&
        checker.hasRaiResponse &&
        !checker.hasEnabledRaiWithdraw &&
        isCmsWriteUser(user) &&
        !checker.hasStatus(finalDispositionStatuses) &&
        !checker.hasStatus([SEATOOL_STATUS.PENDING_CONCURRENCE, SEATOOL_STATUS.PENDING_APPROVAL]) &&
        !checker.isPlaceholderStatus
      );
    }
 
    return (
      !checker.isTempExtension &&
      checker.isNotWithdrawn &&
      checker.hasCompletedRai &&
      !checker.hasEnabledRaiWithdraw &&
      checker.isInSecondClock &&
      isCmsWriteUser(user) &&
      !checker.hasStatus(finalDispositionStatuses) &&
      !checker.hasStatus([SEATOOL_STATUS.PENDING_CONCURRENCE, SEATOOL_STATUS.PENDING_APPROVAL])
    );
  },
};
 
export const arDisableWithdrawRaiResponse: ActionRule = {
  action: Action.DISABLE_RAI_WITHDRAW,
  check: (checker, user) =>
    !checker.isTempExtension &&
    checker.isNotWithdrawn &&
    checker.hasRaiResponse &&
    checker.hasEnabledRaiWithdraw &&
    isCmsWriteUser(user) &&
    !checker.hasStatus(finalDispositionStatuses) &&
    !checker.hasStatus([SEATOOL_STATUS.PENDING_CONCURRENCE, SEATOOL_STATUS.PENDING_APPROVAL]),
};
 
export const arWithdrawRaiResponse: ActionRule = {
  action: Action.WITHDRAW_RAI,
  check: (checker, user) => {
    return (
      !checker.isTempExtension &&
      checker.isInActivePendingStatus &&
      checker.hasCompletedRai &&
      // safety; prevent bad status from causing overwrite,
      // update: needed to allow subsequent RAI responses
      // !checker.hasRaiWithdrawal &&
      !checker.hasStatus([SEATOOL_STATUS.PENDING_CONCURRENCE, SEATOOL_STATUS.PENDING_APPROVAL]) &&
      checker.hasEnabledRaiWithdraw &&
      isStateUser(user) &&
      !checker.isLocked
    );
  },
};
 
export const arWithdrawPackage: ActionRule = {
  action: Action.WITHDRAW_PACKAGE,
  check: (checker, user) =>
    !checker.isTempExtension &&
    !checker.hasStatus(finalDispositionStatuses) &&
    isStateUser(user) &&
    !checker.isPlaceholderStatus,
};
 
// const arUpdateId: ActionRule = {
//   action: Action.UPDATE_ID,
//   check: (checker, user) =>
//     isCmsSuperUser(user) && !checker.hasStatus(finalDispositionStatuses) && false,
// };
 
const arRemoveAppkChild: ActionRule = {
  action: Action.REMOVE_APPK_CHILD,
  check: (checker, user) => isStateUser(user) && !!checker.isAppkChild && false,
};
 
export const arUploadSubsequentDocuments: ActionRule = {
  action: Action.UPLOAD_SUBSEQUENT_DOCUMENTS,
  check: (checker, user) => {
    if (isStateUser(user) === false) {
      return false;
    }
 
    if (checker.needsIntake) {
      return false;
    }
 
    if (checker.isTempExtension) {
      return false;
    }
 
    if (checker.hasStatus([SEATOOL_STATUS.PENDING_RAI])) {
      return false;
    }
 
    if (checker.hasStatus([SEATOOL_STATUS.PENDING])) {
      if (checker.hasRequestedRai) {
        return false;
      }
 
      return true;
    }
 
    return false;
  },
};
 
export default [
  arRespondToRai,
  arEnableWithdrawRaiResponse,
  arDisableWithdrawRaiResponse,
  arWithdrawRaiResponse,
  arWithdrawPackage,
  arTempExtension,
  arAmend,
  // arUpdateId,
  arRemoveAppkChild,
  arUploadSubsequentDocuments,
];