Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function AccessRights() {
const {path, database} = useCurrentSchema();
const editable = useEditAccessAvailable();
const [autoRefreshInterval] = useAutoRefreshInterval();
const {currentData, isFetching, error} = schemaAclApi.useGetSchemaAclQuery(
const {isLoading, error} = schemaAclApi.useGetSchemaAclQuery(
{path, database},
{
pollingInterval: autoRefreshInterval,
Expand All @@ -31,8 +31,6 @@ export function AccessRights() {

const {handleShowGrantAccessChange} = useTenantQueryParams();

const loading = isFetching && !currentData;

const renderContent = () => {
if (error) {
return <ResponseError error={error} />;
Expand Down Expand Up @@ -64,5 +62,5 @@ export function AccessRights() {
);
};

return <LoaderWrapper loading={loading}>{renderContent()}</LoaderWrapper>;
return <LoaderWrapper loading={isLoading}>{renderContent()}</LoaderWrapper>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,56 @@ function ChangeOwnerDialog({open, onClose, path, database}: ChangeOwnerDialogPro
setNewOwner(value);
setRequestErrorMessage('');
};
const onApply = () => {
updateOwner({path, database, rights: {ChangeOwnership: {Subject: newOwner}}})
.unwrap()
.then(() => {
onClose();
createToast({
name: 'updateOwner',
content: i18n('title_owner-changed'),
autoHiding: 3000,
});
})
.catch((error) => {
setRequestErrorMessage(prepareErrorMessage(error));
});
};
return (
<Dialog open={open} size="s" onClose={onClose}>
<Dialog open={open} size="s" onClose={onClose} onEnterKeyDown={onApply}>
<Dialog.Header caption={i18n('action_change-owner')} />
<form
onSubmit={(e) => {
e.preventDefault();
updateOwner({path, database, rights: {ChangeOwnership: {Subject: newOwner}}})
.unwrap()
.then(() => {
onClose();
createToast({
name: 'updateOwner',
content: i18n('title_owner-changed'),
autoHiding: 3000,
});
})
.catch((error) => {
setRequestErrorMessage(prepareErrorMessage(error));
});
<Dialog.Body>
<div className={block('dialog-content-wrapper')}>
<TextInput
id="queryName"
placeholder={i18n('decription_enter-subject')}
value={newOwner}
onUpdate={handleTyping}
hasClear
autoFocus
autoComplete={false}
/>
{requestErrorMessage && (
<Text
color="danger"
className={block('dialog-error')}
title={requestErrorMessage}
>
{requestErrorMessage}
</Text>
)}
</div>
</Dialog.Body>
<Dialog.Footer
onClickButtonApply={onApply}
textButtonCancel={i18n('action_cancel')}
textButtonApply={i18n('action_apply')}
onClickButtonCancel={onClose}
propsButtonApply={{
loading: updateOwnerResponse.isLoading,
disabled: !newOwner.length,
}}
>
<Dialog.Body>
<div className={block('dialog-content-wrapper')}>
<TextInput
id="queryName"
placeholder={i18n('decription_enter-subject')}
value={newOwner}
onUpdate={handleTyping}
hasClear
autoFocus
autoComplete={false}
/>
{requestErrorMessage && (
<Text
color="danger"
className={block('dialog-error')}
title={requestErrorMessage}
>
{requestErrorMessage}
</Text>
)}
</div>
</Dialog.Body>
<Dialog.Footer
textButtonCancel={i18n('action_cancel')}
textButtonApply={i18n('action_apply')}
onClickButtonCancel={onClose}
propsButtonApply={{
type: 'submit',
loading: updateOwnerResponse.isLoading,
disabled: !newOwner.length,
}}
/>
</form>
/>
</Dialog>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,62 +79,59 @@ function RevokeAllRightsDialog({
const [requestErrorMessage, setRequestErrorMessage] = React.useState('');
const [removeAccess, removeAccessResponse] = schemaAclApi.useUpdateAccessMutation();

const onApply = () => {
removeAccess({
path,
database,
rights: {
RemoveAccess: [
{
Subject: subject,
AccessRights: Array.from(subjectExplicitRights),
AccessType: 'Allow',
},
],
},
})
.unwrap()
.then(() => {
onClose();
createToast({
name: 'revokeAllRights',
content: i18n('description_rights-revoked'),
autoHiding: 3000,
});
})
.catch((error) => {
setRequestErrorMessage(prepareErrorMessage(error));
});
};

return (
<Dialog open={open} size="s" onClose={onClose}>
<Dialog.Header caption={i18n('label_revoke-all-rights')} />
<form
onSubmit={(e) => {
e.preventDefault();
removeAccess({
path,
database,
rights: {
RemoveAccess: [
{
Subject: subject,
AccessRights: Array.from(subjectExplicitRights),
AccessType: 'Allow',
},
],
},
})
.unwrap()
.then(() => {
onClose();
createToast({
name: 'revokeAllRights',
content: i18n('description_rights-revoked'),
autoHiding: 3000,
});
})
.catch((error) => {
setRequestErrorMessage(prepareErrorMessage(error));
});
<Dialog.Body>
<Flex direction="column" gap={5}>
<Text variant="body-2">{i18n('description_revoke-all-rights')}</Text>
<SubjectWithAvatar subject={subject} />
</Flex>
</Dialog.Body>
<Dialog.Footer
onClickButtonApply={onApply}
textButtonCancel={i18n('action_cancel')}
textButtonApply={i18n('action_revoke')}
onClickButtonCancel={onClose}
propsButtonApply={{
loading: removeAccessResponse.isLoading,
view: 'outlined-danger',
}}
>
<Dialog.Body>
<Flex direction="column" gap={5}>
<Text variant="body-2">{i18n('description_revoke-all-rights')}</Text>
<SubjectWithAvatar subject={subject} />
</Flex>
</Dialog.Body>
<Dialog.Footer
textButtonCancel={i18n('action_cancel')}
textButtonApply={i18n('action_revoke')}
onClickButtonCancel={onClose}
propsButtonApply={{
type: 'submit',
loading: removeAccessResponse.isLoading,
view: 'outlined-danger',
}}
>
{requestErrorMessage && (
<Text color="danger" title={requestErrorMessage}>
{requestErrorMessage}
</Text>
)}
</Dialog.Footer>
</form>
{requestErrorMessage && (
<Text color="danger" title={requestErrorMessage}>
{requestErrorMessage}
</Text>
)}
</Dialog.Footer>
</Dialog>
);
}
Expand Down
53 changes: 25 additions & 28 deletions src/containers/Tenant/GrantAccess/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import i18n from './i18n';

export const block = cn('ydb-grant-access');

export const HumanReadableRights: Record<string, number> = {
export const RightsCodes: Record<string, number> = {
selectRow: 1,
updateRow: 2,
eraseRow: 4,
Expand All @@ -31,36 +31,33 @@ export const HumanReadableRights: Record<string, number> = {
};

export const RightsDescription: Record<number, string> = {
[HumanReadableRights.selectRow]: i18n('description_select-row'),
[HumanReadableRights.updateRow]: i18n('description_update-row'),
[HumanReadableRights.eraseRow]: i18n('description_erase-row'),
[HumanReadableRights.writeAttributes]: i18n('description_write-attributes'),
[HumanReadableRights.createDirectory]: i18n('description_create-directory'),
[HumanReadableRights.createTable]: i18n('description_create-table'),
[HumanReadableRights.createQueue]: i18n('description_create-queue'),
[HumanReadableRights.removeSchema]: i18n('description_remove-schema'),
[HumanReadableRights.alterSchema]: i18n('description_alter-schema'),
[HumanReadableRights.createDatabase]: i18n('description_create-database'),
[HumanReadableRights.dropDatabase]: i18n('description_drop-database'),
[HumanReadableRights.readAttributes]: i18n('description_read-attributes'),
[HumanReadableRights.describeSchema]: i18n('description_describe-schema'),
[HumanReadableRights.connectDatabase]: i18n('description_connect-database'),
[HumanReadableRights.grantAccessRights]: i18n('description_grant-access-rights'),
[HumanReadableRights.genericRead]: i18n('description_generic-read'),
[HumanReadableRights.genericWrite]: i18n('description_generic-write'),
[HumanReadableRights.genericManage]: i18n('description_generic-manage'),
[HumanReadableRights.genericList]: i18n('description_generic-list'),
[HumanReadableRights.genericUse]: i18n('description_generic-use'),
[HumanReadableRights.genericUseLegacy]: i18n('description_generic-use-legacy'),
[HumanReadableRights.genericFull]: i18n('description_generic-full'),
[HumanReadableRights.genericFullLegacy]: i18n('description_generic-full-legacy'),
[RightsCodes.selectRow]: i18n('description_select-row'),
[RightsCodes.updateRow]: i18n('description_update-row'),
[RightsCodes.eraseRow]: i18n('description_erase-row'),
[RightsCodes.writeAttributes]: i18n('description_write-attributes'),
[RightsCodes.createDirectory]: i18n('description_create-directory'),
[RightsCodes.createTable]: i18n('description_create-table'),
[RightsCodes.createQueue]: i18n('description_create-queue'),
[RightsCodes.removeSchema]: i18n('description_remove-schema'),
[RightsCodes.alterSchema]: i18n('description_alter-schema'),
[RightsCodes.createDatabase]: i18n('description_create-database'),
[RightsCodes.dropDatabase]: i18n('description_drop-database'),
[RightsCodes.readAttributes]: i18n('description_read-attributes'),
[RightsCodes.describeSchema]: i18n('description_describe-schema'),
[RightsCodes.connectDatabase]: i18n('description_connect-database'),
[RightsCodes.grantAccessRights]: i18n('description_grant-access-rights'),
[RightsCodes.genericRead]: i18n('description_generic-read'),
[RightsCodes.genericWrite]: i18n('description_generic-write'),
[RightsCodes.genericManage]: i18n('description_generic-manage'),
[RightsCodes.genericList]: i18n('description_generic-list'),
[RightsCodes.genericUse]: i18n('description_generic-use'),
[RightsCodes.genericUseLegacy]: i18n('description_generic-use-legacy'),
[RightsCodes.genericFull]: i18n('description_generic-full'),
[RightsCodes.genericFullLegacy]: i18n('description_generic-full-legacy'),
};

export function isLegacyRight(right: number) {
return (
right === HumanReadableRights.genericFullLegacy ||
right === HumanReadableRights.genericUseLegacy
);
return right === RightsCodes.genericFullLegacy || right === RightsCodes.genericUseLegacy;
}

export interface CommonRightsProps {
Expand Down
Loading