From a54d53a117e35816ee1075b0daa25757f7f1cd21 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 14 Dec 2022 13:00:51 +0100 Subject: [PATCH] added contraints checking in change request permissions (#2690) --- .../common/PermissionButton/PermissionButton.tsx | 8 ++++---- .../PermissionIconButton/PermissionIconButton.tsx | 8 ++++---- .../common/PermissionSwitch/PermissionSwitch.tsx | 8 ++++---- .../FeatureStrategyConstraints.tsx | 10 ++++------ .../FeatureStrategyForm/FeatureStrategyForm.tsx | 4 ++-- frontend/src/hooks/useHasAccess.ts | 8 ++++---- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/frontend/src/component/common/PermissionButton/PermissionButton.tsx b/frontend/src/component/common/PermissionButton/PermissionButton.tsx index 1a2a2454aa..e94e5cfedd 100644 --- a/frontend/src/component/common/PermissionButton/PermissionButton.tsx +++ b/frontend/src/component/common/PermissionButton/PermissionButton.tsx @@ -35,8 +35,8 @@ const ProjectEnvironmentPermissionButton: React.FC { const access = useHasProjectEnvironmentAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; @@ -46,8 +46,8 @@ const RootPermissionButton: React.FC = React.forwardRef( (props, ref) => { const access = useHasRootAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; diff --git a/frontend/src/component/common/PermissionIconButton/PermissionIconButton.tsx b/frontend/src/component/common/PermissionIconButton/PermissionIconButton.tsx index fc1b4dd882..2ab1fb443b 100644 --- a/frontend/src/component/common/PermissionIconButton/PermissionIconButton.tsx +++ b/frontend/src/component/common/PermissionIconButton/PermissionIconButton.tsx @@ -39,8 +39,8 @@ interface ILinkProps extends IPermissionIconButtonProps { const RootPermissionIconButton = (props: IButtonProps | ILinkProps) => { const access = useHasRootAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; @@ -54,8 +54,8 @@ const ProjectEnvironmentPermissionIconButton = ( ) => { const access = useHasProjectEnvironmentAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; diff --git a/frontend/src/component/common/PermissionSwitch/PermissionSwitch.tsx b/frontend/src/component/common/PermissionSwitch/PermissionSwitch.tsx index 4829fa15ce..beb2b86bb7 100644 --- a/frontend/src/component/common/PermissionSwitch/PermissionSwitch.tsx +++ b/frontend/src/component/common/PermissionSwitch/PermissionSwitch.tsx @@ -27,8 +27,8 @@ const ProjectenvironmentPermissionSwitch = React.forwardRef< >((props, ref) => { const access = useHasProjectEnvironmentAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; @@ -40,8 +40,8 @@ const RootPermissionSwitch = React.forwardRef< >((props, ref) => { const access = useHasRootAccess( props.permission, - props.environmentId, - props.projectId + props.projectId, + props.environmentId ); return ; diff --git a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/FeatureStrategyConstraints.tsx b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/FeatureStrategyConstraints.tsx index 9a34120aa0..6fb29cef1a 100644 --- a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/FeatureStrategyConstraints.tsx +++ b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/FeatureStrategyConstraints.tsx @@ -1,11 +1,11 @@ import { IConstraint, IFeatureStrategy } from 'interfaces/strategy'; -import React, { useMemo, useContext } from 'react'; +import React, { useMemo } from 'react'; import { ConstraintAccordionList } from 'component/common/ConstraintAccordion/ConstraintAccordionList/ConstraintAccordionList'; -import AccessContext from 'contexts/AccessContext'; import { UPDATE_FEATURE_STRATEGY, CREATE_FEATURE_STRATEGY, } from 'component/providers/AccessProvider/permissions'; +import { useHasProjectEnvironmentAccess } from 'hooks/useHasAccess'; interface IFeatureStrategyConstraintsProps { projectId: string; @@ -22,8 +22,6 @@ export const FeatureStrategyConstraints = ({ strategy, setStrategy, }: IFeatureStrategyConstraintsProps) => { - const { hasAccess } = useContext(AccessContext); - const constraints = useMemo(() => { return strategy.constraints ?? []; }, [strategy]); @@ -35,13 +33,13 @@ export const FeatureStrategyConstraints = ({ })); }; - const showCreateButton = hasAccess( + const showCreateButton = useHasProjectEnvironmentAccess( CREATE_FEATURE_STRATEGY, projectId, environmentId ); - const allowEditAndDelete = hasAccess( + const allowEditAndDelete = useHasProjectEnvironmentAccess( UPDATE_FEATURE_STRATEGY, projectId, environmentId diff --git a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx index 293e156839..42a22ffd1d 100644 --- a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx +++ b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx @@ -68,8 +68,8 @@ export const FeatureStrategyForm = ({ const enableProdGuard = useFeatureStrategyProdGuard(feature, environmentId); const access = useHasProjectEnvironmentAccess( permission, - environmentId, - projectId + projectId, + environmentId ); const { strategyDefinition } = useStrategy(strategy?.name); diff --git a/frontend/src/hooks/useHasAccess.ts b/frontend/src/hooks/useHasAccess.ts index d7c56b5f6e..6999d7dde1 100644 --- a/frontend/src/hooks/useHasAccess.ts +++ b/frontend/src/hooks/useHasAccess.ts @@ -69,8 +69,8 @@ const intersect = (array1: string[], array2: string[]) => { export const useHasProjectEnvironmentAccess = ( permission: string | string[], - environmentId: string, - projectId: string + projectId: string, + environmentId: string ) => { const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId); const checkAccess = useCheckProjectPermissions(projectId); @@ -89,8 +89,8 @@ export const useHasProjectEnvironmentAccess = ( export const useHasRootAccess = ( permissions: string | string[], - environmentId?: string, - projectId?: string + projectId?: string, + environmentId?: string ) => { return useCheckProjectPermissions(projectId)(permissions, environmentId); };