@7365admin1/core 3.129.1 → 3.129.2
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/CHANGELOG.md +6 -0
- package/dist/index.js +36 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -262
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/role-inventory-presets.e2e.test.mjs +175 -0
- package/test/e2e/role-template-restore.e2e.test.mjs +7 -7
- package/test/org-modules.test.mjs +21 -0
- package/test/site-modules.test.mjs +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @iservice365/core
|
|
2
2
|
|
|
3
|
+
## 3.129.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5453144: Roles: an owner grant chosen before the inventory permission split still covers the keys it granted (full inventory access covers every inventory key, request-stock covers record-usage, view/approve cover view-reports), so the inventory presets can be saved. Role-save rule refusals (module not given, owner grant, console permission, shared template) now answer 403 with their message instead of 401.
|
|
8
|
+
|
|
3
9
|
## 3.129.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -6549,10 +6549,25 @@ function boundToOwnerGrant(ceiling, next, previous) {
|
|
|
6549
6549
|
return { permissions: [...ceiling], refused: [] };
|
|
6550
6550
|
const held = new Set(previous ?? []);
|
|
6551
6551
|
const refused = list.filter(
|
|
6552
|
-
(p) => !held.has(p) && !ceiling
|
|
6552
|
+
(p) => !held.has(p) && !ceilingCovers(ceiling, p) && !ALWAYS_ALLOWED.includes(p.split(":")[0])
|
|
6553
6553
|
);
|
|
6554
6554
|
return { permissions: list, refused };
|
|
6555
6555
|
}
|
|
6556
|
+
var PERMISSION_COVERS = Object.freeze({
|
|
6557
|
+
"inventory:manage-inventory": ["inventory:*"],
|
|
6558
|
+
"inventory:request-stock": ["inventory:record-usage"],
|
|
6559
|
+
"inventory:view-inventory": ["inventory:view-reports"],
|
|
6560
|
+
"inventory:approve-requests": ["inventory:view-reports"]
|
|
6561
|
+
});
|
|
6562
|
+
function ceilingCovers(ceiling, permission) {
|
|
6563
|
+
if (ceiling.includes(permission))
|
|
6564
|
+
return true;
|
|
6565
|
+
const moduleWide = `${permission.split(":")[0]}:*`;
|
|
6566
|
+
return ceiling.some((granted) => {
|
|
6567
|
+
const covers = PERMISSION_COVERS[granted];
|
|
6568
|
+
return !!covers && (covers.includes(permission) || covers.includes(moduleWide));
|
|
6569
|
+
});
|
|
6570
|
+
}
|
|
6556
6571
|
|
|
6557
6572
|
// src/models/site.model.ts
|
|
6558
6573
|
var import_node_server_utils22 = require("@7365admin1/node-server-utils");
|
|
@@ -6604,6 +6619,9 @@ function permissionsOutsideModules2(effective, next, previous) {
|
|
|
6604
6619
|
if (!Array.isArray(next) || !next.length || next.includes("*"))
|
|
6605
6620
|
return [];
|
|
6606
6621
|
const held = new Set(Array.isArray(previous) ? previous : []);
|
|
6622
|
+
const heldModules = new Set(
|
|
6623
|
+
[...held].map((p) => typeof p === "string" ? p.split(":")[0]?.trim() : "").filter(Boolean)
|
|
6624
|
+
);
|
|
6607
6625
|
const allowed = normaliseModules(effective);
|
|
6608
6626
|
const refused = [];
|
|
6609
6627
|
for (const permission of next) {
|
|
@@ -6612,6 +6630,8 @@ function permissionsOutsideModules2(effective, next, previous) {
|
|
|
6612
6630
|
if (held.has(permission))
|
|
6613
6631
|
continue;
|
|
6614
6632
|
const resource = permission.split(":")[0]?.trim();
|
|
6633
|
+
if (resource && heldModules.has(resource))
|
|
6634
|
+
continue;
|
|
6615
6635
|
if (!resource)
|
|
6616
6636
|
continue;
|
|
6617
6637
|
if (!orgAllowsModule(allowed, resource))
|
|
@@ -6623,8 +6643,9 @@ function requireWithinModules(effective, next, previous) {
|
|
|
6623
6643
|
const refused = permissionsOutsideModules2(effective, next, previous);
|
|
6624
6644
|
if (!refused.length)
|
|
6625
6645
|
return;
|
|
6626
|
-
throw new import_node_server_utils21.
|
|
6627
|
-
"This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first."
|
|
6646
|
+
throw new import_node_server_utils21.AppError(
|
|
6647
|
+
"This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first.",
|
|
6648
|
+
403
|
|
6628
6649
|
);
|
|
6629
6650
|
}
|
|
6630
6651
|
|
|
@@ -27748,8 +27769,9 @@ function requireNoPlatformGrant(role, next) {
|
|
|
27748
27769
|
const added = platformPermissionsAdded(next, role?.permissions);
|
|
27749
27770
|
if (added.length === 0)
|
|
27750
27771
|
return;
|
|
27751
|
-
throw new import_node_server_utils68.
|
|
27752
|
-
"These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", ")
|
|
27772
|
+
throw new import_node_server_utils68.AppError(
|
|
27773
|
+
"These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", "),
|
|
27774
|
+
403
|
|
27753
27775
|
);
|
|
27754
27776
|
}
|
|
27755
27777
|
function permissionsMeanEverything(permissions) {
|
|
@@ -27762,15 +27784,17 @@ function refuseSharedClientTemplate(role, next) {
|
|
|
27762
27784
|
return true;
|
|
27763
27785
|
if (Array.isArray(next) && restorableFromHistory(role, next))
|
|
27764
27786
|
return true;
|
|
27765
|
-
throw new import_node_server_utils68.
|
|
27766
|
-
"This role is shared by every client that was invited with it and cannot be changed here."
|
|
27787
|
+
throw new import_node_server_utils68.AppError(
|
|
27788
|
+
"This role is shared by every client that was invited with it and cannot be changed here.",
|
|
27789
|
+
403
|
|
27767
27790
|
);
|
|
27768
27791
|
}
|
|
27769
27792
|
function refuseNewSharedClientTemplate(role) {
|
|
27770
27793
|
if (roleScope(role) !== "client-template")
|
|
27771
27794
|
return;
|
|
27772
|
-
throw new import_node_server_utils68.
|
|
27773
|
-
"A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to."
|
|
27795
|
+
throw new import_node_server_utils68.AppError(
|
|
27796
|
+
"A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to.",
|
|
27797
|
+
403
|
|
27774
27798
|
);
|
|
27775
27799
|
}
|
|
27776
27800
|
function samePermissionSet(a, b) {
|
|
@@ -27965,8 +27989,9 @@ async function boundRoleToOwnerGrant(req, role, next, previous) {
|
|
|
27965
27989
|
return list;
|
|
27966
27990
|
const { permissions, refused } = boundToOwnerGrant(ceiling, list, previous);
|
|
27967
27991
|
if (refused.length) {
|
|
27968
|
-
throw new import_node_server_utils70.
|
|
27969
|
-
"Seven365 has not given this organisation " + refused.join(", ") + "."
|
|
27992
|
+
throw new import_node_server_utils70.AppError(
|
|
27993
|
+
"Seven365 has not given this organisation " + refused.join(", ") + ".",
|
|
27994
|
+
403
|
|
27970
27995
|
);
|
|
27971
27996
|
}
|
|
27972
27997
|
return permissions;
|