@fonderie/workspaces 6.0.1 → 6.0.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/dist/index.cjs CHANGED
@@ -1396,6 +1396,25 @@ function invitationController(store, ttl, bus) {
1396
1396
  return (0, import_core6.setApiResponse)(import_core6.HTTP.SERVER_ERROR, "SERVER_ERROR", "Default role not found");
1397
1397
  }
1398
1398
  }
1399
+ const explicitRoleIds = [...new Set(
1400
+ entries.map((e) => e["roleId"]).filter((r) => typeof r === "string")
1401
+ )];
1402
+ if (explicitRoleIds.length > 0) {
1403
+ const rows = await store.query(
1404
+ `SELECT id FROM fonderie_roles
1405
+ WHERE id = ANY($1) AND workspace_id = $2 AND is_system = false`,
1406
+ [explicitRoleIds, ctx.workspace.id]
1407
+ );
1408
+ const assignable = new Set(rows.map((r) => r.id));
1409
+ const bad = explicitRoleIds.find((id) => !assignable.has(id));
1410
+ if (bad) {
1411
+ return (0, import_core6.setApiResponse)(
1412
+ import_core6.HTTP.UNPROCESSABLE,
1413
+ "INVALID_ROLE",
1414
+ "Role is not assignable in this workspace."
1415
+ );
1416
+ }
1417
+ }
1399
1418
  const results = await Promise.all(
1400
1419
  entries.map(async (entry) => {
1401
1420
  const email2 = entry["email"];