@7365admin1/core 3.53.0 → 3.53.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.53.1
4
+
5
+ ### Patch Changes
6
+
7
+ - bb5fb95: Scope the roles list to a site. `GET /api/roles` now accepts an optional `site`, and `role.repo.getRoles` filters on it: a role created on a site is listed only on that site, while roles with no site remain the organisation's own and stay visible on every site. `site` is part of the cache key. No stored document changes.
8
+
3
9
  ## 3.53.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -306,13 +306,14 @@ declare function useRoleRepo(): {
306
306
  getRoleByUserId: (value: string | ObjectId) => Promise<TRole | null>;
307
307
  getRoleById: (_id: string | ObjectId) => Promise<TRole | null>;
308
308
  getRoleByName: (name: string, type?: string) => Promise<TRole | null>;
309
- getRoles: ({ search, page, limit, sort, type, org, }: {
309
+ getRoles: ({ search, page, limit, sort, type, org, site, }: {
310
310
  search?: string | undefined;
311
311
  page?: number | undefined;
312
312
  limit?: number | undefined;
313
313
  sort?: any;
314
314
  type?: string | undefined;
315
315
  org: string | ObjectId;
316
+ site?: string | ObjectId | undefined;
316
317
  }) => Promise<{}>;
317
318
  getActiveByTypeOrg: (type: string, org: string | ObjectId) => Promise<TRole[]>;
318
319
  updateRole: (_id: string | ObjectId, value: TMiniRole, session?: ClientSession) => Promise<ObjectId>;
package/dist/index.js CHANGED
@@ -16609,7 +16609,8 @@ function useRoleRepo() {
16609
16609
  limit = 10,
16610
16610
  sort = {},
16611
16611
  type = "",
16612
- org = ""
16612
+ org = "",
16613
+ site = ""
16613
16614
  }) {
16614
16615
  page = page > 0 ? page - 1 : 0;
16615
16616
  if (org && typeof org === "string" && org.length === 24) {
@@ -16619,8 +16620,19 @@ function useRoleRepo() {
16619
16620
  throw new import_node_server_utils36.BadRequestError("Invalid organization ID format.");
16620
16621
  }
16621
16622
  }
16623
+ if (site && typeof site === "string" && site.length === 24) {
16624
+ try {
16625
+ site = new import_mongodb33.ObjectId(site);
16626
+ } catch (error) {
16627
+ throw new import_node_server_utils36.BadRequestError("Invalid site ID format.");
16628
+ }
16629
+ }
16622
16630
  const query2 = { status: "active", org };
16623
16631
  const cacheOptions = { status: "active", org };
16632
+ if (site) {
16633
+ query2.$or = [{ site }, { site: "" }, { site: null }];
16634
+ cacheOptions.site = site.toString();
16635
+ }
16624
16636
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
16625
16637
  cacheOptions.sort = JSON.stringify(sort);
16626
16638
  if (search) {
@@ -19168,7 +19180,8 @@ function useRoleController() {
19168
19180
  page: import_joi19.default.number().integer().min(1).allow("", null).default(1),
19169
19181
  limit: import_joi19.default.number().integer().min(1).max(100).allow("", null).default(10),
19170
19182
  type: import_joi19.default.string().optional().allow("", null),
19171
- org: import_joi19.default.string().hex().optional().allow("", null)
19183
+ org: import_joi19.default.string().hex().optional().allow("", null),
19184
+ site: import_joi19.default.string().hex().optional().allow("", null)
19172
19185
  });
19173
19186
  const query2 = { ...req.query };
19174
19187
  const { error } = validation.validate(query2);
@@ -19182,11 +19195,12 @@ function useRoleController() {
19182
19195
  const limit = parseInt(req.query.limit ?? "10");
19183
19196
  const type = req.query.type ?? "";
19184
19197
  const org = req.query.org ?? "";
19198
+ const site = req.query.site ?? "";
19185
19199
  try {
19186
19200
  if (org) {
19187
19201
  await requireOrgReach(req, org);
19188
19202
  }
19189
- const data = await _getRoles({ search, page, limit, type, org });
19203
+ const data = await _getRoles({ search, page, limit, type, org, site });
19190
19204
  res.json(data);
19191
19205
  return;
19192
19206
  } catch (error2) {