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

Fix/default strategy permission cherry pick #8144

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
Loading