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

100% Statements 45/45
97.32% Branches 109/112
100% Functions 15/15
100% Lines 34/34

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                    215x     1034x                 215x     1034x           215x     1034x           215x     1045x 223x                       822x                         215x     1036x                 215x     1035x                     215x     1032x           215x     1027x     215x   1027x     215x     1034x 516x     518x 1x     517x 15x     502x 82x     420x 168x 1x     167x     252x                                
import {
  Action,
  ActionRule,
  Authority,
  finalDispositionStatuses,
  SEATOOL_STATUS,
} from "shared-types";
 
import { isCmsSuperUser, 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.hasRaiResponse &&
      !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) =>
    !checker.isTempExtension &&
    checker.isInActivePendingStatus &&
    checker.hasRaiResponse &&
    // safety; prevent bad status from causing overwrite
    !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,
];