All files / libs/kernel/auth/shared/src/abilities/company-share-prices definitions.ts

68.67% Statements 57/83
53.33% Branches 8/15
80% Functions 8/10
68.67% Lines 57/83

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 841x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 135x 135x 135x       1x 1x 1x 45x 45x 45x     1x 1x 1x           1x 1x 1x           1x 1x 1x 28x 28x 28x     1x 1x 1x 50x 50x 50x     1x 1x 1x 43x 43x 43x     1x 1x 1x 64x 64x 64x     1x 1x 1x 1x 1x 1x       1x  
import { type AuthenticatedContext } from '@amalia/kernel/auth/types';
 
import { SubjectsEnum, type DefinePermissions, type UserRoleForAccessControl } from '../../types';
 
import { CompanySharePricesActions } from './actions';
 
const isLtiFFEnabled = (authenticatedContext: AuthenticatedContext) =>
  !!authenticatedContext.user.company.featureFlags.LTI;
 
export const companySharePricesAbilityDefinitions = {
  ADMIN(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
    can(CompanySharePricesActions.edit, SubjectsEnum.CompanySharePrice);
  },
 
  READ_ONLY_ADMIN(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  SCOPED_ADMIN(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  SCOPED_READ_ONLY_ADMIN(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  FINANCE(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  MANAGER(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  READ_ONLY_MANAGER(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  EMPLOYEE(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
 
  READ_ONLY_EMPLOYEE(authenticatedContext, { can }) {
    if (!isLtiFFEnabled(authenticatedContext)) {
      return;
    }

    can(CompanySharePricesActions.view, SubjectsEnum.CompanySharePrice);
  },
} as const satisfies Partial<Record<UserRoleForAccessControl, DefinePermissions>>;