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) => {
|
||||
const access = useHasProjectEnvironmentAccess(
|
||||
props.permission,
|
||||
props.environmentId,
|
||||
props.projectId
|
||||
props.projectId,
|
||||
props.environmentId
|
||||
);
|
||||
|
||||
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
||||
@ -46,8 +46,8 @@ const RootPermissionButton: React.FC<IPermissionButtonProps> = React.forwardRef(
|
||||
(props, ref) => {
|
||||
const access = useHasRootAccess(
|
||||
props.permission,
|
||||
props.environmentId,
|
||||
props.projectId
|
||||
props.projectId,
|
||||
props.environmentId
|
||||
);
|
||||
|
||||
return <BasePermissionButton {...props} access={access} ref={ref} />;
|
||||
|
@ -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 <BasePermissionIconButton {...props} access={access} />;
|
||||
@ -54,8 +54,8 @@ const ProjectEnvironmentPermissionIconButton = (
|
||||
) => {
|
||||
const access = useHasProjectEnvironmentAccess(
|
||||
props.permission,
|
||||
props.environmentId,
|
||||
props.projectId
|
||||
props.projectId,
|
||||
props.environmentId
|
||||
);
|
||||
|
||||
return <BasePermissionIconButton {...props} access={access} />;
|
||||
|
@ -27,8 +27,8 @@ const ProjectenvironmentPermissionSwitch = React.forwardRef<
|
||||
>((props, ref) => {
|
||||
const access = useHasProjectEnvironmentAccess(
|
||||
props.permission,
|
||||
props.environmentId,
|
||||
props.projectId
|
||||
props.projectId,
|
||||
props.environmentId
|
||||
);
|
||||
|
||||
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
||||
@ -40,8 +40,8 @@ const RootPermissionSwitch = React.forwardRef<
|
||||
>((props, ref) => {
|
||||
const access = useHasRootAccess(
|
||||
props.permission,
|
||||
props.environmentId,
|
||||
props.projectId
|
||||
props.projectId,
|
||||
props.environmentId
|
||||
);
|
||||
|
||||
return <BasePermissionSwitch {...props} access={access} ref={ref} />;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user