@7365admin1/core 3.99.1-staging.378 → 3.99.1-staging.379

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": minor
3
+ ---
4
+
5
+ Invitations that name an organisation now refuse a role that is not one of that organisation's own active roles for the invited application and site: org-less template roles, deleted roles, another application's roles, and roles pinned to a different site are refused with a 400. `requireInviteReach` takes the invited site.
package/dist/index.js CHANGED
@@ -13447,7 +13447,8 @@ var MRole = class {
13447
13447
  };
13448
13448
 
13449
13449
  // src/utils/invite-role-scope.util.ts
13450
- function roleInvitable(role, inviteOrg, apps) {
13450
+ var ORG_WIDE_ROLE_TYPE = "organization";
13451
+ function roleInvitable(role, inviteOrg, apps, inviteSite) {
13451
13452
  if (!role)
13452
13453
  return null;
13453
13454
  if (role.type === PLATFORM_STAFF_ROLE_TYPE) {
@@ -13461,6 +13462,23 @@ function roleInvitable(role, inviteOrg, apps) {
13461
13462
  if (roleOrg && org && roleOrg !== org) {
13462
13463
  return "That role belongs to a different organisation.";
13463
13464
  }
13465
+ if (!org)
13466
+ return null;
13467
+ if (!roleOrg) {
13468
+ return "That role is a shared template, not one of this organisation's roles.";
13469
+ }
13470
+ if (role.status && role.status !== "active") {
13471
+ return "That role has been deleted.";
13472
+ }
13473
+ const named = (apps ?? []).filter((app) => !!app);
13474
+ if (named.length && role.type && // a legacy role with no type has nothing to disagree with
13475
+ role.type !== ORG_WIDE_ROLE_TYPE && !named.some((app) => sameAppType(app, role.type))) {
13476
+ return "That role belongs to a different application.";
13477
+ }
13478
+ const roleSite = (role.site ?? "").toString();
13479
+ if (roleSite && roleSite !== (inviteSite?.toString() ?? "")) {
13480
+ return "That role belongs to a different site.";
13481
+ }
13464
13482
  return null;
13465
13483
  }
13466
13484
 
@@ -13554,7 +13572,7 @@ async function canReadOrgRecord(req, orgId) {
13554
13572
  })
13555
13573
  );
13556
13574
  }
13557
- async function requireRoleInvitable(role, org, apps) {
13575
+ async function requireRoleInvitable(role, org, apps, site) {
13558
13576
  const roleId = role?.toString() ?? "";
13559
13577
  if (!roleId || !import_mongodb38.ObjectId.isValid(roleId))
13560
13578
  return;
@@ -13563,20 +13581,20 @@ async function requireRoleInvitable(role, org, apps) {
13563
13581
  return;
13564
13582
  const stored = await db2.collection("roles").findOne(
13565
13583
  { _id: new import_mongodb38.ObjectId(roleId) },
13566
- { projection: { org: 1, type: 1 } }
13584
+ { projection: { org: 1, type: 1, site: 1, status: 1 } }
13567
13585
  );
13568
- const refusal = roleInvitable(stored, org, apps);
13586
+ const refusal = roleInvitable(stored, org, apps, site);
13569
13587
  if (refusal)
13570
13588
  throw new import_node_server_utils42.BadRequestError(refusal);
13571
13589
  }
13572
- async function requireInviteReach(req, org, app, role) {
13590
+ async function requireInviteReach(req, org, app, role, site) {
13573
13591
  const apps = Array.isArray(app) ? app : [app];
13574
13592
  if (apps.some((a) => a === PLATFORM_STAFF_MEMBER_TYPE)) {
13575
13593
  await requirePlatformStaff(req);
13576
13594
  }
13577
13595
  if (org)
13578
13596
  await requireOrgReach(req, org);
13579
- await requireRoleInvitable(role, org, apps);
13597
+ await requireRoleInvitable(role, org, apps, site);
13580
13598
  }
13581
13599
  async function requireUserFieldWrite(req, userId, field, grant, value) {
13582
13600
  if (field && SELF_EDITABLE_USER_FIELDS.includes(field)) {
@@ -27387,7 +27405,7 @@ function useVerificationController() {
27387
27405
  const siteId = req.body.siteId ?? "";
27388
27406
  const siteName = req.body.siteName ?? "";
27389
27407
  try {
27390
- await requireInviteReach(req, org, app, role);
27408
+ await requireInviteReach(req, org, app, role, siteId);
27391
27409
  await _createUserInvite({
27392
27410
  email,
27393
27411
  metadata: {
@@ -27488,7 +27506,7 @@ function useVerificationController() {
27488
27506
  }
27489
27507
  clientModules.residentAppModules = residentAppModules;
27490
27508
  }
27491
- await requireInviteReach(req, org, app, role);
27509
+ await requireInviteReach(req, org, app, role, siteId);
27492
27510
  const verificationIds = await _createSimpleUserInvite({
27493
27511
  email,
27494
27512
  metadata: {
@@ -27553,7 +27571,7 @@ function useVerificationController() {
27553
27571
  const siteId = req.body.siteId ?? "";
27554
27572
  const siteName = req.body.siteName ?? "";
27555
27573
  try {
27556
- await requireInviteReach(req, org, app, role);
27574
+ await requireInviteReach(req, org, app, role, siteId);
27557
27575
  await _createSimpleMemberInvite({
27558
27576
  email,
27559
27577
  metadata: {
@@ -27678,7 +27696,7 @@ function useVerificationController() {
27678
27696
  const siteId = req.body.siteId ?? "";
27679
27697
  const siteName = req.body.siteName ?? "";
27680
27698
  try {
27681
- await requireInviteReach(req, orgId, app, role);
27699
+ await requireInviteReach(req, orgId, app, role, siteId);
27682
27700
  await _createSimpleServiceProviderInvite({
27683
27701
  email,
27684
27702
  app,
@@ -95258,7 +95276,7 @@ function useVerificationControllerV2() {
95258
95276
  }
95259
95277
  const { email, app, role, name, org, siteId, siteName } = value;
95260
95278
  try {
95261
- await requireInviteReach(req, org, app, role);
95279
+ await requireInviteReach(req, org, app, role, siteId);
95262
95280
  await _createUserInvite({
95263
95281
  email,
95264
95282
  metadata: {
@@ -95330,7 +95348,7 @@ function useVerificationControllerV2() {
95330
95348
  }
95331
95349
  try {
95332
95350
  const { email, app, role, name, org, siteId, siteName } = value;
95333
- await requireInviteReach(req, org, app, role);
95351
+ await requireInviteReach(req, org, app, role, siteId);
95334
95352
  await _createOrganizationInvite({
95335
95353
  email,
95336
95354
  metadata: {