@7365admin1/layer-common 4.10.2 → 4.11.0

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.
@@ -1,41 +1,65 @@
1
+ import { permissionsDenied } from "../utils/module-routes";
2
+
1
3
  export function useAreaPermission() {
2
4
  const { hasPermission } = usePermission();
3
5
  const { permissions } = useCleaningPermission();
4
6
 
5
- const { userAppRole } = useLocalSetup();
7
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
8
+
9
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
10
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
11
+ // because a wildcard role is exactly the role a module list exists to narrow --
12
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
13
+ // would have missed every wildcard role, which is why the check is per gate.
14
+ //
15
+ // Inert today: no client has an enforced list, so the list is `[]` for
16
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
17
+ // nothing -- it never reads as "hide everything".
18
+ //
19
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
20
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
21
+ // must mean "nothing denied", not a TypeError inside every gate.
22
+ const moduleDenied = (...modules: string[]) =>
23
+ permissionsDenied(modules, userAppModulesDenied?.value);
6
24
 
7
25
  const canViewAreas = computed(() => {
8
26
  if (!userAppRole.value) return false;
27
+ if (moduleDenied("area-mgmt")) return false;
9
28
  if (userAppRole.value.permissions.includes("*")) return true;
10
29
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "see-all-areas");
11
30
  });
12
31
 
13
32
  const canCreateArea = computed(() => {
14
33
  if (!userAppRole.value) return false;
34
+ if (moduleDenied("area-mgmt")) return false;
15
35
  if (userAppRole.value.permissions.includes("*")) return true;
16
36
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "add-area");
17
37
  });
18
38
 
19
39
  const canUpdateArea = computed(() => {
20
40
  if (!userAppRole.value) return false;
41
+ if (moduleDenied("area-mgmt")) return false;
21
42
  if (userAppRole.value.permissions.includes("*")) return true;
22
43
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "update-area");
23
44
  });
24
45
 
25
46
  const canViewAreaDetails = computed(() => {
26
47
  if (!userAppRole.value) return false;
48
+ if (moduleDenied("area-mgmt")) return false;
27
49
  if (userAppRole.value.permissions.includes("*")) return true;
28
50
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "see-area-details");
29
51
  });
30
52
 
31
53
  const canImportArea = computed(() => {
32
54
  if (!userAppRole.value) return false;
55
+ if (moduleDenied("area-mgmt")) return false;
33
56
  if (userAppRole.value.permissions.includes("*")) return true;
34
57
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "import-areas");
35
58
  });
36
59
 
37
60
  const canDeleteArea = computed(() => {
38
61
  if (!userAppRole.value) return false;
62
+ if (moduleDenied("area-mgmt")) return false;
39
63
  if (userAppRole.value.permissions.includes("*")) return true;
40
64
  return hasPermission(userAppRole.value, permissions, "area-mgmt", "delete-area");
41
65
  });
