Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORV2-3069 Special Authorization Feature flag split #1677

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,52 @@ VALUES
GETUTCDATE()
);

INSERT INTO
[dbo].[ORBC_FEATURE_FLAG] (
[FEATURE_ID],
[FEATURE_KEY],
[FEATURE_VALUE],
[CONCURRENCY_CONTROL_NUMBER],
[DB_CREATE_USERID],
[DB_CREATE_TIMESTAMP],
[DB_LAST_UPDATE_USERID],
[DB_LAST_UPDATE_TIMESTAMP]
)
VALUES
(
'10',
'LCV',
'ENABLED',
NULL,
N'dbo',
GETUTCDATE(),
N'dbo',
GETUTCDATE()
);

INSERT INTO
[dbo].[ORBC_FEATURE_FLAG] (
[FEATURE_ID],
[FEATURE_KEY],
[FEATURE_VALUE],
[CONCURRENCY_CONTROL_NUMBER],
[DB_CREATE_USERID],
[DB_CREATE_TIMESTAMP],
[DB_LAST_UPDATE_USERID],
[DB_LAST_UPDATE_TIMESTAMP]
)
VALUES
(
'11',
'NO-FEE',
'ENABLED',
NULL,
N'dbo',
GETUTCDATE(),
N'dbo',
GETUTCDATE()
);

