mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
added contraints checking in change request permissions (#2690)
This commit is contained in:
parent
3549be0251
commit
a54d53a117
@ -35,8 +35,8 @@ const ProjectEnvironmentPermissionButton: React.FC<IProjectPermissionButtonProps
|
|||||||
React.forwardRef((props, ref) => {
|
React.forwardRef((props, ref) => {
|
||||||
const access = useHasProjectEnvironmentAccess(
|
const access = useHasProjectEnvironmentAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
||||||
@ -46,8 +46,8 @@ const RootPermissionButton: React.FC<IPermissionButtonProps> = React.forwardRef(
|
|||||||
(props, ref) => {
|
(props, ref) => {
|
||||||
const access = useHasRootAccess(
|
const access = useHasRootAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
||||||
|
@ -39,8 +39,8 @@ interface ILinkProps extends IPermissionIconButtonProps {
|
|||||||
const RootPermissionIconButton = (props: IButtonProps | ILinkProps) => {
|
const RootPermissionIconButton = (props: IButtonProps | ILinkProps) => {
|
||||||
const access = useHasRootAccess(
|
const access = useHasRootAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionIconButton {...props} access={access} />;
|
return <BasePermissionIconButton {...props} access={access} />;
|
||||||
@ -54,8 +54,8 @@ const ProjectEnvironmentPermissionIconButton = (
|
|||||||
) => {
|
) => {
|
||||||
const access = useHasProjectEnvironmentAccess(
|
const access = useHasProjectEnvironmentAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionIconButton {...props} access={access} />;
|
return <BasePermissionIconButton {...props} access={access} />;
|
||||||
|
@ -27,8 +27,8 @@ const ProjectenvironmentPermissionSwitch = React.forwardRef<
|
|||||||
>((props, ref) => {
|
>((props, ref) => {
|
||||||
const access = useHasProjectEnvironmentAccess(
|
const access = useHasProjectEnvironmentAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
||||||
@ -40,8 +40,8 @@ const RootPermissionSwitch = React.forwardRef<
|
|||||||
>((props, ref) => {
|
>((props, ref) => {
|
||||||
const access = useHasRootAccess(
|
const access = useHasRootAccess(
|
||||||
props.permission,
|
props.permission,
|
||||||
props.environmentId,
|
props.projectId,
|
||||||
props.projectId
|
props.environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { IConstraint, IFeatureStrategy } from 'interfaces/strategy';
|
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 { ConstraintAccordionList } from 'component/common/ConstraintAccordion/ConstraintAccordionList/ConstraintAccordionList';
|
||||||
import AccessContext from 'contexts/AccessContext';
|
|
||||||
import {
|
import {
|
||||||
UPDATE_FEATURE_STRATEGY,
|
UPDATE_FEATURE_STRATEGY,
|
||||||
CREATE_FEATURE_STRATEGY,
|
CREATE_FEATURE_STRATEGY,
|
||||||
} from 'component/providers/AccessProvider/permissions';
|
} from 'component/providers/AccessProvider/permissions';
|
||||||
|
import { useHasProjectEnvironmentAccess } from 'hooks/useHasAccess';
|
||||||
|
|
||||||
interface IFeatureStrategyConstraintsProps {
|
interface IFeatureStrategyConstraintsProps {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@ -22,8 +22,6 @@ export const FeatureStrategyConstraints = ({
|
|||||||
strategy,
|
strategy,
|
||||||
setStrategy,
|
setStrategy,
|
||||||
}: IFeatureStrategyConstraintsProps) => {
|
}: IFeatureStrategyConstraintsProps) => {
|
||||||
const { hasAccess } = useContext(AccessContext);
|
|
||||||
|
|
||||||
const constraints = useMemo(() => {
|
const constraints = useMemo(() => {
|
||||||
return strategy.constraints ?? [];
|
return strategy.constraints ?? [];
|
||||||
}, [strategy]);
|
}, [strategy]);
|
||||||
@ -35,13 +33,13 @@ export const FeatureStrategyConstraints = ({
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const showCreateButton = hasAccess(
|
const showCreateButton = useHasProjectEnvironmentAccess(
|
||||||
CREATE_FEATURE_STRATEGY,
|
CREATE_FEATURE_STRATEGY,
|
||||||
projectId,
|
projectId,
|
||||||
environmentId
|
environmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
const allowEditAndDelete = hasAccess(
|
const allowEditAndDelete = useHasProjectEnvironmentAccess(
|
||||||
UPDATE_FEATURE_STRATEGY,
|
UPDATE_FEATURE_STRATEGY,
|
||||||
projectId,
|
projectId,
|
||||||
environmentId
|
environmentId
|
||||||
|
@ -68,8 +68,8 @@ export const FeatureStrategyForm = ({
|
|||||||
const enableProdGuard = useFeatureStrategyProdGuard(feature, environmentId);
|
const enableProdGuard = useFeatureStrategyProdGuard(feature, environmentId);
|
||||||
const access = useHasProjectEnvironmentAccess(
|
const access = useHasProjectEnvironmentAccess(
|
||||||
permission,
|
permission,
|
||||||
environmentId,
|
projectId,
|
||||||
projectId
|
environmentId
|
||||||
);
|
);
|
||||||
const { strategyDefinition } = useStrategy(strategy?.name);
|
const { strategyDefinition } = useStrategy(strategy?.name);
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ const intersect = (array1: string[], array2: string[]) => {
|
|||||||
|
|
||||||
export const useHasProjectEnvironmentAccess = (
|
export const useHasProjectEnvironmentAccess = (
|
||||||
permission: string | string[],
|
permission: string | string[],
|
||||||
environmentId: string,
|
projectId: string,
|
||||||
projectId: string
|
environmentId: string
|
||||||
) => {
|
) => {
|
||||||
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
|
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
|
||||||
const checkAccess = useCheckProjectPermissions(projectId);
|
const checkAccess = useCheckProjectPermissions(projectId);
|
||||||
@ -89,8 +89,8 @@ export const useHasProjectEnvironmentAccess = (
|
|||||||
|
|
||||||
export const useHasRootAccess = (
|
export const useHasRootAccess = (
|
||||||
permissions: string | string[],
|
permissions: string | string[],
|
||||||
environmentId?: string,
|
projectId?: string,
|
||||||
projectId?: string
|
environmentId?: string
|
||||||
) => {
|
) => {
|
||||||
return useCheckProjectPermissions(projectId)(permissions, environmentId);
|
return useCheckProjectPermissions(projectId)(permissions, environmentId);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user