@@ -1,10 +1,29 @@
1
+ import { permissionsDenied } from "../utils/module-routes";
2
+
1
3
  export function useAttendancePermission() {
2
4
  const { hasPermission } = usePermission();
3
5
  const { permissions } = useCleaningPermission();
4
- const { userAppRole } = useLocalSetup();
6
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
7
+
8
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
9
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
10
+ // because a wildcard role is exactly the role a module list exists to narrow --
11
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
12
+ // would have missed every wildcard role, which is why the check is per gate.
13
+ //
14
+ // Inert today: no client has an enforced list, so the list is `[]` for
15
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
16
+ // nothing -- it never reads as "hide everything".
17
+ //
18
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
19
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
20
+ // must mean "nothing denied", not a TypeError inside every gate.
21
+ const moduleDenied = (...modules: string[]) =>
22
+ permissionsDenied(modules, userAppModulesDenied?.value);
5
23
 
6
24
  const canViewAllAttendance = computed(() => {
7
25
  if (!userAppRole.value) return false;
26
+ if (moduleDenied("attendance-mgmt")) return false;
8
27
  if (userAppRole.value.permissions.includes("*")) return true;
9
28
  return hasPermission(
10
29
  userAppRole.value,
@@ -16,6 +35,7 @@ export function useAttendancePermission() {
16
35
 
17
36
  const canViewAttendanceDetails = computed(() => {
18
37
  if (!userAppRole.value) return false;
38
+ if (moduleDenied("attendance-mgmt")) return false;
19
39
  if (userAppRole.value.permissions.includes("*")) return true;
20
40
  return hasPermission(
21
41
  userAppRole.value,
@@ -27,6 +47,7 @@ export function useAttendancePermission() {
27
47
 
28
48
  const canManageAttendanceSettings = computed(() => {
29
49
  if (!userAppRole.value) return false;
50
+ if (moduleDenied("attendance-mgmt")) return false;
30
51
  if (userAppRole.value.permissions.includes("*")) return true;
31
52
  return hasPermission(
32
53
  userAppRole.value,
@@ -38,6 +59,7 @@ export function useAttendancePermission() {
38
59
 
39
60
  const canViewOwnAttendance = computed(() => {
40
61
  if (!userAppRole.value) return false;
62
+ if (moduleDenied("my-attendance")) return false;
41
63
  if (userAppRole.value.permissions.includes("*")) return true;
42
64
  return hasPermission(
43
65
  userAppRole.value,
@@ -49,6 +71,7 @@ export function useAttendancePermission() {
49
71
 
50
72
  const canCheckInOut = computed(() => {
51
73
  if (!userAppRole.value) return false;
74
+ if (moduleDenied("my-attendance")) return false;
52
75
  if (userAppRole.value.permissions.includes("*")) return true;
53
76
  return hasPermission(
54
77
  userAppRole.value,
@@ -1,4 +1,5 @@
1
1
  import { useCommonPermissions } from "./useCommonPermission";
2
+ import { permissionsDenied } from "../utils/module-routes";
2
3
 
3
4
  export function useBulletinBoardPermission() {
4
5
  const { hasPermission } = usePermission();
@@ -41,12 +42,29 @@ export function useBulletinBoardPermission() {
41
42
  },
42
43
  };
43
44
 
44
- const { userAppRole } = useLocalSetup();
45
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
46
+
47
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
48
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
49
+ // because a wildcard role is exactly the role a module list exists to narrow --
50
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
51
+ // would have missed every wildcard role, which is why the check is per gate.
52
+ //
53
+ // Inert today: no client has an enforced list, so the list is `[]` for
54
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
55
+ // nothing -- it never reads as "hide everything".
56
+ //
57
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
58
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
59
+ // must mean "nothing denied", not a TypeError inside every gate.
60
+ const moduleDenied = (...modules: string[]) =>
61
+ permissionsDenied(modules, userAppModulesDenied?.value);
45
62
 
46
63
  // Every gate fails closed while the role is still resolving: `userAppRole` is
47
64
  // null on the first tick and a null role must never read as "allowed".
48
65
  const canViewBulletinBoard = computed(() => {
49
66
  if (!userAppRole.value) return false;
67
+ if (moduleDenied("bulletin-board", "bulletin-board-mgmt")) return false;
50
68
  if (userAppRole.value.permissions.includes("*")) return true;
51
69
  return (
52
70
  hasPermission(userAppRole.value, permissions, "bulletin-board", "see-all-bulletin-boards") ||
@@ -57,6 +75,7 @@ export function useBulletinBoardPermission() {
57
75
 
58
76
  const canCreateBulletinBoard = computed(() => {
59
77
  if (!userAppRole.value) return false;
78
+ if (moduleDenied("bulletin-board", "bulletin-board-mgmt")) return false;
60
79
  if (userAppRole.value.permissions.includes("*")) return true;
61
80
  return (
62
81
  hasPermission(userAppRole.value, permissions, "bulletin-board", "add-bulletin-board") ||
@@ -66,6 +85,7 @@ export function useBulletinBoardPermission() {
66
85
 
67
86
  const canUpdateBulletinBoard = computed(() => {
68
87
  if (!userAppRole.value) return false;
88
+ if (moduleDenied("bulletin-board", "bulletin-board-mgmt")) return false;
69
89
  if (userAppRole.value.permissions.includes("*")) return true;
70
90
  return (
71
91
  hasPermission(userAppRole.value, permissions, "bulletin-board", "update-bulletin-board") ||
@@ -75,6 +95,7 @@ export function useBulletinBoardPermission() {
75
95
 
76
96
  const canViewBulletinBoardDetails = computed(() => {
77
97
  if (!userAppRole.value) return false;
98
+ if (moduleDenied("bulletin-board", "bulletin-board-mgmt")) return false;
78
99
  if (userAppRole.value.permissions.includes("*")) return true;
79
100
  return (
80
101
  hasPermission(userAppRole.value, permissions, "bulletin-board", "see-bulletin-board-details") ||
@@ -84,6 +105,7 @@ export function useBulletinBoardPermission() {
84
105
 
85
106
  const canDeleteBulletinBoard = computed(() => {
86
107
  if (!userAppRole.value) return false;
108
+ if (moduleDenied("bulletin-board", "bulletin-board-mgmt")) return false;
87
109
  if (userAppRole.value.permissions.includes("*")) return true;
88
110
  return (
89
111
  hasPermission(userAppRole.value, permissions, "bulletin-board", "delete-bulletin-board") ||
@@ -1,10 +1,29 @@
1
+ import { permissionsDenied } from "../utils/module-routes";
2
+
1
3
  export function useEquipmentItemPermission() {
2
4
  const { hasPermission } = usePermission();
3
5
  const { permissions } = useCleaningPermission();
4
- const { userAppRole } = useLocalSetup();
6
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
7
+
8
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
9
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
10
+ // because a wildcard role is exactly the role a module list exists to narrow --
11
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
12
+ // would have missed every wildcard role, which is why the check is per gate.
13
+ //
14
+ // Inert today: no client has an enforced list, so the list is `[]` for
15
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
16
+ // nothing -- it never reads as "hide everything".
17
+ //
18
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
19
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
20
+ // must mean "nothing denied", not a TypeError inside every gate.
21
+ const moduleDenied = (...modules: string[]) =>
22
+ permissionsDenied(modules, userAppModulesDenied?.value);
5
23
 
6
24
  const canViewAllEquipmentItems = computed(() => {
7
25
  if (!userAppRole.value) return false;
26
+ if (moduleDenied("checkout-item-mgmt")) return false;
8
27
  if (userAppRole.value.permissions.includes("*")) return true;
9
28
  return hasPermission(
10
29
  userAppRole.value,
@@ -16,6 +35,7 @@ export function useEquipmentItemPermission() {
16
35
 
17
36
  const canCreateEquipmentItem = computed(() => {
18
37
  if (!userAppRole.value) return false;
38
+ if (moduleDenied("checkout-item-mgmt")) return false;
19
39
  if (userAppRole.value.permissions.includes("*")) return true;
20
40
  return hasPermission(
21
41
  userAppRole.value,
@@ -27,6 +47,7 @@ export function useEquipmentItemPermission() {
27
47
 
28
48
  const canUpdateEquipmentItem = computed(() => {
29
49
  if (!userAppRole.value) return false;
50
+ if (moduleDenied("checkout-item-mgmt")) return false;
30
51
  if (userAppRole.value.permissions.includes("*")) return true;
31
52
  return hasPermission(
32
53
  userAppRole.value,
@@ -38,6 +59,7 @@ export function useEquipmentItemPermission() {
38
59
 
39
60
  const canApproveEquipmentItem = computed(() => {
40
61
  if (!userAppRole.value) return false;
62
+ if (moduleDenied("checkout-item-mgmt")) return false;
41
63
  if (userAppRole.value.permissions.includes("*")) return true;
42
64
  return hasPermission(
43
65
  userAppRole.value,
@@ -49,6 +71,7 @@ export function useEquipmentItemPermission() {
49
71
 
50
72
  const canDisapproveEquipmentItem = computed(() => {
51
73
  if (!userAppRole.value) return false;
74
+ if (moduleDenied("checkout-item-mgmt")) return false;
52
75
  if (userAppRole.value.permissions.includes("*")) return true;
53
76
  return hasPermission(
54
77
  userAppRole.value,
@@ -60,6 +83,7 @@ export function useEquipmentItemPermission() {
60
83
 
61
84
  const canViewEquipmentItemDetails = computed(() => {
62
85
  if (!userAppRole.value) return false;
86
+ if (moduleDenied("checkout-item-mgmt")) return false;
63
87
  if (userAppRole.value.permissions.includes("*")) return true;
64
88
  return hasPermission(
65
89
  userAppRole.value,
@@ -1,14 +1,32 @@
1
1
  import useCleaningPermission from "./useCleaningPermission";
2
2
  import { useLocalSetup } from "./useLocalSetup";
3
3
  import usePermission from "./usePermission";
4
+ import { permissionsDenied } from "../utils/module-routes";
4
5
 
5
6
  export function useEquipmentManagementPermission() {
6
7
  const { hasPermission } = usePermission();
7
8
  const { permissions } = useCleaningPermission();
8
- const { userAppRole } = useLocalSetup();
9
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
10
+
11
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
12
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
13
+ // because a wildcard role is exactly the role a module list exists to narrow --
14
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
15
+ // would have missed every wildcard role, which is why the check is per gate.
16
+ //
17
+ // Inert today: no client has an enforced list, so the list is `[]` for
18
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
19
+ // nothing -- it never reads as "hide everything".
20
+ //
21
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
22
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
23
+ // must mean "nothing denied", not a TypeError inside every gate.
24
+ const moduleDenied = (...modules: string[]) =>
25
+ permissionsDenied(modules, userAppModulesDenied?.value);
9
26
 
10
27
  const canViewEquipments = computed(() => {
11
28
  if (!userAppRole.value) return false;
29
+ if (moduleDenied("supply-mgmt")) return false;
12
30
  if (userAppRole.value.permissions.includes("*")) return true;
13
31
  return hasPermission(
14
32
  userAppRole.value,
@@ -20,6 +38,7 @@ export function useEquipmentManagementPermission() {
20
38
 
21
39
  const canAddEquipment = computed(() => {
22
40
  if (!userAppRole.value) return false;
41
+ if (moduleDenied("supply-mgmt")) return false;
23
42
  if (userAppRole.value.permissions.includes("*")) return true;
24
43
  return hasPermission(
25
44
  userAppRole.value,
@@ -31,6 +50,7 @@ export function useEquipmentManagementPermission() {
31
50
 
32
51
  const canUpdateEquipment = computed(() => {
33
52
  if (!userAppRole.value) return false;
53
+ if (moduleDenied("supply-mgmt")) return false;
34
54
  if (userAppRole.value.permissions.includes("*")) return true;
35
55
  return hasPermission(
36
56
  userAppRole.value,
@@ -42,6 +62,7 @@ export function useEquipmentManagementPermission() {
42
62
 
43
63
  const canDeleteEquipment = computed(() => {
44
64
  if (!userAppRole.value) return false;
65
+ if (moduleDenied("supply-mgmt")) return false;
45
66
  if (userAppRole.value.permissions.includes("*")) return true;
46
67
  return hasPermission(
47
68
  userAppRole.value,
@@ -53,6 +74,7 @@ export function useEquipmentManagementPermission() {
53
74
 
54
75
  const canAddStock = computed(() => {
55
76
  if (!userAppRole.value) return false;
77
+ if (moduleDenied("supply-mgmt")) return false;
56
78
  if (userAppRole.value.permissions.includes("*")) return true;
57
79
  return hasPermission(
58
80
  userAppRole.value,
@@ -64,6 +86,7 @@ export function useEquipmentManagementPermission() {
64
86
 
65
87
  const canViewStock = computed(() => {
66
88
  if (!userAppRole.value) return false;
89
+ if (moduleDenied("supply-mgmt")) return false;
67
90
  if (userAppRole.value.permissions.includes("*")) return true;
68
91
  return hasPermission(
69
92
  userAppRole.value,
@@ -75,6 +98,7 @@ export function useEquipmentManagementPermission() {
75
98
 
76
99
  const canRequestItem = computed(() => {
77
100
  if (!userAppRole.value) return false;
101
+ if (moduleDenied("supply-mgmt")) return false;
78
102
  if (userAppRole.value.permissions.includes("*")) return true;
79
103
  return hasPermission(
80
104
  userAppRole.value,
@@ -1,10 +1,29 @@
1
+ import { permissionsDenied } from "../utils/module-routes";
2
+
1
3
  export default function useScheduleTaskPermission() {
2
4
  const { hasPermission } = usePermission();
3
5
  const { permissions } = useCleaningPermission();
4
- const { userAppRole } = useLocalSetup();
6
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
7
+
8
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
9
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
10
+ // because a wildcard role is exactly the role a module list exists to narrow --
11
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
12
+ // would have missed every wildcard role, which is why the check is per gate.
13
+ //
14
+ // Inert today: no client has an enforced list, so the list is `[]` for
15
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
16
+ // nothing -- it never reads as "hide everything".
17
+ //
18
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
19
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
20
+ // must mean "nothing denied", not a TypeError inside every gate.
21
+ const moduleDenied = (...modules: string[]) =>
22
+ permissionsDenied(modules, userAppModulesDenied?.value);
5
23
 
6
24
  const canViewScheduleTasks = computed(() => {
7
25
  if (!userAppRole.value) return false;
26
+ if (moduleDenied("schedule-task-mgmt")) return false;
8
27
  if (userAppRole.value.permissions.includes("*")) return true;
9
28
  return hasPermission(
10
29
  userAppRole.value,
@@ -16,6 +35,7 @@ export default function useScheduleTaskPermission() {
16
35
 
17
36
  const canCreateScheduleTask = computed(() => {
18
37
  if (!userAppRole.value) return false;
38
+ if (moduleDenied("schedule-task-mgmt")) return false;
19
39
  if (userAppRole.value.permissions.includes("*")) return true;
20
40
  return hasPermission(
21
41
  userAppRole.value,
@@ -27,6 +47,7 @@ export default function useScheduleTaskPermission() {
27
47
 
28
48
  const canUpdateScheduleTask = computed(() => {
29
49
  if (!userAppRole.value) return false;
50
+ if (moduleDenied("schedule-task-mgmt")) return false;
30
51
  if (userAppRole.value.permissions.includes("*")) return true;
31
52
  return hasPermission(
32
53
  userAppRole.value,
@@ -38,6 +59,7 @@ export default function useScheduleTaskPermission() {
38
59
 
39
60
  const canDeleteScheduleTask = computed(() => {
40
61
  if (!userAppRole.value) return false;
62
+ if (moduleDenied("schedule-task-mgmt")) return false;
41
63
  if (userAppRole.value.permissions.includes("*")) return true;
42
64
  return hasPermission(
43
65
  userAppRole.value,
@@ -49,6 +71,7 @@ export default function useScheduleTaskPermission() {
49
71
 
50
72
  const canViewScheduleTaskDetails = computed(() => {
51
73
  if (!userAppRole.value) return false;
74
+ if (moduleDenied("schedule-task-mgmt")) return false;
52
75
  if (userAppRole.value.permissions.includes("*")) return true;
53
76
  return hasPermission(
54
77
  userAppRole.value,
@@ -1,4 +1,5 @@
1
1
  import { useCommonPermissions } from "./useCommonPermission";
2
+ import { permissionsDenied } from "../utils/module-routes";
2
3
 
3
4
  export function useServiceProviderPermission() {
4
5
  const { hasPermission } = usePermission();
@@ -26,24 +27,43 @@ export function useServiceProviderPermission() {
26
27
  },
27
28
  };
28
29
 
29
- const { userAppRole } = useLocalSetup();
30
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
31
+
32
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
33
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
34
+ // because a wildcard role is exactly the role a module list exists to narrow --
35
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
36
+ // would have missed every wildcard role, which is why the check is per gate.
37
+ //
38
+ // Inert today: no client has an enforced list, so the list is `[]` for
39
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
40
+ // nothing -- it never reads as "hide everything".
41
+ //
42
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
43
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
44
+ // must mean "nothing denied", not a TypeError inside every gate.
45
+ const moduleDenied = (...modules: string[]) =>
46
+ permissionsDenied(modules, userAppModulesDenied?.value);
30
47
 
31
48
  // Every gate fails closed while the role is still resolving: `userAppRole` is
32
49
  // null on the first tick and a null role must never read as "allowed".
33
50
  const canAddServiceProvider = computed(() => {
34
51
  if (!userAppRole.value) return false;
52
+ if (moduleDenied("service-provider-mgmt", "service-provider")) return false;
35
53
  if (userAppRole.value.permissions.includes("*")) return true;
36
54
  return hasPermission(userAppRole.value, permissions, "service-provider-mgmt", "add-service-provider");
37
55
  });
38
56
 
39
57
  const canInviteServiceProvider = computed(() => {
40
58
  if (!userAppRole.value) return false;
59
+ if (moduleDenied("service-provider-mgmt", "service-provider")) return false;
41
60
  if (userAppRole.value.permissions.includes("*")) return true;
42
61
  return hasPermission(userAppRole.value, permissions, "service-provider-mgmt", "invite-service-provider");
43
62
  });
44
63
 
45
64
  const canViewServiceProviders = computed(() => {
46
65
  if (!userAppRole.value) return false;
66
+ if (moduleDenied("service-provider-mgmt", "service-provider")) return false;
47
67
  if (userAppRole.value.permissions.includes("*")) return true;
48
68
  return (
49
69
  hasPermission(userAppRole.value, permissions, "service-provider-mgmt", "see-all-service-providers") ||
@@ -48,7 +48,22 @@ export default function () {
48
48
  }
49
49
  );
50
50
  }
51
- async function addCamera(camera: TSiteCamera & TCameraByRecorder) {
51
+ async function addCamera(
52
+ camera: TSiteCamera &
53
+ TCameraByRecorder & {
54
+ /**
55
+ * Clear the new ANPR camera's allowed list and blocklist on the device
56
+ * before the site's vehicles are added. Absent means keep them.
57
+ */
58
+ clearCameraLists?: boolean;
59
+ /**
60
+ * The add-camera screen has already cleared and filled the camera
61
+ * itself (`clearNewCamera` / `addNewCameraPlate`), so saving must not
62
+ * touch the device again.
63
+ */
64
+ skipPlateSync?: boolean;
65
+ }
66
+ ) {
52
67
  return await useNuxtApp().$api<Record<string, any>>(`/api/site-cameras`, {
53
68
  method: "POST",
54
69
  body: camera,
@@ -85,6 +100,83 @@ export default function () {
85
100
  * Try an address before saving it. Read-only, and it runs on the server —
86
101
  * the browser never touches a recorder and never sees a credential.
87
102
  */
103
+ /* ---- filling a NEW ANPR camera, before it is saved ---- */
104
+
105
+ type TNewCameraDevice = {
106
+ host: string;
107
+ username: string;
108
+ password: string;
109
+ name?: string;
110
+ direction: string;
111
+ };
112
+
113
+ /** The plates a new camera of this type receives, blocked ones first. */
114
+ async function getNewCameraPlates(
115
+ siteId: string,
116
+ query: { host: string; direction: string }
117
+ ) {
118
+ return await useNuxtApp().$api<{ items: Array<Record<string, any>> }>(
119
+ `/api/site-cameras/site/${siteId}/new-camera/plates`,
120
+ { method: "GET", query }
121
+ );
122
+ }
123
+
124
+ /** Empty the new camera's allowed list and blocklist on the device. */
125
+ async function clearNewCamera(siteId: string, device: TNewCameraDevice) {
126
+ return await useNuxtApp().$api<Record<string, any>>(
127
+ `/api/site-cameras/site/${siteId}/new-camera/clear`,
128
+ { method: "POST", body: device }
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Write ONE vehicle's plate to the new camera. Answers `{ ok: false, reason,
134
+ * kind }` when the camera refuses it.
135
+ */
136
+ async function addNewCameraPlate(
137
+ siteId: string,
138
+ device: TNewCameraDevice,
139
+ plate: { vehicle: string; list: "allowed" | "blocked"; onlyIfMissing?: boolean }
140
+ ) {
141
+ return await useNuxtApp().$api<{ ok: boolean; reason?: string; kind?: string }>(
142
+ `/api/site-cameras/site/${siteId}/new-camera/plate`,
143
+ { method: "POST", body: { ...device, ...plate } }
144
+ );
145
+ }
146
+
147
+ /* ---- "Sync vehicles": filling a camera that is already saved ---- */
148
+
149
+ /** The plates this saved camera receives, blocked ones first. */
150
+ async function getCameraPlates(cameraId: string) {
151
+ return await useNuxtApp().$api<{ items: Array<Record<string, any>> }>(
152
+ `/api/site-cameras/id/${cameraId}/plates`,
153
+ { method: "GET" }
154
+ );
155
+ }
156
+
157
+ /** Empty the saved camera's allowed list and blocklist on the device. */
158
+ async function clearCamera(cameraId: string) {
159
+ return await useNuxtApp().$api<Record<string, any>>(
160
+ `/api/site-cameras/id/${cameraId}/clear`,
161
+ { method: "POST" }
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Write ONE vehicle's plate to the saved camera. The server uses the
167
+ * camera's stored login. Answers `{ ok: false, reason, kind }` when the
168
+ * camera refuses it.
169
+ */
170
+ async function addCameraPlate(
171
+ cameraId: string,
172
+ plate: { vehicle: string; list: "allowed" | "blocked"; onlyIfMissing?: boolean }
173
+ ) {
174
+ return await useNuxtApp().$api<{ ok: boolean; reason?: string; kind?: string }>(
175
+ `/api/site-cameras/id/${cameraId}/plate`,
176
+ { method: "POST", body: plate }
177
+ );
178
+ }
179
+
88
180
  async function testSiteCamera(
89
181
  siteId: string,
90
182
  payload: { host?: string } & TCameraByRecorder
@@ -112,7 +204,21 @@ export default function () {
112
204
  | "status"
113
205
  >
114
206
  > &
115
- TCameraByRecorder
207
+ TCameraByRecorder & {
208
+ /**
209
+ * The person confirmed that this type change clears the camera's
210
+ * plate lists on the camera itself (to Exit: allowed list and
211
+ * blocklist; Entry / Both / Residents to Visitors: allowed list).
212
+ * Without it the API refuses that change.
213
+ */
214
+ confirmClearCameraLists?: boolean;
215
+ /**
216
+ * Save a type change that would fill the camera (to Entry / Both /
217
+ * Residents, or Exit to Visitors) without filling it: the vehicles
218
+ * are added afterwards with "Sync vehicles", or not now.
219
+ */
220
+ skipPlateSync?: boolean;
221
+ }
116
222
  ) {
117
223
  return await useNuxtApp().$api<Record<string, any>>(
118
224
  `/api/site-cameras/id/${id}`,
@@ -303,6 +409,12 @@ export default function () {
303
409
  updateSite,
304
410
  addCamera,
305
411
  testSiteCamera,
412
+ getNewCameraPlates,
413
+ clearNewCamera,
414
+ addNewCameraPlate,
415
+ getCameraPlates,
416
+ clearCamera,
417
+ addCameraPlate,
306
418
  getAllSiteCameras,
307
419
  bulkImportSiteCameras,
308
420
  getSiteWall,
@@ -1,41 +1,65 @@
1
+ import { permissionsDenied } from "../utils/module-routes";
2
+
1
3
  export function useUnitPermission() {
2
4
  const { hasPermission } = usePermission();
3
5
  const { permissions } = useCleaningPermission();
4
6
 
5
- const { userAppRole } = useLocalSetup();
7
+ const { userAppRole, userAppModulesDenied } = useLocalSetup();
8
+
9
+ // THE CLIENT'S MODULE LIST (RP-5). A gate whose every module Seven365 did not
10
+ // give this client is closed. It is asked BEFORE the `*` short-circuit below,
11
+ // because a wildcard role is exactly the role a module list exists to narrow --
12
+ // the order `DashboardMain` already uses. Wrapping `hasPermission` instead
13
+ // would have missed every wildcard role, which is why the check is per gate.
14
+ //
15
+ // Inert today: no client has an enforced list, so the list is `[]` for
16
+ // everyone and this closes nothing. An absent, empty or unreadable list denies
17
+ // nothing -- it never reads as "hide everything".
18
+ //
19
+ // `?.` on purpose: an app pinned to an older layer-common, or any caller that
20
+ // stubs `useLocalSetup` without this field, hands back `undefined` here. That
21
+ // must mean "nothing denied", not a TypeError inside every gate.
22
+ const moduleDenied = (...modules: string[]) =>
23
+ permissionsDenied(modules, userAppModulesDenied?.value);
6
24
 
7
25
  const canViewUnits = computed(() => {
8
26
  if (!userAppRole.value) return false;
27
+ if (moduleDenied("unit-mgmt")) return false;
9
28
  if (userAppRole.value.permissions.includes("*")) return true;
10
29
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "see-all-units");
11
30
  });
12
31
 
13
32
  const canCreateUnit = computed(() => {
14
33
  if (!userAppRole.value) return false;
34
+ if (moduleDenied("unit-mgmt")) return false;
15
35
  if (userAppRole.value.permissions.includes("*")) return true;
16
36
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "add-unit");
17
37
  });
18
38
 
19
39
  const canUpdateUnit = computed(() => {
20
40
  if (!userAppRole.value) return false;
41
+ if (moduleDenied("unit-mgmt")) return false;
21
42
  if (userAppRole.value.permissions.includes("*")) return true;
22
43
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "update-unit");
23
44
  });
24
45
 
25
46
  const canViewUnitDetails = computed(() => {
26
47
  if (!userAppRole.value) return false;
48
+ if (moduleDenied("unit-mgmt")) return false;
27
49
  if (userAppRole.value.permissions.includes("*")) return true;
28
50
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "see-unit-details");
29
51
  });
30
52
 
31
53
  const canDeleteUnit = computed(() => {
32
54
  if (!userAppRole.value) return false;
55
+ if (moduleDenied("unit-mgmt")) return false;
33
56
  if (userAppRole.value.permissions.includes("*")) return true;
34
57
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "delete-unit");
35
58
  });
36
59
 
37
60
  const canImportUnit = computed(() => {
38
61
  if (!userAppRole.value) return false;
62
+ if (moduleDenied("unit-mgmt")) return false;
39
63
  if (userAppRole.value.permissions.includes("*")) return true;
40
64
  return hasPermission(userAppRole.value, permissions, "unit-mgmt", "import-units");
41
65
  });