@fonderie/workspaces 6.0.1 → 6.0.3
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 +33 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1255,6 +1255,18 @@ async function cancelInvitation(invitationId, workspaceId, store) {
|
|
|
1255
1255
|
[invitationId, workspaceId]
|
|
1256
1256
|
);
|
|
1257
1257
|
}
|
|
1258
|
+
async function assertRoleAssignable(roleId, workspaceId, store) {
|
|
1259
|
+
const rows = await store.query(
|
|
1260
|
+
`SELECT id FROM fonderie_roles
|
|
1261
|
+
WHERE id = $1
|
|
1262
|
+
AND (
|
|
1263
|
+
(workspace_id = $2 AND is_system = false)
|
|
1264
|
+
OR (is_system = true AND name = 'GUEST')
|
|
1265
|
+
)`,
|
|
1266
|
+
[roleId, workspaceId]
|
|
1267
|
+
);
|
|
1268
|
+
if (rows.length === 0) throw new Error("Invitation role is no longer assignable");
|
|
1269
|
+
}
|
|
1258
1270
|
async function acceptInvitationByPin(opts, store) {
|
|
1259
1271
|
const [inv] = await store.query(
|
|
1260
1272
|
`SELECT id, workspace_id AS "workspaceId", role_id AS "roleId", expires_at AS "expiresAt"
|
|
@@ -1264,6 +1276,7 @@ async function acceptInvitationByPin(opts, store) {
|
|
|
1264
1276
|
);
|
|
1265
1277
|
if (!inv) throw new Error("Invalid PIN");
|
|
1266
1278
|
if (/* @__PURE__ */ new Date() > new Date(inv.expiresAt)) throw new Error("Invitation expired");
|
|
1279
|
+
await assertRoleAssignable(inv.roleId, inv.workspaceId, store);
|
|
1267
1280
|
await store.transaction(async (tx) => {
|
|
1268
1281
|
await Promise.all([
|
|
1269
1282
|
tx.query(
|
|
@@ -1289,6 +1302,7 @@ async function acceptInvitationByToken(token, userId, store) {
|
|
|
1289
1302
|
);
|
|
1290
1303
|
if (!inv) throw new Error("Invalid token");
|
|
1291
1304
|
if (/* @__PURE__ */ new Date() > new Date(inv.expiresAt)) throw new Error("Invitation expired");
|
|
1305
|
+
await assertRoleAssignable(inv.roleId, inv.workspaceId, store);
|
|
1292
1306
|
await store.transaction(async (tx) => {
|
|
1293
1307
|
await Promise.all([
|
|
1294
1308
|
tx.query(
|
|
@@ -1396,6 +1410,25 @@ function invitationController(store, ttl, bus) {
|
|
|
1396
1410
|
return (0, import_core6.setApiResponse)(import_core6.HTTP.SERVER_ERROR, "SERVER_ERROR", "Default role not found");
|
|
1397
1411
|
}
|
|
1398
1412
|
}
|
|
1413
|
+
const explicitRoleIds = [...new Set(
|
|
1414
|
+
entries.map((e) => e["roleId"]).filter((r) => typeof r === "string")
|
|
1415
|
+
)];
|
|
1416
|
+
if (explicitRoleIds.length > 0) {
|
|
1417
|
+
const rows = await store.query(
|
|
1418
|
+
`SELECT id FROM fonderie_roles
|
|
1419
|
+
WHERE id = ANY($1) AND workspace_id = $2 AND is_system = false`,
|
|
1420
|
+
[explicitRoleIds, ctx.workspace.id]
|
|
1421
|
+
);
|
|
1422
|
+
const assignable = new Set(rows.map((r) => r.id));
|
|
1423
|
+
const bad = explicitRoleIds.find((id) => !assignable.has(id));
|
|
1424
|
+
if (bad) {
|
|
1425
|
+
return (0, import_core6.setApiResponse)(
|
|
1426
|
+
import_core6.HTTP.UNPROCESSABLE,
|
|
1427
|
+
"INVALID_ROLE",
|
|
1428
|
+
"Role is not assignable in this workspace."
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1399
1432
|
const results = await Promise.all(
|
|
1400
1433
|
entries.map(async (entry) => {
|
|
1401
1434
|
const email2 = entry["email"];
|