• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 20065394908

09 Dec 2025 01:36PM UTC coverage: 71.858%. First build
20065394908

Pull #2168

github

web-flow
Merge b9dc7a0f8 into 6fd609a47
Pull Request #2168: feat: base node

22892 of 25545 branches covered (89.61%)

1916 of 2478 new or added lines in 35 files covered. (77.32%)

57741 of 80354 relevant lines covered (71.86%)

4259.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.01
/apps/nestjs-backend/src/features/base-node/base-node.permission.helper.ts
1
/* eslint-disable sonarjs/no-duplicate-string */
5✔
2
import { HttpErrorCode } from '@teable/core';
3
import { BaseNodeResourceType } from '@teable/openapi';
4
import { CustomHttpException } from '../../custom.exception';
5
import { BaseNodeAction } from './types';
6

7
const map: Record<BaseNodeResourceType, Record<BaseNodeAction, string>> = {
5✔
8
  [BaseNodeResourceType.Folder]: {
5✔
9
    [BaseNodeAction.Read]: 'base|read',
5✔
10
    [BaseNodeAction.Create]: 'base|update',
5✔
11
    [BaseNodeAction.Update]: 'base|update',
5✔
12
    [BaseNodeAction.Delete]: 'base|update',
5✔
13
  },
5✔
14
  [BaseNodeResourceType.Table]: {
5✔
15
    [BaseNodeAction.Read]: 'table|read',
5✔
16
    [BaseNodeAction.Create]: 'table|create',
5✔
17
    [BaseNodeAction.Update]: 'table|update',
5✔
18
    [BaseNodeAction.Delete]: 'table|delete',
5✔
19
  },
5✔
20
  [BaseNodeResourceType.Dashboard]: {
5✔
21
    [BaseNodeAction.Read]: 'base|read',
5✔
22
    [BaseNodeAction.Create]: 'base|update',
5✔
23
    [BaseNodeAction.Update]: 'base|update',
5✔
24
    [BaseNodeAction.Delete]: 'base|update',
5✔
25
  },
5✔
26
  [BaseNodeResourceType.Workflow]: {
5✔
27
    [BaseNodeAction.Read]: 'automation|read',
5✔
28
    [BaseNodeAction.Create]: 'automation|create',
5✔
29
    [BaseNodeAction.Update]: 'automation|update',
5✔
30
    [BaseNodeAction.Delete]: 'automation|delete',
5✔
31
  },
5✔
32
  [BaseNodeResourceType.App]: {
5✔
33
    [BaseNodeAction.Read]: 'base|read',
5✔
34
    [BaseNodeAction.Create]: 'base|update',
5✔
35
    [BaseNodeAction.Update]: 'base|update',
5✔
36
    [BaseNodeAction.Delete]: 'base|update',
5✔
37
  },
5✔
38
};
5✔
39

40
export const checkBaseNodePermission = (
5✔
41
  node: { resourceType: BaseNodeResourceType; resourceId: string },
309✔
42
  action: BaseNodeAction,
309✔
43
  permissionContext: {
309✔
44
    tablePermissionMap?: Record<string, string[]>;
45
    permissionSet: Set<string>;
46
  }
47
): boolean => {
48
  const { resourceType } = node;
309✔
49
  const { resourceId } = node;
309✔
50
  const { tablePermissionMap, permissionSet } = permissionContext;
309✔
51
  const checkAction = map[resourceType][action];
309✔
52
  if (resourceType === BaseNodeResourceType.Table && tablePermissionMap) {
309✔
NEW
53
    return tablePermissionMap[resourceId]?.includes(checkAction) ?? false;
×
NEW
54
  }
×
55
  return permissionSet.has(checkAction);
309✔
56
};
309✔
57

58
export const checkBaseNodePermissionCreate = (
5✔
59
  node: { resourceType: BaseNodeResourceType; resourceId: string },
247✔
60
  baseNodePermissions: BaseNodeAction[],
247✔
61
  permissionContext: {
247✔
62
    tablePermissionMap?: Record<string, string[]>;
63
    permissionSet: Set<string>;
64
  }
65
): boolean => {
66
  const checkCreate = baseNodePermissions.includes(BaseNodeAction.Create);
247✔
67
  if (!checkCreate) {
247✔
68
    return true;
125✔
69
  }
125✔
70
  const { resourceType } = node;
122✔
71
  if (!resourceType) {
247!
72
    throw new CustomHttpException(
1✔
73
      'Cannot create base node with empty resource type',
1✔
74
      HttpErrorCode.VALIDATION_ERROR,
1✔
75
      {
1✔
76
        localization: {
1✔
77
          i18nKey: 'httpErrors.baseNode.invalidResourceType',
1✔
78
        },
1✔
79
      }
1✔
80
    );
81
  }
1✔
82

83
  return checkBaseNodePermission(node, BaseNodeAction.Create, permissionContext);
121✔
84
};
121✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc