Skip to content

Commit

Permalink
Fix/default strategy permission cherry pick (#8144)
Browse files Browse the repository at this point in the history
Cherry pick #8113, #8114 and #8112

---------

Co-authored-by: Thomas Heartman <[email protected]>
  • Loading branch information
FredrikOseberg and thomasheartman authored Sep 16, 2024
1 parent 446e123 commit ccc6344
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
12 changes: 10 additions & 2 deletions frontend/src/component/feature/StrategyTypes/StrategyVariants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFeatureVariantEdit[]>([]);
const theme = useTheme();
Expand Down Expand Up @@ -153,7 +161,7 @@ export const StrategyVariants: FC<{
<PermissionButton
onClick={addVariant}
variant='outlined'
permission={UPDATE_FEATURE_ENVIRONMENT_VARIANTS}
permission={permission}
projectId={projectId}
environmentId={environment}
data-testid='ADD_STRATEGY_VARIANT_BUTTON'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PageContent } from 'component/common/PageContent/PageContent';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import {
PROJECT_DEFAULT_STRATEGY_READ,
PROJECT_DEFAULT_STRATEGY_WRITE,
UPDATE_PROJECT,
} from 'component/providers/AccessProvider/permissions';
import { Alert, styled } from '@mui/material';
Expand All @@ -29,7 +30,14 @@ export const ProjectDefaultStrategySettings = () => {
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 (
<PageContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useStrategy } from 'hooks/api/getters/useStrategy/useStrategy';
import { useEffect, useState } from 'react';
import { formatUnknownError } from 'utils/formatUnknownError';
import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import { UPDATE_FEATURE_STRATEGY } from 'component/providers/AccessProvider/permissions';
import { PROJECT_DEFAULT_STRATEGY_WRITE } from 'component/providers/AccessProvider/permissions';
import type { IStrategy } from 'interfaces/strategy';
import { useRequiredQueryParam } from 'hooks/useRequiredQueryParam';
import type { ISegment } from 'interfaces/segment';
Expand All @@ -19,6 +19,7 @@ import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { ProjectDefaultStrategyForm } from './ProjectDefaultStrategyForm';
import type { CreateFeatureStrategySchema } from 'openapi';
import useProjectOverview from 'hooks/api/getters/useProjectOverview/useProjectOverview';
import { UPDATE_PROJECT } from '@server/types/permissions';

export const useDefaultStrategy = (
projectId: string,
Expand Down Expand Up @@ -154,7 +155,7 @@ const EditDefaultStrategy = () => {
environmentId={environmentId}
onSubmit={onSubmit}
loading={loading}
permission={UPDATE_FEATURE_STRATEGY}
permission={[PROJECT_DEFAULT_STRATEGY_WRITE, UPDATE_PROJECT]}
errors={errors}
isChangeRequest={false}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,6 +190,10 @@ export const ProjectDefaultStrategyForm = ({
setStrategy={setStrategy}
environment={environmentId}
projectId={projectId}
permission={[
PROJECT_DEFAULT_STRATEGY_WRITE,
UPDATE_PROJECT,
]}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,7 +62,10 @@ const ProjectEnvironmentDefaultStrategy = ({
actions={
<>
<PermissionIconButton
permission={UPDATE_FEATURE_STRATEGY}
permission={[
PROJECT_DEFAULT_STRATEGY_WRITE,
UPDATE_PROJECT,
]}
environmentId={environmentId}
projectId={projectId}
component={Link}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/features/project-environments/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type IUnleashServices,
serializeDates,
UPDATE_PROJECT,
PROJECT_DEFAULT_STRATEGY_WRITE,
} from '../../types';
import type { Logger } from '../../logger';
import type EnvironmentService from './environment-service';
Expand Down Expand Up @@ -105,7 +106,7 @@ export default class EnvironmentsController extends Controller {
method: 'post',
path: `${PREFIX}/:environment/default-strategy`,
handler: this.updateDefaultStrategyForProjectEnvironment,
permission: UPDATE_PROJECT,
permission: [UPDATE_PROJECT, PROJECT_DEFAULT_STRATEGY_WRITE],
middleware: [
openApiService.validPath({
tags: ['Projects'],
Expand Down

0 comments on commit ccc6344

Please sign in to comment.