@easy-cms/plugin-multi-tenant 0.47.1 → 0.47.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.
Files changed (2) hide show
  1. package/dist/index.js +8 -7
  2. package/package.json +7 -7
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.1" } : {}
64
+ ...true ? { version: "0.47.3" } : {}
65
65
  };
66
66
 
67
67
  // src/members.ts
@@ -238,14 +238,14 @@ function multiTenantPlugin(options) {
238
238
  throw new Error(
239
239
  `multiTenantPlugin: no global ${unknownGlobals.map((g) => `"${g}"`).join(", ")} in the config`
240
240
  );
241
- const everywhere = (user, context) => tenantOf(context).allTenants || !!user && user.scoped !== true && isSuper(user);
242
- const superUser = (user, context) => !!user && everywhere(user, context);
241
+ const superUser = (user, _context) => !!user && user.member !== true && user.scoped !== true && isSuper(user);
242
+ const everywhere = (user, context) => tenantOf(context).allTenants || superUser(user, context);
243
243
  const tenantFilter = (args, op) => {
244
244
  const { tenant } = tenantOf(args.context);
245
- if (op === "create") return tenant !== null || everywhere(args.user, args.context);
245
+ if (op === "create") return tenant !== null || superUser(args.user, args.context);
246
246
  if (tenant !== null) return { [TENANT_FIELD]: { equals: tenant } };
247
- if (everywhere(args.user, args.context)) return true;
248
- return op === "read" ? NOTHING : false;
247
+ if (op === "read") return everywhere(args.user, args.context) ? true : NOTHING;
248
+ return superUser(args.user, args.context);
249
249
  };
250
250
  const narrow = (original, op) => async (args) => {
251
251
  const base = await (original ?? isLoggedIn)(args);
@@ -320,7 +320,7 @@ function multiTenantPlugin(options) {
320
320
  throw new ValidationError2(slug, [{ field: TENANT_FIELD, message }]);
321
321
  };
322
322
  if (value === null) fail("is required: choose a tenant");
323
- if (everywhere(user, context)) return data;
323
+ if (superUser(user, context)) return data;
324
324
  if (!sameId(value, tenant)) fail("must be the tenant you work in");
325
325
  const before = originalDoc?.[TENANT_FIELD] ?? null;
326
326
  if (operation === "update" && before !== null && !sameId(before, value))
@@ -387,6 +387,7 @@ function multiTenantPlugin(options) {
387
387
  return {
388
388
  read: and(custom?.read, ({ user, context }) => {
389
389
  if (!user) return false;
390
+ if (user.member === true) return self(user);
390
391
  if (superUser(user, context)) return true;
391
392
  const { tenant } = tenantOf(context);
392
393
  return tenant === null ? self(user) : { or: [self(user), { [`${MEMBERSHIPS_FIELD}.tenant`]: { equals: tenant } }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-multi-tenant",
3
- "version": "0.47.1",
3
+ "version": "0.47.3",
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.1"
20
+ "@easy-cms/core": "^0.47.3"
21
21
  },
22
22
  "devDependencies": {
23
- "@easy-cms/core": "^0.47.1",
24
- "@easy-cms/db-sqlite": "^0.47.1",
25
- "@easy-cms/plugin-form-builder": "^0.47.1",
26
- "@easy-cms/plugin-nested-docs": "^0.47.1",
27
- "@easy-cms/plugin-redirects": "^0.47.1"
23
+ "@easy-cms/core": "^0.47.3",
24
+ "@easy-cms/db-sqlite": "^0.47.3",
25
+ "@easy-cms/plugin-form-builder": "^0.47.3",
26
+ "@easy-cms/plugin-nested-docs": "^0.47.3",
27
+ "@easy-cms/plugin-redirects": "^0.47.3"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.12"