mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: validate import permissions (#3097)
This commit is contained in:
parent
5c5269d618
commit
57bce6e039
@ -10,6 +10,8 @@ import useToast from 'hooks/useToast';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import { ActionsContainer } from '../ActionsContainer';
|
import { ActionsContainer } from '../ActionsContainer';
|
||||||
import { IMPORT_CONFIGURATION_BUTTON } from 'utils/testIds';
|
import { IMPORT_CONFIGURATION_BUTTON } from 'utils/testIds';
|
||||||
|
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
|
||||||
|
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions';
|
||||||
|
|
||||||
const ImportInfoContainer = styled(Box)(({ theme }) => ({
|
const ImportInfoContainer = styled(Box)(({ theme }) => ({
|
||||||
backgroundColor: theme.palette.secondaryContainer,
|
backgroundColor: theme.palette.secondaryContainer,
|
||||||
@ -92,7 +94,7 @@ export const ValidationStage: FC<{
|
|||||||
const { validateImport } = useValidateImportApi();
|
const { validateImport } = useValidateImportApi();
|
||||||
const { setToastData } = useToast();
|
const { setToastData } = useToast();
|
||||||
const [validationResult, setValidationResult] = useState<IValidationSchema>(
|
const [validationResult, setValidationResult] = useState<IValidationSchema>(
|
||||||
{ errors: [], warnings: [] }
|
{ errors: [], warnings: [], permissions: [] }
|
||||||
);
|
);
|
||||||
const [validJSON, setValidJSON] = useState(true);
|
const [validJSON, setValidJSON] = useState(true);
|
||||||
|
|
||||||
@ -125,6 +127,30 @@ export const ValidationStage: FC<{
|
|||||||
</span>
|
</span>
|
||||||
</Box>
|
</Box>
|
||||||
</ImportInfoContainer>
|
</ImportInfoContainer>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={validationResult.permissions.length > 0}
|
||||||
|
show={
|
||||||
|
<ErrorContainer>
|
||||||
|
<ErrorHeader>
|
||||||
|
<strong>Missing permissions!</strong> There are some
|
||||||
|
permissions that you need to be granted before
|
||||||
|
importing this configuration
|
||||||
|
</ErrorHeader>
|
||||||
|
{validationResult.permissions.map(error => (
|
||||||
|
<Box key={error.message} sx={{ p: 2 }}>
|
||||||
|
<ErrorMessage>{error.message}</ErrorMessage>
|
||||||
|
<StyledItems>
|
||||||
|
{error.affectedItems.map(item => (
|
||||||
|
<StyledItem key={item}>
|
||||||
|
{item}
|
||||||
|
</StyledItem>
|
||||||
|
))}
|
||||||
|
</StyledItems>
|
||||||
|
</Box>
|
||||||
|
))}
|
||||||
|
</ErrorContainer>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={validationResult.errors.length > 0}
|
condition={validationResult.errors.length > 0}
|
||||||
show={
|
show={
|
||||||
@ -187,16 +213,22 @@ export const ValidationStage: FC<{
|
|||||||
>
|
>
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<PermissionButton
|
||||||
|
permission={CREATE_FEATURE}
|
||||||
|
projectId={project}
|
||||||
sx={{ position: 'static' }}
|
sx={{ position: 'static' }}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
data-testid={IMPORT_CONFIGURATION_BUTTON}
|
data-testid={IMPORT_CONFIGURATION_BUTTON}
|
||||||
disabled={validationResult.errors.length > 0 || !validJSON}
|
disabled={
|
||||||
|
validationResult.errors.length > 0 ||
|
||||||
|
validationResult.permissions.length > 0 ||
|
||||||
|
!validJSON
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Import configuration
|
Import configuration
|
||||||
</Button>
|
</PermissionButton>
|
||||||
<Button
|
<Button
|
||||||
sx={{ position: 'static', ml: 2 }}
|
sx={{ position: 'static', ml: 2 }}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
@ -28,6 +28,7 @@ import ProjectOverview from './ProjectOverview';
|
|||||||
import ProjectHealth from './ProjectHealth/ProjectHealth';
|
import ProjectHealth from './ProjectHealth/ProjectHealth';
|
||||||
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
||||||
import {
|
import {
|
||||||
|
CREATE_FEATURE,
|
||||||
DELETE_PROJECT,
|
DELETE_PROJECT,
|
||||||
UPDATE_PROJECT,
|
UPDATE_PROJECT,
|
||||||
} from 'component/providers/AccessProvider/permissions';
|
} from 'component/providers/AccessProvider/permissions';
|
||||||
@ -142,7 +143,7 @@ export const Project = () => {
|
|||||||
)}
|
)}
|
||||||
show={
|
show={
|
||||||
<PermissionIconButton
|
<PermissionIconButton
|
||||||
permission={UPDATE_PROJECT}
|
permission={CREATE_FEATURE}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
sx={{
|
sx={{
|
||||||
visibility: isOss()
|
visibility: isOss()
|
||||||
|
@ -8,6 +8,7 @@ export interface ImportQuerySchema {
|
|||||||
export interface IValidationSchema {
|
export interface IValidationSchema {
|
||||||
errors: Array<{ message: string; affectedItems: Array<string> }>;
|
errors: Array<{ message: string; affectedItems: Array<string> }>;
|
||||||
warnings: Array<{ message: string; affectedItems: Array<string> }>;
|
warnings: Array<{ message: string; affectedItems: Array<string> }>;
|
||||||
|
permissions: Array<{ message: string; affectedItems: Array<string> }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useValidateImportApi = () => {
|
export const useValidateImportApi = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user