Skip to content

Commit e5e6f3a

Browse files
authored
feat: add setting to select syntax in acl handlers (#2474)
1 parent 1eb4e01 commit e5e6f3a

File tree

19 files changed

+400
-91
lines changed

19 files changed

+400
-91
lines changed

src/containers/Tenant/Diagnostics/AccessRights/AccessRights.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {ResponseError} from '../../../../components/Errors/ResponseError';
77
import {LoaderWrapper} from '../../../../components/LoaderWrapper/LoaderWrapper';
88
import {useEditAccessAvailable} from '../../../../store/reducers/capabilities/hooks';
99
import {schemaAclApi} from '../../../../store/reducers/schemaAcl/schemaAcl';
10-
import {useAutoRefreshInterval} from '../../../../utils/hooks';
10+
import {useAclSyntax, useAutoRefreshInterval} from '../../../../utils/hooks';
1111
import {useCurrentSchema} from '../../TenantContext';
1212
import {useTenantQueryParams} from '../../useTenantQueryParams';
1313

@@ -22,15 +22,18 @@ export function AccessRights() {
2222
const {path, database} = useCurrentSchema();
2323
const editable = useEditAccessAvailable();
2424
const [autoRefreshInterval] = useAutoRefreshInterval();
25-
const {isLoading, error} = schemaAclApi.useGetSchemaAclQuery(
26-
{path, database},
25+
const dialect = useAclSyntax();
26+
const {isFetching, currentData, error} = schemaAclApi.useGetSchemaAclQuery(
27+
{path, database, dialect},
2728
{
2829
pollingInterval: autoRefreshInterval,
2930
},
3031
);
3132

3233
const {handleShowGrantAccessChange} = useTenantQueryParams();
3334

35+
const loading = isFetching && !currentData;
36+
3437
const renderContent = () => {
3538
if (error) {
3639
return <ResponseError error={error} />;
@@ -62,5 +65,5 @@ export function AccessRights() {
6265
);
6366
};
6467

65-
return <LoaderWrapper loading={isLoading}>{renderContent()}</LoaderWrapper>;
68+
return <LoaderWrapper loading={loading}>{renderContent()}</LoaderWrapper>;
6669
}

src/containers/Tenant/Diagnostics/AccessRights/components/ChangeOwnerDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Dialog, Text, TextInput} from '@gravity-ui/uikit';
55

66
import {schemaAclApi} from '../../../../../store/reducers/schemaAcl/schemaAcl';
77
import createToast from '../../../../../utils/createToast';
8+
import {useAclSyntax} from '../../../../../utils/hooks';
89
import {prepareErrorMessage} from '../../../../../utils/prepareErrorMessage';
910
import i18n from '../i18n';
1011
import {block} from '../shared';
@@ -61,13 +62,14 @@ function ChangeOwnerDialog({open, onClose, path, database}: ChangeOwnerDialogPro
6162
const [newOwner, setNewOwner] = React.useState('');
6263
const [requestErrorMessage, setRequestErrorMessage] = React.useState('');
6364
const [updateOwner, updateOwnerResponse] = schemaAclApi.useUpdateAccessMutation();
65+
const dialect = useAclSyntax();
6466

6567
const handleTyping = (value: string) => {
6668
setNewOwner(value);
6769
setRequestErrorMessage('');
6870
};
6971
const onApply = () => {
70-
updateOwner({path, database, rights: {ChangeOwnership: {Subject: newOwner}}})
72+
updateOwner({path, database, dialect, rights: {ChangeOwnership: {Subject: newOwner}}})
7173
.unwrap()
7274
.then(() => {
7375
onClose();

src/containers/Tenant/Diagnostics/AccessRights/components/Owner.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ActionTooltip, Button, Card, Divider, Flex, Icon, Text} from '@gravity-u
44
import {SubjectWithAvatar} from '../../../../../components/SubjectWithAvatar/SubjectWithAvatar';
55
import {useEditAccessAvailable} from '../../../../../store/reducers/capabilities/hooks';
66
import {selectSchemaOwner} from '../../../../../store/reducers/schemaAcl/schemaAcl';
7-
import {useTypedSelector} from '../../../../../utils/hooks';
7+
import {useAclSyntax, useTypedSelector} from '../../../../../utils/hooks';
88
import {useCurrentSchema} from '../../../TenantContext';
99
import i18n from '../i18n';
1010
import {block} from '../shared';
@@ -14,7 +14,8 @@ import {getChangeOwnerDialog} from './ChangeOwnerDialog';
1414
export function Owner() {
1515
const editable = useEditAccessAvailable();
1616
const {path, database} = useCurrentSchema();
17-
const owner = useTypedSelector((state) => selectSchemaOwner(state, path, database));
17+
const dialect = useAclSyntax();
18+
const owner = useTypedSelector((state) => selectSchemaOwner(state, path, database, dialect));
1819

1920
if (!owner) {
2021
return null;

src/containers/Tenant/Diagnostics/AccessRights/components/RightsTable/Actions.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {ActionTooltip, Button, Flex, Icon} from '@gravity-ui/uikit';
33

44
import {useEditAccessAvailable} from '../../../../../../store/reducers/capabilities/hooks';
55
import {selectSubjectExplicitRights} from '../../../../../../store/reducers/schemaAcl/schemaAcl';
6-
import {useTypedSelector} from '../../../../../../utils/hooks';
6+
import {useAclSyntax, useTypedSelector} from '../../../../../../utils/hooks';
77
import {useCurrentSchema} from '../../../../TenantContext';
88
import {useTenantQueryParams} from '../../../../useTenantQueryParams';
99
import i18n from '../../i18n';
@@ -50,8 +50,9 @@ function GrantRightsToSubject({subject}: ActionProps) {
5050

5151
function RevokeAllRights({subject}: ActionProps) {
5252
const {path, database} = useCurrentSchema();
53+
const dialect = useAclSyntax();
5354
const subjectExplicitRights = useTypedSelector((state) =>
54-
selectSubjectExplicitRights(state, subject, path, database),
55+
selectSubjectExplicitRights(state, subject, path, database, dialect),
5556
);
5657
const noRightsToRevoke = subjectExplicitRights.length === 0;
5758

src/containers/Tenant/Diagnostics/AccessRights/components/RightsTable/RevokeAllRightsDialog.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
selectSubjectExplicitRights,
1010
} from '../../../../../../store/reducers/schemaAcl/schemaAcl';
1111
import createToast from '../../../../../../utils/createToast';
12-
import {useTypedSelector} from '../../../../../../utils/hooks';
12+
import {useAclSyntax, useTypedSelector} from '../../../../../../utils/hooks';
1313
import {prepareErrorMessage} from '../../../../../../utils/prepareErrorMessage';
1414
import i18n from '../../i18n';
1515

@@ -72,8 +72,9 @@ function RevokeAllRightsDialog({
7272
database,
7373
subject,
7474
}: RevokeAllRightsDialogProps) {
75+
const dialect = useAclSyntax();
7576
const subjectExplicitRights = useTypedSelector((state) =>
76-
selectSubjectExplicitRights(state, subject, path, database),
77+
selectSubjectExplicitRights(state, subject, path, database, dialect),
7778
);
7879

7980
const [requestErrorMessage, setRequestErrorMessage] = React.useState('');
@@ -83,6 +84,7 @@ function RevokeAllRightsDialog({
8384
removeAccess({
8485
path,
8586
database,
87+
dialect,
8688
rights: {
8789
RemoveAccess: [
8890
{

src/containers/Tenant/Diagnostics/AccessRights/components/RightsTable/RightsTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {Settings} from '@gravity-ui/react-data-table';
33
import {ResizeableDataTable} from '../../../../../../components/ResizeableDataTable/ResizeableDataTable';
44
import {selectPreparedRights} from '../../../../../../store/reducers/schemaAcl/schemaAcl';
55
import {DEFAULT_TABLE_SETTINGS} from '../../../../../../utils/constants';
6-
import {useTypedSelector} from '../../../../../../utils/hooks';
6+
import {useAclSyntax, useTypedSelector} from '../../../../../../utils/hooks';
77
import {useCurrentSchema} from '../../../../TenantContext';
88
import i18n from '../../i18n';
99
import {block} from '../../shared';
@@ -16,7 +16,8 @@ const AccessRightsTableSettings: Settings = {...DEFAULT_TABLE_SETTINGS, dynamicR
1616

1717
export function RightsTable() {
1818
const {path, database} = useCurrentSchema();
19-
const data = useTypedSelector((state) => selectPreparedRights(state, path, database));
19+
const dialect = useAclSyntax();
20+
const data = useTypedSelector((state) => selectPreparedRights(state, path, database, dialect));
2021
return (
2122
<ResizeableDataTable
2223
columnsWidthLSKey={RIGHT_TABLE_COLUMNS_WIDTH_LS_KEY}

src/containers/Tenant/GrantAccess/GrantAccess.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
selectSubjectInheritedRights,
1111
} from '../../../store/reducers/schemaAcl/schemaAcl';
1212
import createToast from '../../../utils/createToast';
13-
import {useTypedSelector} from '../../../utils/hooks';
13+
import {useAclSyntax, useTypedSelector} from '../../../utils/hooks';
1414
import {prepareErrorMessage} from '../../../utils/prepareErrorMessage';
1515
import {useCurrentSchema} from '../TenantContext';
1616
import {useTenantQueryParams} from '../useTenantQueryParams';
@@ -36,24 +36,27 @@ export function GrantAccess({handleCloseDrawer}: GrantAccessProps) {
3636
const [rightView, setRightsView] = React.useState<RightsView>('Groups');
3737

3838
const {path, database} = useCurrentSchema();
39+
const dialect = useAclSyntax();
3940
const {currentRightsMap, setExplicitRightsChanges, rightsToGrant, rightsToRevoke, hasChanges} =
4041
useRights({aclSubject: aclSubject ?? undefined, path, database});
4142
const {isFetching: aclIsFetching} = schemaAclApi.useGetSchemaAclQuery(
4243
{
4344
path,
4445
database,
46+
dialect,
4547
},
4648
{skip: !aclSubject},
4749
);
4850
const {isFetching: availableRightsAreFetching} = schemaAclApi.useGetAvailablePermissionsQuery({
4951
database,
52+
dialect,
5053
});
5154
const [updateRights, updateRightsResponse] = schemaAclApi.useUpdateAccessMutation();
5255

5356
const [updateRightsError, setUpdateRightsError] = React.useState('');
5457

5558
const inheritedRightsSet = useTypedSelector((state) =>
56-
selectSubjectInheritedRights(state, aclSubject ?? undefined, path, database),
59+
selectSubjectInheritedRights(state, aclSubject ?? undefined, path, database, dialect),
5760
);
5861

5962
const handleDiscardRightsChanges = React.useCallback(() => {
@@ -68,6 +71,7 @@ export function GrantAccess({handleCloseDrawer}: GrantAccessProps) {
6871
updateRights({
6972
path,
7073
database,
74+
dialect,
7175
rights: {
7276
AddAccess: subjects.map((subj) => ({
7377
AccessRights: rightsToGrant,
@@ -98,6 +102,7 @@ export function GrantAccess({handleCloseDrawer}: GrantAccessProps) {
98102
updateRights,
99103
path,
100104
database,
105+
dialect,
101106
rightsToGrant,
102107
aclSubject,
103108
rightsToRevoke,
@@ -106,7 +111,7 @@ export function GrantAccess({handleCloseDrawer}: GrantAccessProps) {
106111
]);
107112

108113
const availablePermissions = useTypedSelector((state) =>
109-
selectAvailablePermissions(state, database),
114+
selectAvailablePermissions(state, database, dialect),
110115
);
111116
const handleChangeRightGetter = React.useCallback(
112117
(right: string) => {

src/containers/Tenant/GrantAccess/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {selectSubjectExplicitRights} from '../../../store/reducers/schemaAcl/schemaAcl';
4-
import {useTypedSelector} from '../../../utils/hooks';
4+
import {useAclSyntax, useTypedSelector} from '../../../utils/hooks';
55

66
interface UseRightsProps {
77
aclSubject?: string;
@@ -10,8 +10,9 @@ interface UseRightsProps {
1010
}
1111

1212
export function useRights({aclSubject, path, database}: UseRightsProps) {
13+
const dialect = useAclSyntax();
1314
const subjectExplicitRights = useTypedSelector((state) =>
14-
selectSubjectExplicitRights(state, aclSubject ?? undefined, path, database),
15+
selectSubjectExplicitRights(state, aclSubject ?? undefined, path, database, dialect),
1516
);
1617
const [explicitRightsChanges, setExplicitRightsChanges] = React.useState(
1718
() => new Map<string, boolean>(),

src/containers/UserSettings/i18n/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@
4848
"settings.useClusterBalancerAsBackend.title": "Use cluster balancer as backend",
4949
"settings.useClusterBalancerAsBackend.description": "By default random cluster node is used as backend. It causes saved links to become invalid after some time, when node is restarted. Using balancer as backend fixes it",
5050

51+
"settings.aclSyntax.title": "ACL syntax format",
52+
"settings.aclSyntax.option-kikimr": "KiKiMr",
53+
"settings.aclSyntax.option-ydb-short": "YDB Short",
54+
"settings.aclSyntax.option-ydb": "YDB",
55+
"settings.aclSyntax.option-yql": "YQL",
56+
5157
"settings.about.interfaceVersionInfoField.title": "Interface version"
5258
}

src/containers/UserSettings/settings.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {createNextState} from '@reduxjs/toolkit';
44

55
import {codeAssistBackend} from '../../store';
66
import {
7+
ACL_SYNTAX_KEY,
78
AUTOCOMPLETE_ON_ENTER,
9+
AclSyntax,
810
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
911
ENABLE_AUTOCOMPLETE,
1012
ENABLE_CODE_ASSISTANT,
@@ -147,6 +149,32 @@ export const autocompleteOnEnterSetting: SettingProps = {
147149
description: i18n('settings.editor.autocomplete-on-enter.description'),
148150
};
149151

152+
const aclSyntaxOptions = [
153+
{
154+
value: AclSyntax.Kikimr,
155+
content: i18n('settings.aclSyntax.option-kikimr'),
156+
},
157+
{
158+
value: AclSyntax.YdbShort,
159+
content: i18n('settings.aclSyntax.option-ydb-short'),
160+
},
161+
{
162+
value: AclSyntax.Ydb,
163+
content: i18n('settings.aclSyntax.option-ydb'),
164+
},
165+
{
166+
value: AclSyntax.Yql,
167+
content: i18n('settings.aclSyntax.option-yql'),
168+
},
169+
];
170+
171+
export const aclSyntaxSetting: SettingProps = {
172+
settingKey: ACL_SYNTAX_KEY,
173+
title: i18n('settings.aclSyntax.title'),
174+
type: 'radio',
175+
options: aclSyntaxOptions,
176+
};
177+
150178
export const interfaceVersionInfoField: SettingsInfoFieldProps = {
151179
title: i18n('settings.about.interfaceVersionInfoField.title'),
152180
type: 'info',
@@ -161,6 +189,7 @@ export const appearanceSection: SettingsSection = {
161189
invertedDisksSetting,
162190
binaryDataInPlainTextDisplay,
163191
showDomainDatabase,
192+
aclSyntaxSetting,
164193
],
165194
};
166195

0 commit comments

Comments
 (0)