@7365admin1/core 3.48.1-staging.152 → 3.48.1-staging.153

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,40 @@
1
+ ---
2
+ "@7365admin1/core": minor
3
+ ---
4
+
5
+ Scope the incident report routes to the estate the report was written at.
6
+
7
+ Every route on `/api/incident-reports` carried `requireAuth` and nothing more, so
8
+ being signed in anywhere on the platform was enough to page another estate's
9
+ incident log — complainant name, contact, NRIC, unit, the guard's narrative and
10
+ the photographs — and to open, rewrite, approve, reject or delete any single
11
+ report, or file one at any estate.
12
+
13
+ All eight now go through `requireSiteReach`, the rule `/api/vehicles`,
14
+ `/api/documents` and `/api/service-providers` already use:
15
+
16
+ - the two lists (`GET /`, `GET /incident-report`) and the two creates
17
+ (`POST /`, `POST /summary`) name a site in the request; that site is checked
18
+ before it is used.
19
+ - the four id routes (`GET /id/:id`, `PUT /id/:id`, `PUT /review/:id`,
20
+ `PUT /:id`) name only a record, so the site is read off the **stored** record.
21
+ `PUT /id/:id` carries a `site` of its own in the body, and authorising on that
22
+ would have let a caller quote their own estate beside another estate's report
23
+ id — the shape already found on `/api/vehicles`.
24
+
25
+ `requireSiteReach` matters more here than anywhere else: a contracted security
26
+ agency holds no membership in the estate's organisation and reaches its own site
27
+ through `customer.sites` — and the agency's guards are who **write** these
28
+ reports. A flat organisation check would have locked them out of their own work.
29
+
30
+ A report the caller cannot reach answers exactly as one that does not exist
31
+ (404), so ids cannot be enumerated from the difference. Guards sit after each
32
+ handler's Joi validation, so a malformed id still answers 400 exactly as today.
33
+
34
+ Note on the count: the route inventory listed six handlers on this mount as
35
+ unguarded. There are eight, and `POST /` and `GET /` were open too — the
36
+ controller contains no authorization identifier of any kind at the `staging` tip.
37
+ All eight are closed here.
38
+
39
+ Nothing changes for a permitted caller: same response shape, same fields, same
40
+ status.
package/dist/index.d.ts CHANGED
@@ -7210,6 +7210,25 @@ declare function useIncidentReportService(): {
7210
7210
  reviewIncidentReport: (id: string | ObjectId, value: Partial<TIncidentReport>) => Promise<string>;
7211
7211
  };
7212
7212
 
7213
+ /**
7214
+ * Who may see, or change, a security incident record.
7215
+ *
7216
+ * Every route on this mount was `requireAuth` and nothing more, so being signed
7217
+ * in anywhere on the platform was enough to read another estate's incident
7218
+ * reports — names, unit numbers, photographs and the guard's narrative — and to
7219
+ * edit, review or delete them.
7220
+ *
7221
+ * The estate is the scope. Where the request names a site (the two lists, the
7222
+ * two creates) that site is checked before it is used; where it names only a
7223
+ * record id, the site is read off the STORED record, so a caller-supplied site
7224
+ * can never stand in for the real one.
7225
+ *
7226
+ * `requireSiteReach` is the rule `/api/vehicles`, `/api/documents` and
7227
+ * `/api/service-providers` already use, so a contracted security agency — which
7228
+ * holds no membership in the estate's organisation — reaches its own site
7229
+ * through `customer.sites` exactly as it does everywhere else. That matters more
7230
+ * here than anywhere: the agency's guards are who WRITE these reports.
7231
+ */
7213
7232
  declare function useIncidentReportController(): {
7214
7233
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
7215
7234
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
package/dist/index.js CHANGED
@@ -70396,6 +70396,7 @@ function useIncidentReportController() {
70396
70396
  return;
70397
70397
  }
70398
70398
  try {
70399
+ await requireSiteReach(req, payload.site);
70399
70400
  const data = await _add(payload);
70400
70401
  res.status(201).json({ data });
70401
70402
  return;
@@ -70444,6 +70445,7 @@ function useIncidentReportController() {
70444
70445
  }
70445
70446
  });
70446
70447
  try {
70448
+ await requireSiteReach(req, site);
70447
70449
  const data = await _getAll({
70448
70450
  search,
70449
70451
  page,
@@ -70500,6 +70502,7 @@ function useIncidentReportController() {
70500
70502
  }
70501
70503
  });
70502
70504
  try {
70505
+ await requireSiteReach(req, site);
70503
70506
  const data = await _getAllForVirtualPatrolLogs({
70504
70507
  search,
70505
70508
  page,
@@ -70528,6 +70531,7 @@ function useIncidentReportController() {
70528
70531
  }
70529
70532
  try {
70530
70533
  const data = await _getIncidentReportById(_id);
70534
+ await requireSiteReach(req, data?.site);
70531
70535
  res.status(200).json(data);
70532
70536
  return;
70533
70537
  } catch (error2) {
@@ -70549,6 +70553,8 @@ function useIncidentReportController() {
70549
70553
  return;
70550
70554
  }
70551
70555
  try {
70556
+ const existing = await _getIncidentReportById(_id);
70557
+ await requireSiteReach(req, existing?.site);
70552
70558
  const result = await _updateIncidentReportById(_id, req.body);
70553
70559
  res.status(200).json({ message: result });
70554
70560
  return;
@@ -70568,6 +70574,8 @@ function useIncidentReportController() {
70568
70574
  return;
70569
70575
  }
70570
70576
  try {
70577
+ const existing = await _getIncidentReportById(_id);
70578
+ await requireSiteReach(req, existing?.site);
70571
70579
  await _deleteIncidentReportById(_id);
70572
70580
  res.status(200).json({ message: "Successfully deleted incident report." });
70573
70581
  return;
@@ -70589,6 +70597,7 @@ function useIncidentReportController() {
70589
70597
  return;
70590
70598
  }
70591
70599
  try {
70600
+ await requireSiteReach(req, payload.site);
70592
70601
  delete payload._id;
70593
70602
  delete payload.createdAt;
70594
70603
  delete payload.reasonForReject;
@@ -70623,6 +70632,8 @@ function useIncidentReportController() {
70623
70632
  return;
70624
70633
  }
70625
70634
  try {
70635
+ const existing = await _getIncidentReportById(_id);
70636
+ await requireSiteReach(req, existing?.site);
70626
70637
  const result = await _reviewIncidentReport(_id, req.body);
70627
70638
  res.status(200).json({ message: result });
70628
70639
  return;