From ccc63446c3262db7ef42ef9a3e21eb5fcf79d8e1 Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Mon, 16 Sep 2024 11:13:18 +0200 Subject: [PATCH] Fix/default strategy permission cherry pick (#8144) Cherry pick #8113, #8114 and #8112 --------- Co-authored-by: Thomas Heartman --- .../feature/StrategyTypes/StrategyVariants.tsx | 12 ++++++++++-- .../ProjectDefaultStrategySettings.tsx | 10 +++++++++- .../EditDefaultStrategy.tsx | 5 +++-- .../ProjectDefaultStrategyForm.tsx | 10 +++++++++- .../ProjectEnvironmentDefaultStrategy.tsx | 10 ++++++++-- .../features/project-environments/environments.ts | 3 ++- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx b/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx index da2a70c75fc8..33cd56e7dfad 100644 --- a/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx +++ b/frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx @@ -27,7 +27,15 @@ export const StrategyVariants: FC<{ projectId: string; environment: string; editable?: boolean; -}> = ({ strategy, setStrategy, projectId, environment, editable }) => { + permission?: string | string[]; +}> = ({ + strategy, + setStrategy, + projectId, + environment, + editable, + permission = UPDATE_FEATURE_ENVIRONMENT_VARIANTS, +}) => { const { trackEvent } = usePlausibleTracker(); const [variantsEdit, setVariantsEdit] = useState([]); const theme = useTheme(); @@ -153,7 +161,7 @@ export const StrategyVariants: FC<{ { usePageTitle(`Project default strategy configuration – ${projectName}`); if ( - !hasAccess([UPDATE_PROJECT, PROJECT_DEFAULT_STRATEGY_READ], projectId) + !hasAccess( + [ + UPDATE_PROJECT, + PROJECT_DEFAULT_STRATEGY_READ, + PROJECT_DEFAULT_STRATEGY_WRITE, + ], + projectId, + ) ) { return ( { environmentId={environmentId} onSubmit={onSubmit} loading={loading} - permission={UPDATE_FEATURE_STRATEGY} + permission={[PROJECT_DEFAULT_STRATEGY_WRITE, UPDATE_PROJECT]} errors={errors} isChangeRequest={false} /> diff --git a/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectDefaultStrategyForm.tsx b/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectDefaultStrategyForm.tsx index dda1c80342b8..7ad83f8dd3d3 100644 --- a/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectDefaultStrategyForm.tsx +++ b/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectDefaultStrategyForm.tsx @@ -21,11 +21,15 @@ import { FeatureStrategyConstraints } from 'component/feature/FeatureStrategy/Fe import { FeatureStrategyType } from 'component/feature/FeatureStrategy/FeatureStrategyType/FeatureStrategyType'; import { FeatureStrategyTitle } from 'component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyTitle/FeatureStrategyTitle'; import { StrategyVariants } from 'component/feature/StrategyTypes/StrategyVariants'; +import { + PROJECT_DEFAULT_STRATEGY_WRITE, + UPDATE_PROJECT, +} from '@server/types/permissions'; interface IProjectDefaultStrategyFormProps { projectId: string; environmentId: string; - permission: string; + permission: string | string[]; onSubmit: () => void; onCancel?: () => void; loading: boolean; @@ -186,6 +190,10 @@ export const ProjectDefaultStrategyForm = ({ setStrategy={setStrategy} environment={environmentId} projectId={projectId} + permission={[ + PROJECT_DEFAULT_STRATEGY_WRITE, + UPDATE_PROJECT, + ]} /> } /> diff --git a/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectEnvironmentDefaultStrategy.tsx b/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectEnvironmentDefaultStrategy.tsx index e7786bf2b5f0..a340a3742dff 100644 --- a/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectEnvironmentDefaultStrategy.tsx +++ b/frontend/src/component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/ProjectEnvironmentDefaultStrategy.tsx @@ -1,13 +1,16 @@ import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; import { StrategyItemContainer } from 'component/common/StrategyItemContainer/StrategyItemContainer'; import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton'; -import { UPDATE_FEATURE_STRATEGY } from 'component/providers/AccessProvider/permissions'; import { Link } from 'react-router-dom'; import Edit from '@mui/icons-material/Edit'; import { StrategyExecution } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/EnvironmentAccordionBody/StrategyDraggableItem/StrategyItem/StrategyExecution/StrategyExecution'; import type { ProjectEnvironmentType } from 'interfaces/environments'; import { useMemo } from 'react'; import type { CreateFeatureStrategySchema } from 'openapi'; +import { + PROJECT_DEFAULT_STRATEGY_WRITE, + UPDATE_PROJECT, +} from '@server/types/permissions'; interface ProjectEnvironmentDefaultStrategyProps { environment: ProjectEnvironmentType; @@ -59,7 +62,10 @@ const ProjectEnvironmentDefaultStrategy = ({ actions={ <>