1
0
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:
Mateusz Kwasniewski 2023-02-14 08:11:45 +01:00 committed by GitHub
parent 5c5269d618
commit 57bce6e039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { ActionsContainer } from '../ActionsContainer';
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 }) => ({
backgroundColor: theme.palette.secondaryContainer,
@ -92,7 +94,7 @@ export const ValidationStage: FC<{
const { validateImport } = useValidateImportApi();
const { setToastData } = useToast();
const [validationResult, setValidationResult] = useState<IValidationSchema>(
{ errors: [], warnings: [] }
{ errors: [], warnings: [], permissions: [] }
);
const [validJSON, setValidJSON] = useState(true);
@ -125,6 +127,30 @@ export const ValidationStage: FC<{
</span>
</Box>
</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
condition={validationResult.errors.length > 0}
show={
@ -187,16 +213,22 @@ export const ValidationStage: FC<{
>
Back
</Button>
<Button
<PermissionButton
permission={CREATE_FEATURE}
projectId={project}
sx={{ position: 'static' }}
variant="contained"
type="submit"
onClick={onSubmit}
data-testid={IMPORT_CONFIGURATION_BUTTON}
disabled={validationResult.errors.length > 0 || !validJSON}
disabled={
validationResult.errors.length > 0 ||
validationResult.permissions.length > 0 ||
!validJSON
}
>
Import configuration
</Button>
</PermissionButton>
<Button
sx={{ position: 'static', ml: 2 }}
variant="outlined"

View File

@ -28,6 +28,7 @@ import ProjectOverview from './ProjectOverview';
import ProjectHealth from './ProjectHealth/ProjectHealth';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
import {
CREATE_FEATURE,
DELETE_PROJECT,
UPDATE_PROJECT,
} from 'component/providers/AccessProvider/permissions';
@ -142,7 +143,7 @@ export const Project = () => {
)}
show={
<PermissionIconButton
permission={UPDATE_PROJECT}
permission={CREATE_FEATURE}
projectId={projectId}
sx={{
visibility: isOss()

View File

@ -8,6 +8,7 @@ export interface ImportQuerySchema {
export interface IValidationSchema {
errors: Array<{ message: string; affectedItems: Array<string> }>;
warnings: Array<{ message: string; affectedItems: Array<string> }>;
permissions: Array<{ message: string; affectedItems: Array<string> }>;
}
export const useValidateImportApi = () => {