SET
IDENTITY_INSERT [dbo].[ORBC_FEATURE_FLAG] OFF
GO
8 changes: 4 additions & 4 deletions frontend/src/common/authentication/PermissionMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ const MANAGE_SETTINGS = {
* Special Authorizations Tab
*/
VIEW_SPECIAL_AUTHORIZATIONS: { allowedIDIRRoles: ALL_IDIR_ROLES },
ADD_NO_FEE_FLAG: { allowedIDIRRoles: [SA, FIN, HQA] },
UPDATE_NO_FEE_FLAG: { allowedIDIRRoles: [SA, FIN, HQA] },
ADD_LCV_FLAG: { allowedIDIRRoles: [HQA] },
REMOVE_LCV_FLAG: { allowedIDIRRoles: [HQA] },
ADD_NO_FEE_FLAG: { allowedIDIRRoles: [SA, HQA] },
UPDATE_NO_FEE_FLAG: { allowedIDIRRoles: [SA, HQA] },
ADD_LCV_FLAG: { allowedIDIRRoles: [SA, HQA] },
REMOVE_LCV_FLAG: { allowedIDIRRoles: [SA, HQA] },
ADD_AN_LOA: { allowedIDIRRoles: [SA, HQA] },
EDIT_AN_LOA: { allowedIDIRRoles: [SA, HQA] },
VIEW_LOA: { allowedIDIRRoles: ALL_IDIR_ROLES },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { SETTINGS_TABS, SettingsTab } from "../../types/tabs";
import OnRouteBCContext from "../../../../common/authentication/OnRouteBCContext";
import { ERROR_ROUTES } from "../../../../routes/constants";
import { SpecialAuthorizations } from "../../pages/SpecialAuthorizations/SpecialAuthorizations";
import { useFeatureFlagsQuery } from "../../../../common/hooks/hooks";
import {
canViewSpecialAuthorizations,
canViewSuspend,
} from "../../helpers/permissions";
import { canViewSuspend } from "../../helpers/permissions";
import { CreditAccountMetadataComponent } from "../../pages/CreditAccountMetadataComponent";
import { usePermissionMatrix } from "../../../../common/authentication/PermissionMatrix";
import { useGetCreditAccountMetadataQuery } from "../../hooks/creditAccount";
Expand All @@ -20,8 +16,6 @@ import { CREDIT_ACCOUNT_USER_TYPE } from "../../types/creditAccount";
export const ManageSettingsDashboard = React.memo(() => {
const { userClaims, companyId, idirUserDetails } =
useContext(OnRouteBCContext);

const { data: featureFlags } = useFeatureFlagsQuery();
const { data: creditAccountMetadata, isPending } =
useGetCreditAccountMetadataQuery(companyId as number);

Expand All @@ -41,15 +35,17 @@ export const ManageSettingsDashboard = React.memo(() => {
}
};

const isStaffActingAsCompany = Boolean(idirUserDetails?.userRole);
const isFinanceUser = idirUserDetails?.userRole === IDIR_USER_ROLE.FINANCE;

const [hideSuspendTab, setHideSuspendTab] = useState<boolean>(false);
const showSuspendTab = canViewSuspend(userClaims) && !hideSuspendTab;
const showSpecialAuth =
isStaffActingAsCompany &&
canViewSpecialAuthorizations(userClaims, idirUserDetails?.userRole) &&
featureFlags?.["LOA"] === "ENABLED";

const showSpecialAuth = usePermissionMatrix({
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "VIEW_SPECIAL_AUTHORIZATIONS",
},
});

const showCreditAccountTab = usePermissionMatrix({
featureFlag: "CREDIT-ACCOUNT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const QUERY_KEYS = {
*/
export const useFetchSpecialAuthorizations = (
companyId: number | string,
enabled: boolean = true,
) => {
return useQuery({
queryKey: QUERY_KEYS.SPECIAL_AUTH(companyId),
Expand All @@ -22,7 +23,7 @@ export const useFetchSpecialAuthorizations = (
retry: false,
refetchOnMount: "always",
refetchOnWindowFocus: false,
enabled: Boolean(companyId),
enabled,
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState } from "react";
import { useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { Button } from "@mui/material";
Expand All @@ -11,80 +11,94 @@ import { ExpiredLOAModal } from "../../components/SpecialAuthorizations/LOA/expi
import { DeleteConfirmationDialog } from "../../../../common/components/dialog/DeleteConfirmationDialog";
import { LOASteps } from "./LOA/LOASteps";
import { useFetchLOAs, useRemoveLOAMutation } from "../../hooks/LOA";
import { getDefaultNullableVal, getDefaultRequiredVal } from "../../../../common/helpers/util";
import { DEFAULT_NO_FEE_PERMIT_TYPE, NoFeePermitType } from "../../types/SpecialAuthorization";
import { getDefaultRequiredVal } from "../../../../common/helpers/util";
import {
DEFAULT_NO_FEE_PERMIT_TYPE,
NoFeePermitType,
} from "../../types/SpecialAuthorization";
import { NoFeePermitsSection } from "../../components/SpecialAuthorizations/NoFeePermits/NoFeePermitsSection";
import OnRouteBCContext from "../../../../common/authentication/OnRouteBCContext";
import { LCVSection } from "../../components/SpecialAuthorizations/LCV/LCVSection";
import { downloadLOA } from "../../apiManager/loa";
import {
useFetchSpecialAuthorizations,
useUpdateLCV,
useUpdateNoFee,
} from "../../hooks/specialAuthorizations";
import { usePermissionMatrix } from "../../../../common/authentication/PermissionMatrix";
import { useFeatureFlagsQuery } from "../../../../common/hooks/hooks";

import {
canUpdateLCVFlag,
canUpdateLOA,
canUpdateNoFeePermitsFlag,
canViewLCVFlag,
canViewLOA,
canViewNoFeePermitsFlag,
} from "../../helpers/permissions";

export const SpecialAuthorizations = ({
companyId,
}: {
companyId: number;
}) => {
const {
data: specialAuthorizations,
refetch: refetchSpecialAuth,
} = useFetchSpecialAuthorizations(companyId);

const noFeeType = getDefaultRequiredVal(null, specialAuthorizations?.noFeeType);
const isLcvAllowed = getDefaultRequiredVal(false, specialAuthorizations?.isLcvAllowed);
export const SpecialAuthorizations = ({ companyId }: { companyId: number }) => {
const { data: featureFlags } = useFeatureFlagsQuery();
const { data: specialAuthorizations, refetch: refetchSpecialAuth } =
useFetchSpecialAuthorizations(
companyId,
// At least one of the special auth feature flags must be enabled
// to decide whether to enable the query.
featureFlags?.["NO-FEE"] === "ENABLED" ||
featureFlags?.["LCV"] === "ENABLED",
);

const noFeeType = getDefaultRequiredVal(
null,
specialAuthorizations?.noFeeType,
);
const isLcvAllowed = getDefaultRequiredVal(
false,
specialAuthorizations?.isLcvAllowed,
);

const [showExpiredLOAs, setShowExpiredLOAs] = useState<boolean>(false);
const [loaToDelete, setLoaToDelete] = useState<RequiredOrNull<number>>(null);
const [showLOASteps, setShowLOASteps] = useState<boolean>(false);
const [loaToEdit, setLoaToEdit] = useState<RequiredOrNull<number>>(null);

const {
userClaims,
idirUserDetails,
userDetails,
} = useContext(OnRouteBCContext);

const canEditNoFeePermits = canUpdateNoFeePermitsFlag(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);

const canViewNoFeePermits = canViewNoFeePermitsFlag(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);

const canUpdateLCV = canUpdateLCVFlag(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);

const canViewLCV = canViewLCVFlag(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);

const canWriteLOA = canUpdateLOA(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);

const canReadLOA = canViewLOA(
userClaims,
getDefaultNullableVal(idirUserDetails?.userRole, userDetails?.userRole),
);
const canEditNoFeePermits = usePermissionMatrix({
featureFlag: "NO-FEE",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "UPDATE_NO_FEE_FLAG",
},
});

const canViewNoFeePermits = usePermissionMatrix({
featureFlag: "NO-FEE",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "VIEW_SPECIAL_AUTHORIZATIONS",
},
});

const canUpdateLCV = usePermissionMatrix({
featureFlag: "LCV",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "REMOVE_LCV_FLAG",
},
});

const canViewLCV = usePermissionMatrix({
featureFlag: "LCV",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "VIEW_SPECIAL_AUTHORIZATIONS",
},
});

const canReadLOA = usePermissionMatrix({
featureFlag: "LOA",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "VIEW_LOA",
},
});

const canWriteLOA = usePermissionMatrix({
featureFlag: "LOA",
permissionMatrixKeys: {
permissionMatrixFeatureKey: "MANAGE_SETTINGS",
permissionMatrixFunctionKey: "EDIT_AN_LOA",
},
});

const updateNoFeeMutation = useUpdateNoFee();
const updateLCVMutation = useUpdateLCV();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {

@ApiBearerAuth()
@ApiTags('Special Authorization')
@IsFeatureFlagEnabled('LOA')
@Controller('companies/:companyId/special-auths')
@ApiMethodNotAllowedResponse({
description: 'The Special Authorizaion Api Method Not Allowed Response',
Expand Down Expand Up @@ -79,6 +78,7 @@ export class SpecialAuthController {
],
})
@Put('/lcv')
@IsFeatureFlagEnabled('LCV')
async updateLcv(
@Req() request: Request,
@Param() { companyId }: CompanyIdPathParamDto,
Expand Down Expand Up @@ -107,6 +107,7 @@ export class SpecialAuthController {
IDIRUserRole.SYSTEM_ADMINISTRATOR,
],
})
@IsFeatureFlagEnabled('NO-FEE')
@Put('/no-fee')
async updateNoFee(
@Req() request: Request,
Expand Down
Loading