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

Replace userAuthGroup with userRole in vehicles - Part 2 #1541

Merged
merged 8 commits into from
Aug 19, 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
4 changes: 2 additions & 2 deletions frontend/src/common/authentication/OnRouteBCContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type IDIRUserDetailContext = {
lastName: string;
userName: string;
email: string;
userAuthGroup: IDIRUserAuthGroupType;
userRole: IDIRUserAuthGroupType;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand All @@ -32,7 +32,7 @@ export interface BCeIDUserDetailContext {
phone2Extension?: string;
email: string;
fax?: string;
userAuthGroup: BCeIDUserAuthGroupType;
userRole: BCeIDUserAuthGroupType;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/common/authentication/PermissionMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export const usePermissionMatrix = ({
}: PermissionConfigType & PermissionMatrixKeysType): boolean => {
const { userDetails, idirUserDetails } = useContext(OnRouteBCContext);
const { data: featureFlags } = useFeatureFlagsQuery();
const isIdir = Boolean(idirUserDetails?.userAuthGroup);
const isIdir = Boolean(idirUserDetails?.userRole);

// If featureFlag is given, exit if it is not enabled.
if (featureFlag) {
Expand All @@ -504,14 +504,13 @@ export const usePermissionMatrix = ({
}
)[permissionMatrixFunctionKey];
if (isIdir) {
currentUserAuthGroup = idirUserDetails?.userAuthGroup;
currentUserAuthGroup = idirUserDetails?.userRole;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
isAllowed = Boolean(
currentUserAuthGroup &&
allowedIDIRAuthGroups?.includes(currentUserAuthGroup),

);
} else {
currentUserAuthGroup = userDetails?.userAuthGroup;
currentUserAuthGroup = userDetails?.userRole;
isAllowed = Boolean(
currentUserAuthGroup &&
allowedBCeIDAuthGroups?.includes(currentUserAuthGroup),
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const IDIRAuthWall = ({

if (isAuthenticated) {
if (isIDIR(userIDP)) {
if (!idirUserDetails?.userAuthGroup) {
if (!idirUserDetails?.userRole) {
return (
<>
<LoadIDIRUserContext />
Expand All @@ -84,7 +84,7 @@ export const IDIRAuthWall = ({
}

const doesUserHaveAccess = DoesUserHaveAuthGroup<IDIRUserAuthGroupType>({
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
userAuthGroup: idirUserDetails?.userAuthGroup,
userAuthGroup: idirUserDetails?.userRole,
allowedAuthGroups,
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const NewBCeIDAuthWall = () => {
if (
!companyId &&
isNewBCeIDUser === undefined &&
!userDetails?.userAuthGroup
!userDetails?.userRole
) {
return (
<>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/common/authentication/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type BCeIDUserContextType = {
pendingCompanies: CompanyMetadata[];
migratedClient: VerifiedClient;
user?: {
userAuthGroup?: string;
userRole?: string;
statusCode?: string;
userGUID?: string;
userName?: string;
Expand Down Expand Up @@ -174,7 +174,7 @@ export type UserAuthGroupType =
*/
export type IDIRUserContextType = {
user?: {
userAuthGroup?: IDIRUserAuthGroupType;
userRole?: IDIRUserAuthGroupType;
statusCode?: string;
userGUID?: string;
userName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const NavIconSideBar = (props: NavIconSideBarProps) => {
const { idirUserDetails } = useContext(OnRouteBCContext);
const isIdir = user?.profile?.identity_provider === IDPS.IDIR;
const isEofficer =
idirUserDetails?.userAuthGroup === USER_AUTH_GROUP.ENFORCEMENT_OFFICER;
idirUserDetails?.userRole === USER_AUTH_GROUP.ENFORCEMENT_OFFICER;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved

const shouldShowSideBar =
isAuthenticated && isIdir && idirUserDetails?.userName && !isEofficer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export const PaymentAndRefundDetail = () => {
const { idirUserDetails } = useContext(OnRouteBCContext);
const { user: idirUserFromAuthContext } = useAuth();
const canSelectPermitIssuers =
idirUserDetails?.userAuthGroup ===
IDIR_USER_AUTH_GROUP.SYSTEM_ADMINISTRATOR ||
idirUserDetails?.userAuthGroup === IDIR_USER_AUTH_GROUP.HQ_ADMINISTRATOR ||
idirUserDetails?.userAuthGroup === IDIR_USER_AUTH_GROUP.FINANCE;
idirUserDetails?.userRole === IDIR_USER_AUTH_GROUP.SYSTEM_ADMINISTRATOR ||
idirUserDetails?.userRole === IDIR_USER_AUTH_GROUP.HQ_ADMINISTRATOR ||
idirUserDetails?.userRole === IDIR_USER_AUTH_GROUP.FINANCE;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
// GET the permit types.
const permitTypesQuery = usePermitTypesQuery();
const { setSnackBar } = useContext(SnackBarContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export const IDIRPermitSearchResults = memo(
* @param initialData The initial data to filter by the active data toggle.
* @returns List of permit items containing the data to be displayed in table.
*/
const getFilteredData = (initialData: PermitListItem[]): PermitListItem[] => {
const getFilteredData = (
initialData: PermitListItem[],
): PermitListItem[] => {
if (!initialData.length) return [];
if (isActiveRecordsOnly) {
// Returns unexpired permits
Expand Down Expand Up @@ -164,27 +166,30 @@ export const IDIRPermitSearchResults = memo(
</Box>
);
},
renderRowActions: useCallback(({ row }: { row: MRT_Row<PermitListItem> }) => {
const isInactive =
hasPermitExpired(row.original.expiryDate) ||
isPermitInactive(row.original.permitStatus);
renderRowActions: useCallback(
({ row }: { row: MRT_Row<PermitListItem> }) => {
const isInactive =
hasPermitExpired(row.original.expiryDate) ||
isPermitInactive(row.original.permitStatus);

if (shouldShowRowActions(idirUserDetails?.userAuthGroup)) {
return (
<Box className="idir-search-results__row-actions">
<IDIRPermitSearchRowActions
isPermitInactive={isInactive}
permitNumber={row.original.permitNumber}
permitId={row.original.permitId}
userAuthGroup={idirUserDetails?.userAuthGroup}
companyId={row.original.companyId?.toString()}
/>
</Box>
);
} else {
return <></>;
}
}, []),
if (shouldShowRowActions(idirUserDetails?.userRole)) {
return (
<Box className="idir-search-results__row-actions">
<IDIRPermitSearchRowActions
isPermitInactive={isInactive}
permitNumber={row.original.permitNumber}
permitId={row.original.permitId}
userAuthGroup={idirUserDetails?.userRole}
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
companyId={row.original.companyId?.toString()}
/>
</Box>
);
} else {
return <></>;
}
},
[],
),
muiToolbarAlertBannerProps: isError
? {
color: "error",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/manageProfile/apiManager/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const useUserContext = (
lastName: user.lastName,
userName: user.userName,
email: user.email,
userAuthGroup: user.userAuthGroup,
userRole: user.userRole,
} as IDIRUserDetailContext;

setIDIRUserDetails?.(() => userDetails);
Expand Down Expand Up @@ -160,7 +160,7 @@ export const useUserContext = (
phone2Extension: user.phone2Extension,
email: user.email,
fax: user.fax,
userAuthGroup: user.userAuthGroup as BCeIDUserAuthGroupType,
userRole: user.userRole as BCeIDUserAuthGroupType,
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
} as BCeIDUserDetailContext;

setUserDetails?.(() => userDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ export const ManageProfilesDashboard = React.memo(() => {
useGetCreditAccountMetadataQuery(companyId);
const { data: featureFlags } = useFeatureFlagsQuery();
const populatedUserRoles = getDefaultRequiredVal([], userRoles);
const isStaffActingAsCompany = Boolean(idirUserDetails?.userAuthGroup);
const isStaffActingAsCompany = Boolean(idirUserDetails?.userRole);
const isBCeIDAdmin = isBCeIDOrgAdmin(populatedUserRoles);
const shouldAllowUserManagement = isBCeIDAdmin || isStaffActingAsCompany;
const showSpecialAuth =
!isStaffActingAsCompany &&
canViewSpecialAuthorizations(userRoles, userDetails?.userAuthGroup) &&
canViewSpecialAuthorizations(userRoles, userDetails?.userRole) &&
featureFlags?.["LOA"] === "ENABLED";

const isCreditAccountHolder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const MyInfoForm = memo(
countryCode: getDefaultRequiredVal("", myInfo?.countryCode),
provinceCode: getDefaultRequiredVal("", myInfo?.provinceCode),
city: getDefaultRequiredVal("", myInfo?.city),
userAuthGroup: getDefaultRequiredVal(
userRole: getDefaultRequiredVal(
BCeID_USER_AUTH_GROUP.PERMIT_APPLICANT,
myInfo?.userAuthGroup as BCeIDUserAuthGroupType,
myInfo?.userRole as BCeIDUserAuthGroupType,
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export const EditUserForm = memo(
countryCode: getDefaultRequiredVal("", userInfo?.countryCode),
provinceCode: getDefaultRequiredVal("", userInfo?.provinceCode),
city: getDefaultRequiredVal("", userInfo?.city),
userAuthGroup: getDefaultRequiredVal(
userRole: getDefaultRequiredVal(
BCeID_USER_AUTH_GROUP.COMPANY_ADMINISTRATOR,
userInfo?.userAuthGroup,
userInfo?.userRole,
),
},
});
Expand Down Expand Up @@ -163,7 +163,7 @@ export const EditUserForm = memo(
</Stack>
<Stack spacing={2}>
<Controller
name="userAuthGroup"
name="userRole"
rules={{
required: { value: true, message: requiredMessage() },
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const UserAuthRadioGroup = ({
field,
fieldState,
}: {
field: ControllerRenderProps<FieldValues, "userAuthGroup">;
field: ControllerRenderProps<FieldValues, "userRole">;
fieldState: ControllerFieldState;
}) => {
const { invalid } = fieldState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AddUserDashboard = React.memo(() => {

const formMethods = useForm<BCeIDAddUserRequest>({
defaultValues: {
userAuthGroup: BCeID_USER_AUTH_GROUP.PERMIT_APPLICANT,
userRole: BCeID_USER_AUTH_GROUP.PERMIT_APPLICANT,
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
},
reValidateMode: "onBlur",
});
Expand Down Expand Up @@ -185,7 +185,7 @@ export const AddUserDashboard = React.memo(() => {
</Stack>
<Stack spacing={2}>
<Controller
name="userAuthGroup"
name="userRole"
rules={{
required: { value: true, message: requiredMessage() },
}}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/manageProfile/pages/MyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const MyInfo = memo(() => {
return (
<div className="my-info-page">
{isEditing ? <Header /> : null}
<UserInfoBanner userAuthGroup={myInfo?.userAuthGroup} />
<UserInfoBanner userAuthGroup={myInfo?.userRole} />
{isEditing ? (
<MyInfoForm myInfo={myInfo} setIsEditing={setIsEditing} />
) : (
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/manageProfile/types/manageProfile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type BCeIDUserStatusType =
*/
export type BCeIDAddUserRequest = {
userName: string;
userAuthGroup: BCeIDAuthGroup;
userRole: BCeIDAuthGroup;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ export type UpdateCompanyProfileRequest = Omit<
* The response structure of get user info API.
*/
export type ReadUserInformationResponse = Contact & {
userAuthGroup: BCeIDUserAuthGroupType;
userRole: BCeIDUserAuthGroupType;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
userGUID: string;
userName: string;
statusCode: BCeID_USER_STATUS;
Expand All @@ -100,7 +100,7 @@ export type ReadUserInformationResponse = Contact & {
* The edit user info request body.
*/
export type UserInfoRequest = Contact & {
userAuthGroup: BCeIDUserAuthGroupType;
userRole: BCeIDUserAuthGroupType;
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getDefaultUserDetails = () => ({
phone2Extension: "234",
email: "[email protected]",
fax: "604-123-4569",
userAuthGroup: USER_AUTH_GROUP.COMPANY_ADMINISTRATOR,
userRole: USER_AUTH_GROUP.COMPANY_ADMINISTRATOR,
krishnan-aot marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand All @@ -28,6 +28,6 @@ export const getEmptyUserDetails = () => ({
phone2Extension: "",
email: "",
fax: "",
userAuthGroup: USER_AUTH_GROUP.PERMIT_APPLICANT,
userRole: USER_AUTH_GROUP.PERMIT_APPLICANT,
},
});
Loading
Loading