@webitel/ui-datalist 26.12.1 → 26.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-datalist",
3
- "version": "26.12.1",
3
+ "version": "26.12.3",
4
4
  "description": "Toolkit for building data lists in webitel ui system",
5
5
  "scripts": {
6
6
  "build:types": "vue-tsc -b tsconfig.build.json",
@@ -1,3 +1,4 @@
1
+ import { AccessRuleName } from '@webitel/ui-sdk/modules/ObjectPermissions/enums';
1
2
  import type { TableApiModule } from '../../types/tableStore.types';
2
3
  import type {
3
4
  PermissionEntity,
@@ -13,6 +14,25 @@ import type {
13
14
  export const PermissionsApiModule = (
14
15
  rawApiModule: RawPermissionsApiModule,
15
16
  ): TableApiModule<PermissionEntity> => {
17
+ /**
18
+ * [Claude] The rule columns are keyed by their letter (`r`, `w`, `d`), so
19
+ * each sorts on its own, but the endpoint has no such attributes in `fields`:
20
+ * it returns the three rules merged into one `granted` string, asked for once.
21
+ */
22
+ const toAclFields = (fields?: string[]) => {
23
+ if (!fields) return fields;
24
+ const ruleFields = Object.values(AccessRuleName).filter(
25
+ (rule) => rule !== AccessRuleName.X,
26
+ );
27
+ return [
28
+ ...new Set(
29
+ fields
30
+ .filter((field) => field !== 'id')
31
+ .map((field) => (ruleFields.includes(field) ? 'granted' : field)),
32
+ ),
33
+ ];
34
+ };
35
+
16
36
  /**
17
37
  * The table store always asks for `id` (every registry needs it to open or
18
38
  * delete a row), but an access rule has no such attribute and the endpoint
@@ -27,7 +47,7 @@ export const PermissionsApiModule = (
27
47
  } & Record<string, unknown>) =>
28
48
  rawApiModule.getPermissionsList?.({
29
49
  ...params,
30
- fields: fields?.filter((field) => field !== 'id'),
50
+ fields: toAclFields(fields),
31
51
  });
32
52
 
33
53
  return {
@@ -0,0 +1,31 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import { PermissionsApiModule } from '../PermissionsApiModule';
4
+
5
+ describe('PermissionsApiModule', () => {
6
+ it('asks for one `granted` in place of the rule columns, and never for `id`', async () => {
7
+ const getPermissionsList = vi.fn();
8
+ const { getList } = PermissionsApiModule({
9
+ getPermissionsList,
10
+ } as never);
11
+
12
+ await getList({
13
+ fields: [
14
+ 'id',
15
+ 'grantee',
16
+ 'r',
17
+ 'w',
18
+ 'd',
19
+ ],
20
+ sort: '+w',
21
+ } as never);
22
+
23
+ expect(getPermissionsList).toHaveBeenCalledWith({
24
+ fields: [
25
+ 'grantee',
26
+ 'granted',
27
+ ],
28
+ sort: '+w',
29
+ });
30
+ });
31
+ });