@easy-cms/plugin-multi-tenant 0.47.4 → 0.48.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.
package/dist/index.d.ts CHANGED
@@ -42,6 +42,12 @@ interface MultiTenantOptions<S extends string = string, T extends string = strin
42
42
  readonly collections: readonly S[];
43
43
  /** Globals with a value per tenant, e.g. `['site-settings']`. Others are shared. */
44
44
  readonly globals?: readonly string[];
45
+ /**
46
+ * Shared collections and globals (not listed above) that the people of a tenant, its admins
47
+ * included, may change. A change applies to every tenant. Default: none; only users with
48
+ * access to all tenants change shared data.
49
+ */
50
+ readonly editShared?: readonly string[];
45
51
  /** Slug of the tenants collection. Default `tenants`. */
46
52
  readonly tenantsSlug?: T;
47
53
  /**
package/dist/index.js CHANGED
@@ -61,7 +61,7 @@ import {
61
61
  // src/info.ts
62
62
  var INFO = {
63
63
  name: "@easy-cms/plugin-multi-tenant",
64
- ...true ? { version: "0.47.4" } : {}
64
+ ...true ? { version: "0.48.0" } : {}
65
65
  };
66
66
 
67
67
  // src/members.ts
@@ -274,6 +274,8 @@ function multiTenantPlugin(options) {
274
274
  );
275
275
  const superUser = (user, _context) => !!user && user.member !== true && user.scoped !== true && isSuper(user);
276
276
  const everywhere = (user, context) => tenantOf(context).allTenants || superUser(user, context);
277
+ const editShared = new Set(options.editShared ?? []);
278
+ const sharedWrite = (slug, original) => async (args) => args.user?.scoped === true && !editShared.has(slug) ? false : (original ?? isLoggedIn)(args);
277
279
  const tenantFilter = (args, op) => {
278
280
  const { tenant } = tenantOf(args.context);
279
281
  if (op === "create") return tenant !== null || superUser(args.user, args.context);
@@ -516,7 +518,17 @@ function multiTenantPlugin(options) {
516
518
  access: { ...c.access, ...usersAccess(c.access) }
517
519
  });
518
520
  } else if (scoped.has(c.slug)) collections.push(scopeCollection(c, BUILTIN_ACCESS[c.slug]));
519
- else collections.push({ ...c, fields: withTenantFilters(c.fields) });
521
+ else
522
+ collections.push({
523
+ ...c,
524
+ fields: withTenantFilters(c.fields),
525
+ access: {
526
+ ...c.access,
527
+ create: sharedWrite(c.slug, c.access?.create),
528
+ update: sharedWrite(c.slug, c.access?.update),
529
+ delete: sharedWrite(c.slug, c.access?.delete)
530
+ }
531
+ });
520
532
  }
521
533
  if (!hasUsers) collections.push({ slug: "users", fields: [memberships], access: usersAccess() });
522
534
  for (const builtin of [MEDIA, MEDIA_FOLDERS]) {
@@ -534,7 +546,11 @@ function multiTenantPlugin(options) {
534
546
  }
535
547
  const globals = (config.globals ?? []).map((g) => {
536
548
  const filtered = { ...g, fields: withTenantFilters(g.fields) };
537
- if (!perTenant.has(g.slug)) return filtered;
549
+ if (!perTenant.has(g.slug))
550
+ return {
551
+ ...filtered,
552
+ access: { ...g.access, update: sharedWrite(g.slug, g.access?.update) }
553
+ };
538
554
  return {
539
555
  ...filtered,
540
556
  // One value per tenant; none when the request has no tenant.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-multi-tenant",
3
- "version": "0.47.4",
3
+ "version": "0.48.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": "^0.47.4"
20
+ "@easy-cms/core": "^0.48.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@easy-cms/core": "^0.47.4",
24
- "@easy-cms/db-sqlite": "^0.47.4",
25
- "@easy-cms/plugin-form-builder": "^0.47.4",
26
- "@easy-cms/plugin-nested-docs": "^0.47.4",
27
- "@easy-cms/plugin-redirects": "^0.47.4"
23
+ "@easy-cms/core": "^0.48.0",
24
+ "@easy-cms/db-sqlite": "^0.48.0",
25
+ "@easy-cms/plugin-form-builder": "^0.48.0",
26
+ "@easy-cms/plugin-nested-docs": "^0.48.0",
27
+ "@easy-cms/plugin-redirects": "^0.48.0"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.12"