@7365admin1/core 3.127.2-staging.424 → 3.127.2-staging.425

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.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ 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.
package/dist/index.js CHANGED
@@ -6639,10 +6639,25 @@ function boundToOwnerGrant(ceiling, next, previous) {
6639
6639
  return { permissions: [...ceiling], refused: [] };
6640
6640
  const held = new Set(previous ?? []);
6641
6641
  const refused = list.filter(
6642
- (p) => !held.has(p) && !ceiling.includes(p) && !ALWAYS_ALLOWED.includes(p.split(":")[0])
6642
+ (p) => !held.has(p) && !ceilingCovers(ceiling, p) && !ALWAYS_ALLOWED.includes(p.split(":")[0])
6643
6643
  );
6644
6644
  return { permissions: list, refused };
6645
6645
  }
6646
+ var PERMISSION_COVERS = Object.freeze({
6647
+ "inventory:manage-inventory": ["inventory:*"],
6648
+ "inventory:request-stock": ["inventory:record-usage"],
6649
+ "inventory:view-inventory": ["inventory:view-reports"],
6650
+ "inventory:approve-requests": ["inventory:view-reports"]
6651
+ });
6652
+ function ceilingCovers(ceiling, permission) {
6653
+ if (ceiling.includes(permission))
6654
+ return true;
6655
+ const moduleWide = `${permission.split(":")[0]}:*`;
6656
+ return ceiling.some((granted) => {
6657
+ const covers = PERMISSION_COVERS[granted];
6658
+ return !!covers && (covers.includes(permission) || covers.includes(moduleWide));
6659
+ });
6660
+ }
6646
6661
 
6647
6662
  // src/models/site.model.ts
6648
6663
  var import_node_server_utils23 = require("@7365admin1/node-server-utils");
@@ -6694,6 +6709,9 @@ function permissionsOutsideModules2(effective, next, previous) {
6694
6709
  if (!Array.isArray(next) || !next.length || next.includes("*"))
6695
6710
  return [];
6696
6711
  const held = new Set(Array.isArray(previous) ? previous : []);
6712
+ const heldModules = new Set(
6713
+ [...held].map((p) => typeof p === "string" ? p.split(":")[0]?.trim() : "").filter(Boolean)
6714
+ );
6697
6715
  const allowed = normaliseModules(effective);
6698
6716
  const refused = [];
6699
6717
  for (const permission of next) {
@@ -6702,6 +6720,8 @@ function permissionsOutsideModules2(effective, next, previous) {
6702
6720
  if (held.has(permission))
6703
6721
  continue;
6704
6722
  const resource = permission.split(":")[0]?.trim();
6723
+ if (resource && heldModules.has(resource))
6724
+ continue;
6705
6725
  if (!resource)
6706
6726
  continue;
6707
6727
  if (!orgAllowsModule(allowed, resource))
@@ -6713,8 +6733,9 @@ function requireWithinModules(effective, next, previous) {
6713
6733
  const refused = permissionsOutsideModules2(effective, next, previous);
6714
6734
  if (!refused.length)
6715
6735
  return;
6716
- throw new import_node_server_utils22.UnauthorizedError(
6717
- "This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first."
6736
+ throw new import_node_server_utils22.AppError(
6737
+ "This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first.",
6738
+ 403
6718
6739
  );
6719
6740
  }
6720
6741
 
@@ -28196,8 +28217,9 @@ function requireNoPlatformGrant(role, next) {
28196
28217
  const added = platformPermissionsAdded(next, role?.permissions);
28197
28218
  if (added.length === 0)
28198
28219
  return;
28199
- throw new import_node_server_utils69.UnauthorizedError(
28200
- "These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", ")
28220
+ throw new import_node_server_utils69.AppError(
28221
+ "These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", "),
28222
+ 403
28201
28223
  );
28202
28224
  }
28203
28225
  function permissionsMeanEverything(permissions) {
@@ -28210,15 +28232,17 @@ function refuseSharedClientTemplate(role, next) {
28210
28232
  return true;
28211
28233
  if (Array.isArray(next) && restorableFromHistory(role, next))
28212
28234
  return true;
28213
- throw new import_node_server_utils69.UnauthorizedError(
28214
- "This role is shared by every client that was invited with it and cannot be changed here."
28235
+ throw new import_node_server_utils69.AppError(
28236
+ "This role is shared by every client that was invited with it and cannot be changed here.",
28237
+ 403
28215
28238
  );
28216
28239
  }
28217
28240
  function refuseNewSharedClientTemplate(role) {
28218
28241
  if (roleScope(role) !== "client-template")
28219
28242
  return;
28220
- throw new import_node_server_utils69.UnauthorizedError(
28221
- "A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to."
28243
+ throw new import_node_server_utils69.AppError(
28244
+ "A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to.",
28245
+ 403
28222
28246
  );
28223
28247
  }
28224
28248
  function samePermissionSet(a, b) {
@@ -28413,8 +28437,9 @@ async function boundRoleToOwnerGrant(req, role, next, previous) {
28413
28437
  return list;
28414
28438
  const { permissions, refused } = boundToOwnerGrant(ceiling, list, previous);
28415
28439
  if (refused.length) {
28416
- throw new import_node_server_utils71.UnauthorizedError(
28417
- "Seven365 has not given this organisation " + refused.join(", ") + "."
28440
+ throw new import_node_server_utils71.AppError(
28441
+ "Seven365 has not given this organisation " + refused.join(", ") + ".",
28442
+ 403
28418
28443
  );
28419
28444
  }
28420
28445
  return permissions;