@7365admin1/core 3.48.1-staging.189 → 3.48.1-staging.191

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.
@@ -0,0 +1,11 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Scope the manpower designation routes to the estate, and stamp who filed the plan
6
+ from the session. `/api/manpower-designations` carried `requireAuth` and nothing
7
+ else on all three routes: any signed-in account could file a manning plan into
8
+ another estate, read any estate's guard-strength plan, or rewrite one by id alone.
9
+ `createdBy` and `createdByName` were taken from the request body, so the plan could
10
+ be attributed to anybody. Reach is now checked on the site named in the request and
11
+ on the stored row for the update, and the two identity fields come from the session.
@@ -0,0 +1,12 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Scope the site facility routes to the estate. `/api/site-facilities` carried
6
+ `requireAuth` and nothing else on all six routes: any signed-in account could add a
7
+ facility to another estate, list another client's facilities — or, by omitting the
8
+ optional `site` filter, every estate's facilities at once — and read, rewrite or
9
+ archive any facility by id alone, including its opening hours, booking fees, deposit
10
+ and policies. Reach is now checked on the site named in the request, and on the
11
+ stored row where the request names only an id; the unfiltered cross-estate list is
12
+ left to platform staff.
package/dist/index.d.ts CHANGED
@@ -8807,6 +8807,7 @@ declare class MManpowerDesignations implements Partial<TManpowerDesignations> {
8807
8807
  declare function useManpowerDesignationRepo(): {
8808
8808
  createManpowerDesignations: (value: TManpowerDesignations) => Promise<mongodb.InsertOneResult<bson.Document>>;
8809
8809
  getManpowerDesignationsBySiteId: (_id: string | ObjectId, serviceProviderId?: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
8810
+ getManpowerDesignationsById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
8810
8811
  updateManpowerDesignations: (_id: string | ObjectId, value: TManpowerDesignationsUpdate) => Promise<number>;
8811
8812
  createIndexes: () => Promise<string>;
8812
8813
  };
package/dist/index.js CHANGED
@@ -54721,6 +54721,14 @@ function useSiteFacilityController() {
54721
54721
  getSiteFacilityById: _getSiteFacilityById,
54722
54722
  deleteSiteFacilityById: _deleteSiteFacilityById
54723
54723
  } = useSiteFacilityRepo();
54724
+ async function requireFacilityReach(req, id) {
54725
+ const facility = await _getSiteFacilityById(id);
54726
+ const { canReach } = await siteReachOf(req);
54727
+ if (!await canReach(facility)) {
54728
+ throw new import_node_server_utils162.NotFoundError("Site facility not found.");
54729
+ }
54730
+ return facility;
54731
+ }
54724
54732
  async function add(req, res, next) {
54725
54733
  const payload = { ...req.body };
54726
54734
  const { error } = schemaSiteFacility.validate(payload, {
@@ -54733,6 +54741,7 @@ function useSiteFacilityController() {
54733
54741
  return;
54734
54742
  }
54735
54743
  try {
54744
+ await requireSiteReach(req, payload.site);
54736
54745
  const data = await _add(payload);
54737
54746
  res.status(201).json(data);
54738
54747
  return;
@@ -54779,6 +54788,13 @@ function useSiteFacilityController() {
54779
54788
  }
54780
54789
  });
54781
54790
  try {
54791
+ if (site) {
54792
+ await requireSiteReach(req, site);
54793
+ } else {
54794
+ const { actor } = await siteReachOf(req);
54795
+ if (!actor.isSuperAdmin)
54796
+ throw new import_node_server_utils162.UnauthorizedError("Not authorized.");
54797
+ }
54782
54798
  const data = await _getAll({
54783
54799
  search,
54784
54800
  page,
@@ -54805,7 +54821,7 @@ function useSiteFacilityController() {
54805
54821
  return;
54806
54822
  }
54807
54823
  try {
54808
- const data = await _getSiteFacilityById(_id);
54824
+ const data = await requireFacilityReach(req, _id);
54809
54825
  res.status(200).json(data);
54810
54826
  return;
54811
54827
  } catch (error2) {
@@ -54827,6 +54843,7 @@ function useSiteFacilityController() {
54827
54843
  return;
54828
54844
  }
54829
54845
  try {
54846
+ await requireFacilityReach(req, _id);
54830
54847
  const result = await _updateSiteFacilityById(_id, req.body);
54831
54848
  res.status(200).json({ message: result });
54832
54849
  return;
@@ -54846,6 +54863,7 @@ function useSiteFacilityController() {
54846
54863
  return;
54847
54864
  }
54848
54865
  try {
54866
+ await requireFacilityReach(req, _id);
54849
54867
  await _deleteSiteFacilityById(_id);
54850
54868
  res.status(200).json({ message: "Successfully deleted site facility." });
54851
54869
  return;
@@ -54872,6 +54890,7 @@ function useSiteFacilityController() {
54872
54890
  return next(new import_node_server_utils162.BadRequestError(error.message));
54873
54891
  }
54874
54892
  try {
54893
+ await requireSiteReach(req, value.site);
54875
54894
  const data = await _getSiteFacilityTimeSlotById(
54876
54895
  payload._id,
54877
54896
  value.date,
@@ -76974,6 +76993,14 @@ function useManpowerDesignationRepo() {
76974
76993
  throw error;
76975
76994
  }
76976
76995
  }
76996
+ async function getManpowerDesignationsById(_id) {
76997
+ try {
76998
+ _id = new import_mongodb151.ObjectId(_id);
76999
+ } catch (error) {
77000
+ return null;
77001
+ }
77002
+ return await collection.findOne({ _id });
77003
+ }
76977
77004
  async function updateManpowerDesignations(_id, value) {
76978
77005
  try {
76979
77006
  _id = new import_mongodb151.ObjectId(_id);
@@ -76997,6 +77024,7 @@ function useManpowerDesignationRepo() {
76997
77024
  return {
76998
77025
  createManpowerDesignations,
76999
77026
  getManpowerDesignationsBySiteId,
77027
+ getManpowerDesignationsById,
77000
77028
  updateManpowerDesignations,
77001
77029
  createIndexes
77002
77030
  };
@@ -77009,8 +77037,17 @@ function useManpowerDesignationCtrl() {
77009
77037
  const {
77010
77038
  createManpowerDesignations: _createManpowerDesignations,
77011
77039
  getManpowerDesignationsBySiteId: _getManpowerDesignationsBySiteId,
77040
+ getManpowerDesignationsById: _getManpowerDesignationsById,
77012
77041
  updateManpowerDesignations: _updateManpowerDesignations
77013
77042
  } = useManpowerDesignationRepo();
77043
+ async function requireDesignationReach(req, _id) {
77044
+ const row = await _getManpowerDesignationsById(_id);
77045
+ const { canReach } = await siteReachOf(req);
77046
+ if (!row || !await canReach({ site: row.siteId })) {
77047
+ throw new import_node_server_utils241.NotFoundError("Manpower designations not found.");
77048
+ }
77049
+ return row;
77050
+ }
77014
77051
  async function createManpowerDesignations(req, res, next) {
77015
77052
  try {
77016
77053
  const payload = { ...req.body };
@@ -77019,6 +77056,12 @@ function useManpowerDesignationCtrl() {
77019
77056
  next(new import_node_server_utils241.BadRequestError(error.message));
77020
77057
  return;
77021
77058
  }
77059
+ const { actor, canReach } = await siteReachOf(req);
77060
+ if (!await canReach({ site: payload.siteId })) {
77061
+ throw new import_node_server_utils241.NotFoundError("Site not found.");
77062
+ }
77063
+ payload.createdBy = actor.id;
77064
+ payload.createdByName = actor.name;
77022
77065
  const result = await _createManpowerDesignations(payload);
77023
77066
  return res.json(result);
77024
77067
  } catch (error) {
@@ -77039,6 +77082,7 @@ function useManpowerDesignationCtrl() {
77039
77082
  next(new import_node_server_utils241.BadRequestError(error.message));
77040
77083
  return;
77041
77084
  }
77085
+ await requireSiteReach(req, id);
77042
77086
  const result = await _getManpowerDesignationsBySiteId(
77043
77087
  id,
77044
77088
  serviceProviderId
@@ -77063,6 +77107,7 @@ function useManpowerDesignationCtrl() {
77063
77107
  next(new import_node_server_utils241.BadRequestError(error.message));
77064
77108
  return;
77065
77109
  }
77110
+ await requireDesignationReach(req, _id);
77066
77111
  const result = await _updateManpowerDesignations(_id, payload);
77067
77112
  return res.json(result);
77068
77113
  } catch (error) {