All files / libs/kernel/auth/shared/src/abilities/payments definitions.ts

100% Statements 35/35
100% Branches 5/5
50% Functions 5/10
100% Lines 35/35

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 361x 1x 1x 1x 1x 1x 1x 1x 135x 135x 135x 1x 1x 1x 45x 1x 1x 1x 28x 1x 1x 1x 50x 50x 50x 50x 1x 1x 1x 43x 43x 43x 43x 43x 1x  
import { SubsetAccessEnum } from '../../subsets/enums';
import { SubjectsEnum, type DefinePermissions, type UserRoleForAccessControl } from '../../types';
 
import { PaymentsActions } from './actions';
import { type ViewPaymentSubject } from './subjects';
 
export const paymentsAbilityDefinitions = {
  ADMIN(_, { can }) {
    can(PaymentsActions.delete, SubjectsEnum.Payment);
    can(PaymentsActions.overwrite, SubjectsEnum.Payment);
    can(PaymentsActions.view, SubjectsEnum.Payment, { predicate: () => true, subset: SubsetAccessEnum.EVERYTHING });
  },
 
  READ_ONLY_ADMIN(_, { can }) {
    can(PaymentsActions.view, SubjectsEnum.Payment, { predicate: () => true, subset: SubsetAccessEnum.EVERYTHING });
  },
 
  FINANCE(_, { can }) {
    can(PaymentsActions.view, SubjectsEnum.Payment, { predicate: () => true, subset: SubsetAccessEnum.EVERYTHING });
  },
 
  MANAGER({ hierarchy }, { can }) {
    can(PaymentsActions.view, SubjectsEnum.Payment, {
      subset: SubsetAccessEnum.MATCH_MANAGEES,
      predicate: ({ userId }: ViewPaymentSubject) => hierarchy.isManagerOf(userId, new Date()),
    });
  },
 
  READ_ONLY_MANAGER({ hierarchy }, { can }) {
    can(PaymentsActions.view, SubjectsEnum.Payment, {
      subset: SubsetAccessEnum.MATCH_MANAGEES,
      predicate: ({ userId }: ViewPaymentSubject) => hierarchy.isManagerOf(userId, new Date()),
    });
  },
} as const satisfies Partial<Record<UserRoleForAccessControl, DefinePermissions>>;