@7365admin1/core 3.53.1 → 3.53.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.
package/dist/index.js CHANGED
@@ -6246,6 +6246,7 @@ __export(src_exports, {
6246
6246
  resolveHidPhysicalCardValue: () => resolveHidPhysicalCardValue,
6247
6247
  resolveInviteActor: () => resolveInviteActor,
6248
6248
  resolveSiteTimezone: () => resolveSiteTimezone,
6249
+ resolveStaffRole: () => resolveStaffRole,
6249
6250
  robotSchema: () => robotSchema,
6250
6251
  rtspUrl: () => rtspUrl,
6251
6252
  schema: () => schema,
@@ -10926,39 +10927,28 @@ var import_mongodb15 = require("mongodb");
10926
10927
  var import_node_server_utils15 = require("@7365admin1/node-server-utils");
10927
10928
  var import_mongodb14 = require("mongodb");
10928
10929
  var LIVE_ROLE = { status: { $ne: "deleted" } };
10929
- async function isSuperAdmin(userId) {
10930
+ async function resolveStaffRole(userId) {
10930
10931
  const id = userId?.toString() ?? "";
10931
10932
  if (!id || !import_mongodb14.ObjectId.isValid(id))
10932
- return false;
10933
+ return null;
10933
10934
  const db2 = import_node_server_utils15.useAtlas.getDb();
10934
10935
  if (!db2)
10935
- return false;
10936
+ return null;
10936
10937
  const member = await db2.collection("members").findOne({
10937
10938
  user: new import_mongodb14.ObjectId(id),
10938
10939
  type: "admin",
10939
10940
  status: { $ne: "deleted" }
10940
10941
  });
10941
10942
  if (!member?.role || !import_mongodb14.ObjectId.isValid(member.role.toString()))
10942
- return false;
10943
+ return null;
10943
10944
  const role = await db2.collection("roles").findOne({ _id: new import_mongodb14.ObjectId(member.role.toString()), ...LIVE_ROLE });
10944
- return role?.type === "admin";
10945
+ return role?.type === "admin" ? role : null;
10946
+ }
10947
+ async function isSuperAdmin(userId) {
10948
+ return await resolveStaffRole(userId) !== null;
10945
10949
  }
10946
10950
  async function isPlatformOwner(userId) {
10947
- const id = userId?.toString() ?? "";
10948
- if (!id || !import_mongodb14.ObjectId.isValid(id))
10949
- return false;
10950
- const db2 = import_node_server_utils15.useAtlas.getDb();
10951
- if (!db2)
10952
- return false;
10953
- const member = await db2.collection("members").findOne({
10954
- user: new import_mongodb14.ObjectId(id),
10955
- type: "admin",
10956
- status: { $ne: "deleted" }
10957
- });
10958
- if (!member?.role || !import_mongodb14.ObjectId.isValid(member.role.toString()))
10959
- return false;
10960
- const role = await db2.collection("roles").findOne({ _id: new import_mongodb14.ObjectId(member.role.toString()), ...LIVE_ROLE });
10961
- return role?.type === "admin" && role?.default === true;
10951
+ return (await resolveStaffRole(userId))?.default === true;
10962
10952
  }
10963
10953
 
10964
10954
  // src/utils/org-suspension.util.ts
@@ -16836,6 +16826,8 @@ var MFile = class {
16836
16826
  this.size = value.size ?? 0;
16837
16827
  this.status = value.status ?? "draft";
16838
16828
  this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
16829
+ if (value.createdBy)
16830
+ this.createdBy = value.createdBy.toString();
16839
16831
  }
16840
16832
  };
16841
16833
 
@@ -18659,32 +18651,127 @@ function usePersonRepo() {
18659
18651
 
18660
18652
  // src/utils/console-authz.util.ts
18661
18653
  var import_node_server_utils42 = require("@7365admin1/node-server-utils");
18654
+
18655
+ // src/utils/console-permission.util.ts
18656
+ var CONSOLE_PERMISSIONS = Object.freeze({
18657
+ organizations: Object.freeze([
18658
+ "see-all-organizations",
18659
+ "see-organization-details"
18660
+ ]),
18661
+ "promo-codes": Object.freeze([
18662
+ "create-promo-code",
18663
+ "see-promo-code-details",
18664
+ "edit-promo-code-details",
18665
+ "change-promo-code-status",
18666
+ "delete-promo-code"
18667
+ ]),
18668
+ users: Object.freeze(["see-all-users", "see-user-details"]),
18669
+ invitations: Object.freeze([
18670
+ "create-invitation",
18671
+ "view-invitations",
18672
+ "cancel-invitation"
18673
+ ]),
18674
+ subscriptions: Object.freeze([
18675
+ "see-all-subscriptions",
18676
+ "see-subscription-details",
18677
+ "manage-subscription"
18678
+ ]),
18679
+ "sp-approvals": Object.freeze([
18680
+ "see-all-sp-approvals",
18681
+ "approve-sp",
18682
+ "reject-sp",
18683
+ "delete-sp-approval"
18684
+ ]),
18685
+ "marketplace-vendors": Object.freeze([
18686
+ "see-all-marketplace-vendors",
18687
+ "see-marketplace-vendor-details"
18688
+ ]),
18689
+ "platform-terms": Object.freeze([
18690
+ "see-platform-terms",
18691
+ "edit-platform-terms"
18692
+ ]),
18693
+ "activity-history": Object.freeze(["see-activity-history"]),
18694
+ members: Object.freeze([
18695
+ "view-members",
18696
+ "assign-member-role",
18697
+ "suspend-member",
18698
+ "activate-member",
18699
+ "delete-member"
18700
+ ]),
18701
+ "roles-and-permissions": Object.freeze([
18702
+ "add-role",
18703
+ "see-all-roles",
18704
+ "see-role-details",
18705
+ "update-role",
18706
+ "delete-role"
18707
+ ])
18708
+ });
18709
+ var RESOURCE_SPELLINGS = Object.freeze({
18710
+ "roles-and-permissions": Object.freeze([
18711
+ "roles-and-permissions",
18712
+ "roles"
18713
+ ]),
18714
+ roles: Object.freeze(["roles", "roles-and-permissions"])
18715
+ });
18716
+ function consoleSpellings(resource, action) {
18717
+ const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
18718
+ return resources.map((name) => `${name}:${action}`);
18719
+ }
18720
+ function consoleRoleAllowsAll(held) {
18721
+ if (!Array.isArray(held) || held.length === 0)
18722
+ return true;
18723
+ return held.includes("*");
18724
+ }
18725
+ function consoleRoleAllows(held, resource, action) {
18726
+ if (consoleRoleAllowsAll(held))
18727
+ return true;
18728
+ const actions = CONSOLE_PERMISSIONS[resource];
18729
+ if (!actions?.length)
18730
+ return false;
18731
+ const wanted = action ? actions.includes(action) ? [action] : [] : actions;
18732
+ return wanted.some(
18733
+ (name) => consoleSpellings(resource, name).some(
18734
+ (spelling) => held.includes(spelling)
18735
+ )
18736
+ );
18737
+ }
18738
+
18739
+ // src/utils/console-authz.util.ts
18662
18740
  function callerId(req) {
18663
18741
  const user = req.user;
18664
18742
  return user?.user?.toString?.() || user?._id?.toString?.() || "";
18665
18743
  }
18666
- async function requirePlatformStaff(req) {
18744
+ async function requirePlatformStaff(req, grant) {
18667
18745
  const id = callerId(req);
18668
- if (!id || !await isSuperAdmin(id)) {
18746
+ const role = id ? await resolveStaffRole(id) : null;
18747
+ if (!role) {
18748
+ throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
18749
+ }
18750
+ if (grant && !consoleRoleAllows(role.permissions, grant.resource, grant.action)) {
18669
18751
  throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
18670
18752
  }
18671
18753
  return id;
18672
18754
  }
18673
- async function requireSelfOrPlatformStaff(req, userId) {
18755
+ async function requireConsolePermission(req, resource, action) {
18756
+ return await requirePlatformStaff(req, { resource, action });
18757
+ }
18758
+ async function requireSelfOrPlatformStaff(req, userId, grant) {
18674
18759
  const id = callerId(req);
18675
18760
  const target = userId?.toString() ?? "";
18676
18761
  if (id && target && target === id)
18677
18762
  return id;
18678
- return await requirePlatformStaff(req);
18763
+ return await requirePlatformStaff(req, grant);
18679
18764
  }
18680
18765
  async function requireOrgAccess(req, orgId) {
18681
18766
  return await requireOrgReach(req, orgId);
18682
18767
  }
18683
- async function requirePlatformOwner(req) {
18768
+ async function requirePlatformOwner(req, grant) {
18684
18769
  const id = callerId(req);
18685
18770
  if (!id || !await isPlatformOwner(id)) {
18686
18771
  throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
18687
18772
  }
18773
+ if (grant)
18774
+ await requirePlatformStaff(req, grant);
18688
18775
  return id;
18689
18776
  }
18690
18777
  async function requireOrgReach(req, orgId) {
@@ -18711,10 +18798,10 @@ async function requireInviteReach(req, org, app) {
18711
18798
  if (org)
18712
18799
  await requireOrgReach(req, org);
18713
18800
  }
18714
- async function requireUserFieldWrite(req, userId, field) {
18801
+ async function requireUserFieldWrite(req, userId, field, grant) {
18715
18802
  if (field === "email")
18716
- return await requirePlatformStaff(req);
18717
- return await requireSelfOrPlatformStaff(req, userId);
18803
+ return await requirePlatformStaff(req, grant);
18804
+ return await requireSelfOrPlatformStaff(req, userId, grant);
18718
18805
  }
18719
18806
 
18720
18807
  // src/utils/user-response.util.ts
@@ -18754,7 +18841,7 @@ function useUserController() {
18754
18841
  return;
18755
18842
  }
18756
18843
  try {
18757
- await requireSelfOrPlatformStaff(req, _id);
18844
+ await requireSelfOrPlatformStaff(req, _id, { resource: "users", action: "see-user-details" });
18758
18845
  const user = await _getById(_id);
18759
18846
  res.json(user);
18760
18847
  return;
@@ -18839,7 +18926,7 @@ function useUserController() {
18839
18926
  const page = parseInt(req.query.page ?? "1");
18840
18927
  const status = req.query.status ?? "active";
18841
18928
  try {
18842
- await requirePlatformStaff(req);
18929
+ await requireConsolePermission(req, "users", "see-all-users");
18843
18930
  const data = await _getUsers({ search, page, status });
18844
18931
  res.json(data);
18845
18932
  return;
@@ -18934,7 +19021,7 @@ function useUserController() {
18934
19021
  return;
18935
19022
  }
18936
19023
  try {
18937
- await requireSelfOrPlatformStaff(req, _id);
19024
+ await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
18938
19025
  const message = await _updateBirthday({ _id, ...payload });
18939
19026
  res.json({ message });
18940
19027
  return;
@@ -18976,7 +19063,7 @@ function useUserController() {
18976
19063
  return;
18977
19064
  }
18978
19065
  try {
18979
- await requireUserFieldWrite(req, _id, payload.field);
19066
+ await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
18980
19067
  let message;
18981
19068
  if (payload.field === "plateNumber") {
18982
19069
  message = await updatePlateNumberByUserId(
@@ -19018,7 +19105,7 @@ function useUserController() {
19018
19105
  const newPassword = req.body.newPassword ?? "";
19019
19106
  const passwordConfirmation = req.body.passwordConfirmation ?? "";
19020
19107
  try {
19021
- await requireSelfOrPlatformStaff(req, _id);
19108
+ await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
19022
19109
  await _updatePasswordById(
19023
19110
  _id,
19024
19111
  currentPassword,
@@ -19118,7 +19205,7 @@ function useRoleService() {
19118
19205
  async function requireRoleOrg(req, org) {
19119
19206
  const orgId = org?.toString() ?? "";
19120
19207
  if (!orgId) {
19121
- await requirePlatformStaff(req);
19208
+ await requireConsolePermission(req, "roles-and-permissions");
19122
19209
  return;
19123
19210
  }
19124
19211
  await requireOrgAccess(req, orgId);
@@ -19160,7 +19247,7 @@ function useRoleController() {
19160
19247
  }
19161
19248
  try {
19162
19249
  if (payload.type === PLATFORM_STAFF_ROLE_TYPE) {
19163
- await requirePlatformStaff(req);
19250
+ await requireConsolePermission(req, "roles-and-permissions", "add-role");
19164
19251
  }
19165
19252
  if (payload.org) {
19166
19253
  await requireOrgReach(req, payload.org);
@@ -22532,13 +22619,14 @@ function useFileService() {
22532
22619
  bucket: SPACES_BUCKET,
22533
22620
  forcePathStyle: true
22534
22621
  });
22535
- async function createFile(value, folder = "default") {
22622
+ async function createFile(value, folder = "default", createdBy) {
22536
22623
  const session = import_node_server_utils51.useAtlas.getClient()?.startSession();
22537
22624
  session?.startTransaction();
22538
22625
  const file = {
22539
22626
  name: value.originalname,
22540
22627
  size: value.size ?? (value.buffer ? value.buffer.length : 0),
22541
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
22628
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
22629
+ ...createdBy ? { createdBy } : {}
22542
22630
  };
22543
22631
  try {
22544
22632
  const id = await _createFile(file, session);
@@ -26748,7 +26836,7 @@ async function entitledSites(req) {
26748
26836
  async function requireMemberOrg(req, org) {
26749
26837
  const orgId = org?.toString() ?? "";
26750
26838
  if (!orgId) {
26751
- await requirePlatformStaff(req);
26839
+ await requireConsolePermission(req, "members");
26752
26840
  return;
26753
26841
  }
26754
26842
  await requireOrgAccess(req, orgId);
@@ -26795,7 +26883,7 @@ function useMemberController() {
26795
26883
  return;
26796
26884
  }
26797
26885
  try {
26798
- await requireSelfOrPlatformStaff(req, userId);
26886
+ await requireSelfOrPlatformStaff(req, userId, { resource: "members", action: "view-members" });
26799
26887
  const data = await _getByUserId(userId);
26800
26888
  res.json(data);
26801
26889
  return;
@@ -26845,7 +26933,7 @@ function useMemberController() {
26845
26933
  const user = req.params.id;
26846
26934
  const type = req.params.type;
26847
26935
  try {
26848
- await requireSelfOrPlatformStaff(req, user);
26936
+ await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
26849
26937
  const data = await _getByUserIdType(user, type);
26850
26938
  res.json(data);
26851
26939
  return;
@@ -26891,11 +26979,11 @@ function useMemberController() {
26891
26979
  }
26892
26980
  try {
26893
26981
  if (type === "admin") {
26894
- await requirePlatformStaff(req);
26982
+ await requireConsolePermission(req, "members", "view-members");
26895
26983
  } else if (org) {
26896
26984
  await requireOrgAccess(req, org);
26897
26985
  } else if (user && user !== callerId(req)) {
26898
- await requirePlatformStaff(req);
26986
+ await requireConsolePermission(req, "users", "see-all-users");
26899
26987
  }
26900
26988
  const items = await _getAll({
26901
26989
  search,
@@ -27090,7 +27178,7 @@ function useMemberController() {
27090
27178
  const type = req.params.type;
27091
27179
  const org = req.query.org;
27092
27180
  try {
27093
- await requireSelfOrPlatformStaff(req, user);
27181
+ await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
27094
27182
  const data = await _getByUserIdTypeOrg(
27095
27183
  user,
27096
27184
  type,
@@ -27624,6 +27712,49 @@ function useVerificationController() {
27624
27712
  // src/controllers/file.controller.ts
27625
27713
  var import_node_server_utils59 = require("@7365admin1/node-server-utils");
27626
27714
  var import_joi27 = __toESM(require("joi"));
27715
+
27716
+ // src/utils/file-owner.util.ts
27717
+ function fileOwnerId(file) {
27718
+ return file?.createdBy?.toString?.() ?? "";
27719
+ }
27720
+ function mayDeleteFile(params) {
27721
+ if (!params.ownerId)
27722
+ return true;
27723
+ if (!params.callerId)
27724
+ return false;
27725
+ if (params.callerId === params.ownerId)
27726
+ return true;
27727
+ if (params.callerIsSuperAdmin)
27728
+ return true;
27729
+ const ownerOrgs = new Set((params.ownerOrgIds ?? []).map(String));
27730
+ return (params.callerOrgIds ?? []).some((org) => ownerOrgs.has(String(org)));
27731
+ }
27732
+
27733
+ // src/controllers/file.controller.ts
27734
+ async function requireFileDelete(req, file) {
27735
+ const ownerId = fileOwnerId(file);
27736
+ if (!ownerId)
27737
+ return;
27738
+ const caller = callerId(req);
27739
+ if (!caller)
27740
+ throw new import_node_server_utils59.UnauthorizedError("Not authorized.");
27741
+ if (caller === ownerId)
27742
+ return;
27743
+ const [me, owner] = await Promise.all([
27744
+ resolveInviteActor(caller),
27745
+ resolveInviteActor(ownerId)
27746
+ ]);
27747
+ if (mayDeleteFile({
27748
+ ownerId,
27749
+ callerId: caller,
27750
+ callerIsSuperAdmin: me.isSuperAdmin,
27751
+ callerOrgIds: me.orgIds,
27752
+ ownerOrgIds: owner.orgIds
27753
+ })) {
27754
+ return;
27755
+ }
27756
+ throw new import_node_server_utils59.UnauthorizedError("Not authorized.");
27757
+ }
27627
27758
  function useFileController() {
27628
27759
  const { createFile, deleteFile: _deleteFile } = useFileService();
27629
27760
  const { getFileById: _getFileById } = useFileRepo();
@@ -27633,7 +27764,7 @@ function useFileController() {
27633
27764
  return;
27634
27765
  }
27635
27766
  try {
27636
- const id = await createFile(req.file);
27767
+ const id = await createFile(req.file, "default", callerId(req) || void 0);
27637
27768
  res.status(201).json({ message: "Successfully uploaded file", id });
27638
27769
  return;
27639
27770
  } catch (error) {
@@ -27652,6 +27783,7 @@ function useFileController() {
27652
27783
  return;
27653
27784
  }
27654
27785
  try {
27786
+ await requireFileDelete(req, await _getFileById(_id));
27655
27787
  const message = await _deleteFile(_id);
27656
27788
  res.json({ message });
27657
27789
  return;
@@ -28881,7 +29013,7 @@ function useOrgController() {
28881
29013
  return;
28882
29014
  }
28883
29015
  try {
28884
- const createdBy = await requirePlatformStaff(req);
29016
+ const createdBy = await requireConsolePermission(req, "organizations");
28885
29017
  await _add({ ...req.body, createdBy });
28886
29018
  res.status(201).json({ message: "Successfully created organization." });
28887
29019
  return;
@@ -28987,7 +29119,7 @@ function useOrgController() {
28987
29119
  const type = req.query.type ?? "";
28988
29120
  try {
28989
29121
  if (user !== callerId(req)) {
28990
- await requirePlatformStaff(req);
29122
+ await requireConsolePermission(req, "organizations", "see-all-organizations");
28991
29123
  }
28992
29124
  const data = await getOrgsByMembership({
28993
29125
  search,
@@ -29014,7 +29146,7 @@ function useOrgController() {
29014
29146
  return;
29015
29147
  }
29016
29148
  try {
29017
- await requirePlatformStaff(req);
29149
+ await requireConsolePermission(req, "organizations", "see-organization-details");
29018
29150
  const data = await _getByName(name);
29019
29151
  res.json(data);
29020
29152
  return;
@@ -29052,7 +29184,7 @@ function useOrgController() {
29052
29184
  return;
29053
29185
  }
29054
29186
  try {
29055
- await requirePlatformStaff(req);
29187
+ await requireConsolePermission(req, "organizations", "see-organization-details");
29056
29188
  const data = await _getByEmail(email);
29057
29189
  if (!data) {
29058
29190
  next(new import_node_server_utils64.NotFoundError("Organization not found."));
@@ -29082,7 +29214,7 @@ function useOrgController() {
29082
29214
  try {
29083
29215
  const self = await _getUserById(callerId(req)).catch(() => null);
29084
29216
  if (!self?.email || self.email.toLowerCase() !== email.toLowerCase()) {
29085
- await requirePlatformStaff(req);
29217
+ await requireConsolePermission(req, "organizations", "see-all-organizations");
29086
29218
  }
29087
29219
  const data = await _getOrgsByEmail(email);
29088
29220
  res.json(data);
@@ -29142,7 +29274,7 @@ function useOrgController() {
29142
29274
  const orgId = req.params.id;
29143
29275
  const { status } = req.body;
29144
29276
  try {
29145
- const ownerId = await requirePlatformOwner(req);
29277
+ const ownerId = await requirePlatformOwner(req, { resource: "organizations" });
29146
29278
  await _updateStatusById(orgId, status);
29147
29279
  const subscription = await _getSubscriptionByOrgId(orgId);
29148
29280
  if (subscription) {
@@ -29213,7 +29345,7 @@ function useOrgControllerV2() {
29213
29345
  const nature = value.nature ?? "";
29214
29346
  const status = value.status;
29215
29347
  try {
29216
- await requirePlatformStaff(req);
29348
+ await requireConsolePermission(req, "organizations", "see-all-organizations");
29217
29349
  const data = await _getAll({
29218
29350
  search,
29219
29351
  page,
@@ -29250,7 +29382,7 @@ function useOrgControllerV2() {
29250
29382
  return;
29251
29383
  }
29252
29384
  try {
29253
- await requirePlatformStaff(req);
29385
+ await requireConsolePermission(req, "organizations", "see-all-organizations");
29254
29386
  const data = await _getOrganizationsWithSubscription({
29255
29387
  search: value.search ?? "",
29256
29388
  page: value.page ?? 1,
@@ -31712,7 +31844,7 @@ function useSubscriptionController() {
31712
31844
  return;
31713
31845
  }
31714
31846
  try {
31715
- await requirePlatformStaff(req);
31847
+ await requireConsolePermission(req, "subscriptions", "manage-subscription");
31716
31848
  const id = await _add(payload);
31717
31849
  res.status(201).json({ message: "Successfully added subscription.", id });
31718
31850
  return;
@@ -31759,7 +31891,7 @@ function useSubscriptionController() {
31759
31891
  const page = parseInt(req.query.page ?? "1");
31760
31892
  const status = req.query.status ?? "active";
31761
31893
  try {
31762
- await requirePlatformStaff(req);
31894
+ await requireConsolePermission(req, "subscriptions", "see-all-subscriptions");
31763
31895
  const data = await _getSubscriptions({ search, page, status });
31764
31896
  res.json(data);
31765
31897
  return;
@@ -31893,7 +32025,7 @@ function useSubscriptionController() {
31893
32025
  }
31894
32026
  async function createConsoleSubscription(req, res, next) {
31895
32027
  try {
31896
- const staffId = await requirePlatformStaff(req);
32028
+ const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
31897
32029
  const form = await readConsoleForm(req);
31898
32030
  const existing = await _getByOrgId(form.orgId);
31899
32031
  if (existing && existing.status !== "ended") {
@@ -31939,7 +32071,7 @@ function useSubscriptionController() {
31939
32071
  }
31940
32072
  async function updateConsoleSubscription(req, res, next) {
31941
32073
  try {
31942
- const staffId = await requirePlatformStaff(req);
32074
+ const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
31943
32075
  const form = await readConsoleForm(req);
31944
32076
  const existing = await _getByOrgId(form.orgId);
31945
32077
  if (!existing?._id) {
@@ -31979,7 +32111,7 @@ function useSubscriptionController() {
31979
32111
  }
31980
32112
  async function getConsoleSubscription(req, res, next) {
31981
32113
  try {
31982
- await requirePlatformStaff(req);
32114
+ await requireConsolePermission(req, "subscriptions", "see-subscription-details");
31983
32115
  const orgId = req.params.id;
31984
32116
  if (!/^[0-9a-fA-F]{24}$/.test(orgId ?? "")) {
31985
32117
  throw new import_node_server_utils80.BadRequestError("That client could not be found.");
@@ -32048,7 +32180,7 @@ function useSubscriptionPlanController() {
32048
32180
  return;
32049
32181
  }
32050
32182
  try {
32051
- const staffId = await requirePlatformStaff(req);
32183
+ const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
32052
32184
  const _id = await _add(req.body);
32053
32185
  const data = await _getById(_id);
32054
32186
  await recordConsoleAction({
@@ -32144,7 +32276,7 @@ function useSubscriptionPlanController() {
32144
32276
  }
32145
32277
  const id = req.params.id;
32146
32278
  try {
32147
- const staffId = await requirePlatformStaff(req);
32279
+ const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
32148
32280
  const before = await _getById(id);
32149
32281
  await _update(id, req.body);
32150
32282
  const data = await _getById(id);
@@ -32176,7 +32308,7 @@ function useSubscriptionPlanController() {
32176
32308
  const id = req.params.id;
32177
32309
  const { status } = req.body;
32178
32310
  try {
32179
- const staffId = await requirePlatformStaff(req);
32311
+ const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
32180
32312
  await _updateStatusById(id, status);
32181
32313
  const data = await _getById(id);
32182
32314
  await recordConsoleAction({
@@ -32317,7 +32449,7 @@ function usePromoCodeController() {
32317
32449
  payload.code = payload.code.trim().toUpperCase();
32318
32450
  payload.fixed_rate = parseInt(payload.fixed_rate ?? "0");
32319
32451
  try {
32320
- const staffId = await requirePlatformStaff(req);
32452
+ const staffId = await requireConsolePermission(req, "promo-codes", "create-promo-code");
32321
32453
  const created = await _add(payload);
32322
32454
  await recordConsoleAction({
32323
32455
  action: "promo-code.created" /* PROMO_CODE_CREATED */,
@@ -32370,7 +32502,7 @@ function usePromoCodeController() {
32370
32502
  return;
32371
32503
  }
32372
32504
  try {
32373
- await requirePlatformStaff(req);
32505
+ await requireConsolePermission(req, "promo-codes", "see-promo-code-details");
32374
32506
  const data = await _getById(_id);
32375
32507
  res.json(data);
32376
32508
  return;
@@ -32399,7 +32531,7 @@ function usePromoCodeController() {
32399
32531
  const limit = parseInt(req.query.limit ?? "10");
32400
32532
  const status = req.query.status ?? "active";
32401
32533
  try {
32402
- await requirePlatformStaff(req);
32534
+ await requireConsolePermission(req, "promo-codes");
32403
32535
  const data = await _getPromoCodes({
32404
32536
  search,
32405
32537
  page,
@@ -32424,7 +32556,7 @@ function usePromoCodeController() {
32424
32556
  return;
32425
32557
  }
32426
32558
  try {
32427
- const staffId = await requirePlatformStaff(req);
32559
+ const staffId = await requireConsolePermission(req, "promo-codes", "edit-promo-code-details");
32428
32560
  const before = await _getById(req.params.id);
32429
32561
  await _updateById(req.params.id, req.body);
32430
32562
  await recordConsoleAction({
@@ -32460,7 +32592,7 @@ function usePromoCodeController() {
32460
32592
  return;
32461
32593
  }
32462
32594
  try {
32463
- const staffId = await requirePlatformStaff(req);
32595
+ const staffId = await requireConsolePermission(req, "promo-codes", "change-promo-code-status");
32464
32596
  await _updateStatusById(req.params.id, status.value.status);
32465
32597
  await recordConsoleAction({
32466
32598
  action: "promo-code.status-changed" /* PROMO_CODE_STATUS_CHANGED */,
@@ -32489,7 +32621,7 @@ function usePromoCodeController() {
32489
32621
  return;
32490
32622
  }
32491
32623
  try {
32492
- const staffId = await requirePlatformStaff(req);
32624
+ const staffId = await requireConsolePermission(req, "promo-codes", "delete-promo-code");
32493
32625
  await _softDeleteById(req.params.id, staffId);
32494
32626
  await recordConsoleAction({
32495
32627
  action: "promo-code.removed" /* PROMO_CODE_REMOVED */,
@@ -86299,7 +86431,7 @@ function useUserControllerV2() {
86299
86431
  return;
86300
86432
  }
86301
86433
  try {
86302
- await requireSelfOrPlatformStaff(req, value);
86434
+ await requireSelfOrPlatformStaff(req, value, { resource: "users", action: "see-user-details" });
86303
86435
  const user = await _getById(value);
86304
86436
  res.json(user);
86305
86437
  return;
@@ -86336,7 +86468,7 @@ function useUserControllerV2() {
86336
86468
  if (error)
86337
86469
  return rejectValidation(error, next);
86338
86470
  try {
86339
- await requirePlatformStaff(req);
86471
+ await requireConsolePermission(req, "users", "see-all-users");
86340
86472
  const users = await _getUsers({
86341
86473
  search: value.search ?? "",
86342
86474
  page: value.page,
@@ -86461,7 +86593,7 @@ function useUserControllerV2() {
86461
86593
  return;
86462
86594
  }
86463
86595
  try {
86464
- await requireSelfOrPlatformStaff(req, _id);
86596
+ await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
86465
86597
  const message = await _updateBirthday({ _id, ...payload });
86466
86598
  res.json({ message });
86467
86599
  return;
@@ -86493,7 +86625,7 @@ function useUserControllerV2() {
86493
86625
  return;
86494
86626
  }
86495
86627
  try {
86496
- await requireUserFieldWrite(req, _id, payload.field);
86628
+ await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
86497
86629
  const message = await _updateUserFieldById({ _id, ...payload });
86498
86630
  res.json({ message });
86499
86631
  return;
@@ -86524,7 +86656,7 @@ function useUserControllerV2() {
86524
86656
  const newPassword = req.body.newPassword ?? "";
86525
86657
  const passwordConfirmation = req.body.passwordConfirmation ?? "";
86526
86658
  try {
86527
- await requireSelfOrPlatformStaff(req, _id);
86659
+ await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
86528
86660
  await _updatePasswordById(
86529
86661
  _id,
86530
86662
  currentPassword,
@@ -86702,7 +86834,7 @@ function useRoleControllerV2() {
86702
86834
  }
86703
86835
  try {
86704
86836
  if (value.type === PLATFORM_STAFF_ROLE_TYPE) {
86705
- await requirePlatformStaff(req);
86837
+ await requireConsolePermission(req, "roles-and-permissions", "add-role");
86706
86838
  }
86707
86839
  if (value.org) {
86708
86840
  await requireOrgReach(req, value.org);
@@ -91378,7 +91510,7 @@ function usePlatformTermsController() {
91378
91510
  return id;
91379
91511
  }
91380
91512
  if (staffMayRead) {
91381
- return await requirePlatformStaff(req);
91513
+ return await requireConsolePermission(req, "platform-terms", "see-platform-terms");
91382
91514
  }
91383
91515
  throw new import_node_server_utils298.UnauthorizedError("Not authorized.");
91384
91516
  }
@@ -91470,7 +91602,7 @@ function usePlatformTermsController() {
91470
91602
  return;
91471
91603
  }
91472
91604
  try {
91473
- await requirePlatformStaff(req);
91605
+ await requireConsolePermission(req, "platform-terms", "see-platform-terms");
91474
91606
  res.json(
91475
91607
  await _listAcceptance({
91476
91608
  version: value.version || null,
@@ -91502,7 +91634,7 @@ function usePlatformTermsController() {
91502
91634
  return;
91503
91635
  }
91504
91636
  try {
91505
- const staffId = await requirePlatformStaff(req);
91637
+ const staffId = await requireConsolePermission(req, "platform-terms", "edit-platform-terms");
91506
91638
  const created = await _add({
91507
91639
  terms: value.terms,
91508
91640
  policies: value.policies,
@@ -91560,7 +91692,7 @@ function useConsoleAuditController() {
91560
91692
  }
91561
91693
  const to = value.to && value.to.length === 10 ? `${value.to}T23:59:59.999Z` : value.to;
91562
91694
  try {
91563
- await requirePlatformStaff(req);
91695
+ await requireConsolePermission(req, "activity-history", "see-activity-history");
91564
91696
  res.json(
91565
91697
  await _list({
91566
91698
  org: value.org || "",
@@ -92223,6 +92355,7 @@ function useNotificationPreferenceController() {
92223
92355
  resolveHidPhysicalCardValue,
92224
92356
  resolveInviteActor,
92225
92357
  resolveSiteTimezone,
92358
+ resolveStaffRole,
92226
92359
  robotSchema,
92227
92360
  rtspUrl,
92228
92361
  schema,