import React from 'react'; import NiceModal from '@ebay/nice-modal-react'; import {Dialog, Flex, Text} from '@gravity-ui/uikit'; import {SubjectWithAvatar} from '../../../../../../components/SubjectWithAvatar/SubjectWithAvatar'; import {useNonDefaultAclInheritanceRevocationAvailable} from '../../../../../../store/reducers/capabilities/hooks'; import {useClusterWithProxy} from '../../../../../../store/reducers/cluster/cluster'; import { schemaAclApi, selectSubjectExplicitAllowAces, } from '../../../../../../store/reducers/schemaAcl/schemaAcl'; import {prepareRevokeAllRightsRequest} from '../../../../../../store/reducers/schemaAcl/utils'; import createToast from '../../../../../../utils/createToast'; import {useAclSyntax, useTypedSelector} from '../../../../../../utils/hooks'; import {prepareErrorMessage} from '../../../../../../utils/prepareErrorMessage'; import i18n from '../../i18n'; const REVOKE_ALL_RIGHTS_DIALOG = 'revoke-all-rights-dialog'; interface GetRevokeAllRightsDialogProps { path: string; database: string; databaseFullPath: string; subject: string; } export async function getRevokeAllRightsDialog({ path, database, subject, databaseFullPath, }: GetRevokeAllRightsDialogProps): Promise { return await NiceModal.show(REVOKE_ALL_RIGHTS_DIALOG, { id: REVOKE_ALL_RIGHTS_DIALOG, path, database, subject, databaseFullPath, }); } const RevokeAllRightsDialogNiceModal = NiceModal.create( ({path, database, subject, databaseFullPath}: GetRevokeAllRightsDialogProps) => { const modal = NiceModal.useModal(); const handleClose = () => { modal.hide(); modal.remove(); }; return ( { modal.resolve(false); handleClose(); }} open={modal.visible} path={path} database={database} subject={subject} databaseFullPath={databaseFullPath} /> ); }, ); NiceModal.register(REVOKE_ALL_RIGHTS_DIALOG, RevokeAllRightsDialogNiceModal); interface RevokeAllRightsDialogProps extends GetRevokeAllRightsDialogProps { open: boolean; onClose: () => void; } function RevokeAllRightsDialog({ open, onClose, path, database, databaseFullPath, subject, }: RevokeAllRightsDialogProps) { const useMetaProxy = useClusterWithProxy(); const supportsNonDefaultInheritanceRevocation = useNonDefaultAclInheritanceRevocationAvailable(); const dialect = useAclSyntax(); const subjectExplicitAces = useTypedSelector((state) => selectSubjectExplicitAllowAces( state, subject, path, database, databaseFullPath, dialect, useMetaProxy, ), ); const [requestErrorMessage, setRequestErrorMessage] = React.useState(''); const [removeAccess, removeAccessResponse] = schemaAclApi.useUpdateAccessMutation(); const onApply = () => { removeAccess({ path, database, databaseFullPath, dialect, rights: prepareRevokeAllRightsRequest( subjectExplicitAces, supportsNonDefaultInheritanceRevocation, ), }) .unwrap() .then(() => { onClose(); createToast({ name: 'revokeAllRights', content: i18n('description_rights-revoked'), autoHiding: 3000, }); }) .catch((error) => { setRequestErrorMessage(prepareErrorMessage(error)); }); }; return ( {i18n('description_revoke-all-rights')} {requestErrorMessage && ( {requestErrorMessage} )} ); } export default RevokeAllRightsDialog;