@easy-cms/plugin-multi-tenant 1.27.0 → 1.29.0

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -6
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -55,14 +55,21 @@ import {
55
55
  isStaff,
56
56
  ValidationError as ValidationError2
57
57
  } from "@easy-cms/core";
58
- import { checkRenamedOptions, MEDIA, MEDIA_FOLDERS } from "@easy-cms/core/internal";
58
+ import {
59
+ checkRenamedOptions,
60
+ isPolymorphic,
61
+ MEDIA,
62
+ MEDIA_FOLDERS,
63
+ polymorphicValue,
64
+ relationTargets
65
+ } from "@easy-cms/core/internal";
59
66
 
60
67
  // src/info.ts
61
68
  var INFO = {
62
69
  name: "@easy-cms/plugin-multi-tenant",
63
70
  // The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
64
71
  apiVersion: 1,
65
- ...true ? { version: "1.27.0" } : {}
72
+ ...true ? { version: "1.29.0" } : {}
66
73
  };
67
74
 
68
75
  // src/members.ts
@@ -327,14 +334,14 @@ function multiTenantPlugin(options) {
327
334
  ...field,
328
335
  blocks: field.blocks.map((b) => ({ ...b, fields: withTenantFilters(b.fields) }))
329
336
  };
330
- const target = field.type === "relationship" ? field.to : field.type === "upload" ? MEDIA : null;
331
- if (field.type !== "relationship" && field.type !== "upload" || !target || !scoped.has(target))
337
+ if (field.type !== "relationship" && field.type !== "upload" || !relationTargets(field).some((target) => scoped.has(target)))
332
338
  return field;
333
339
  const own = field.filterOptions;
334
340
  return {
335
341
  ...field,
336
342
  filterOptions: async (args) => {
337
343
  const base = own ? await own(args) : true;
344
+ if (!scoped.has(args.relationTo)) return base;
338
345
  const { tenant } = tenantOf(args.context);
339
346
  if (tenant === null) return base;
340
347
  const mine = { [TENANT_FIELD]: { equals: tenant } };
@@ -364,9 +371,12 @@ function multiTenantPlugin(options) {
364
371
  const { tenant } = tenantOf(context);
365
372
  if (tenant !== null) return { ...data, [TENANT_FIELD]: tenant };
366
373
  for (const field of fields) {
367
- const target = field.type === "relationship" ? field.to : field.type === "upload" ? MEDIA : null;
374
+ if (field.type !== "relationship" && field.type !== "upload") continue;
375
+ const first = [data[field.name]].flat()[0];
376
+ const pair = isPolymorphic(field) ? polymorphicValue(first) : void 0;
377
+ const target = pair ? pair.relationTo : relationTargets(field)[0];
368
378
  if (!target || !scoped.has(target) || field.name === TENANT_FIELD) continue;
369
- const value = [data[field.name]].flat()[0];
379
+ const value = pair ? pair.value : first;
370
380
  const id = value && typeof value === "object" ? value.id : value;
371
381
  if (id === null || id === void 0) continue;
372
382
  if (!cms.config.collections.some((c) => c.slug === target)) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-multi-tenant",
3
- "version": "1.27.0",
3
+ "version": "1.29.0",
4
4
  "description": "Multi-tenant Easy CMS: several sites or clients in one CMS, each with its own content, members and roles",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,14 +17,14 @@
17
17
  "dist"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@easy-cms/core": "^1.27.0"
20
+ "@easy-cms/core": "^1.29.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@easy-cms/core": "^1.27.0",
24
- "@easy-cms/db-sqlite": "^1.27.0",
25
- "@easy-cms/plugin-form-builder": "^1.27.0",
26
- "@easy-cms/plugin-nested-docs": "^1.27.0",
27
- "@easy-cms/plugin-redirects": "^1.27.0"
23
+ "@easy-cms/core": "^1.29.0",
24
+ "@easy-cms/db-sqlite": "^1.29.0",
25
+ "@easy-cms/plugin-form-builder": "^1.29.0",
26
+ "@easy-cms/plugin-nested-docs": "^1.29.0",
27
+ "@easy-cms/plugin-redirects": "^1.29.0"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.12"