@7365admin1/core 3.53.2 → 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/CHANGELOG.md +15 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +159 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/console-audit.test.mjs +4 -4
- package/test/console-permission.test.mjs +273 -0
- package/test/e2e/console-permission.e2e.test.mjs +286 -0
- package/test/member-scope.test.mjs +4 -4
- package/test/org-suspension.test.mjs +22 -7
- package/test/resident-ownership-scope.test.mjs +1 -1
- package/test/role-member-org-scope.test.mjs +1 -1
- package/test/role-scope.test.mjs +4 -4
- package/test/staff-console-authz.test.mjs +25 -25
- package/test/terms-acceptance-list.test.mjs +2 -2
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
|
|
10930
|
+
async function resolveStaffRole(userId) {
|
|
10930
10931
|
const id = userId?.toString() ?? "";
|
|
10931
10932
|
if (!id || !import_mongodb14.ObjectId.isValid(id))
|
|
10932
|
-
return
|
|
10933
|
+
return null;
|
|
10933
10934
|
const db2 = import_node_server_utils15.useAtlas.getDb();
|
|
10934
10935
|
if (!db2)
|
|
10935
|
-
return
|
|
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
|
|
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
|
-
|
|
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
|
|
@@ -18661,32 +18651,127 @@ function usePersonRepo() {
|
|
|
18661
18651
|
|
|
18662
18652
|
// src/utils/console-authz.util.ts
|
|
18663
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
|
|
18664
18740
|
function callerId(req) {
|
|
18665
18741
|
const user = req.user;
|
|
18666
18742
|
return user?.user?.toString?.() || user?._id?.toString?.() || "";
|
|
18667
18743
|
}
|
|
18668
|
-
async function requirePlatformStaff(req) {
|
|
18744
|
+
async function requirePlatformStaff(req, grant) {
|
|
18669
18745
|
const id = callerId(req);
|
|
18670
|
-
|
|
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)) {
|
|
18671
18751
|
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18672
18752
|
}
|
|
18673
18753
|
return id;
|
|
18674
18754
|
}
|
|
18675
|
-
async function
|
|
18755
|
+
async function requireConsolePermission(req, resource, action) {
|
|
18756
|
+
return await requirePlatformStaff(req, { resource, action });
|
|
18757
|
+
}
|
|
18758
|
+
async function requireSelfOrPlatformStaff(req, userId, grant) {
|
|
18676
18759
|
const id = callerId(req);
|
|
18677
18760
|
const target = userId?.toString() ?? "";
|
|
18678
18761
|
if (id && target && target === id)
|
|
18679
18762
|
return id;
|
|
18680
|
-
return await requirePlatformStaff(req);
|
|
18763
|
+
return await requirePlatformStaff(req, grant);
|
|
18681
18764
|
}
|
|
18682
18765
|
async function requireOrgAccess(req, orgId) {
|
|
18683
18766
|
return await requireOrgReach(req, orgId);
|
|
18684
18767
|
}
|
|
18685
|
-
async function requirePlatformOwner(req) {
|
|
18768
|
+
async function requirePlatformOwner(req, grant) {
|
|
18686
18769
|
const id = callerId(req);
|
|
18687
18770
|
if (!id || !await isPlatformOwner(id)) {
|
|
18688
18771
|
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18689
18772
|
}
|
|
18773
|
+
if (grant)
|
|
18774
|
+
await requirePlatformStaff(req, grant);
|
|
18690
18775
|
return id;
|
|
18691
18776
|
}
|
|
18692
18777
|
async function requireOrgReach(req, orgId) {
|
|
@@ -18713,10 +18798,10 @@ async function requireInviteReach(req, org, app) {
|
|
|
18713
18798
|
if (org)
|
|
18714
18799
|
await requireOrgReach(req, org);
|
|
18715
18800
|
}
|
|
18716
|
-
async function requireUserFieldWrite(req, userId, field) {
|
|
18801
|
+
async function requireUserFieldWrite(req, userId, field, grant) {
|
|
18717
18802
|
if (field === "email")
|
|
18718
|
-
return await requirePlatformStaff(req);
|
|
18719
|
-
return await requireSelfOrPlatformStaff(req, userId);
|
|
18803
|
+
return await requirePlatformStaff(req, grant);
|
|
18804
|
+
return await requireSelfOrPlatformStaff(req, userId, grant);
|
|
18720
18805
|
}
|
|
18721
18806
|
|
|
18722
18807
|
// src/utils/user-response.util.ts
|
|
@@ -18756,7 +18841,7 @@ function useUserController() {
|
|
|
18756
18841
|
return;
|
|
18757
18842
|
}
|
|
18758
18843
|
try {
|
|
18759
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
18844
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users", action: "see-user-details" });
|
|
18760
18845
|
const user = await _getById(_id);
|
|
18761
18846
|
res.json(user);
|
|
18762
18847
|
return;
|
|
@@ -18841,7 +18926,7 @@ function useUserController() {
|
|
|
18841
18926
|
const page = parseInt(req.query.page ?? "1");
|
|
18842
18927
|
const status = req.query.status ?? "active";
|
|
18843
18928
|
try {
|
|
18844
|
-
await
|
|
18929
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
18845
18930
|
const data = await _getUsers({ search, page, status });
|
|
18846
18931
|
res.json(data);
|
|
18847
18932
|
return;
|
|
@@ -18936,7 +19021,7 @@ function useUserController() {
|
|
|
18936
19021
|
return;
|
|
18937
19022
|
}
|
|
18938
19023
|
try {
|
|
18939
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
19024
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
18940
19025
|
const message = await _updateBirthday({ _id, ...payload });
|
|
18941
19026
|
res.json({ message });
|
|
18942
19027
|
return;
|
|
@@ -18978,7 +19063,7 @@ function useUserController() {
|
|
|
18978
19063
|
return;
|
|
18979
19064
|
}
|
|
18980
19065
|
try {
|
|
18981
|
-
await requireUserFieldWrite(req, _id, payload.field);
|
|
19066
|
+
await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
|
|
18982
19067
|
let message;
|
|
18983
19068
|
if (payload.field === "plateNumber") {
|
|
18984
19069
|
message = await updatePlateNumberByUserId(
|
|
@@ -19020,7 +19105,7 @@ function useUserController() {
|
|
|
19020
19105
|
const newPassword = req.body.newPassword ?? "";
|
|
19021
19106
|
const passwordConfirmation = req.body.passwordConfirmation ?? "";
|
|
19022
19107
|
try {
|
|
19023
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
19108
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
19024
19109
|
await _updatePasswordById(
|
|
19025
19110
|
_id,
|
|
19026
19111
|
currentPassword,
|
|
@@ -19120,7 +19205,7 @@ function useRoleService() {
|
|
|
19120
19205
|
async function requireRoleOrg(req, org) {
|
|
19121
19206
|
const orgId = org?.toString() ?? "";
|
|
19122
19207
|
if (!orgId) {
|
|
19123
|
-
await
|
|
19208
|
+
await requireConsolePermission(req, "roles-and-permissions");
|
|
19124
19209
|
return;
|
|
19125
19210
|
}
|
|
19126
19211
|
await requireOrgAccess(req, orgId);
|
|
@@ -19162,7 +19247,7 @@ function useRoleController() {
|
|
|
19162
19247
|
}
|
|
19163
19248
|
try {
|
|
19164
19249
|
if (payload.type === PLATFORM_STAFF_ROLE_TYPE) {
|
|
19165
|
-
await
|
|
19250
|
+
await requireConsolePermission(req, "roles-and-permissions", "add-role");
|
|
19166
19251
|
}
|
|
19167
19252
|
if (payload.org) {
|
|
19168
19253
|
await requireOrgReach(req, payload.org);
|
|
@@ -26751,7 +26836,7 @@ async function entitledSites(req) {
|
|
|
26751
26836
|
async function requireMemberOrg(req, org) {
|
|
26752
26837
|
const orgId = org?.toString() ?? "";
|
|
26753
26838
|
if (!orgId) {
|
|
26754
|
-
await
|
|
26839
|
+
await requireConsolePermission(req, "members");
|
|
26755
26840
|
return;
|
|
26756
26841
|
}
|
|
26757
26842
|
await requireOrgAccess(req, orgId);
|
|
@@ -26798,7 +26883,7 @@ function useMemberController() {
|
|
|
26798
26883
|
return;
|
|
26799
26884
|
}
|
|
26800
26885
|
try {
|
|
26801
|
-
await requireSelfOrPlatformStaff(req, userId);
|
|
26886
|
+
await requireSelfOrPlatformStaff(req, userId, { resource: "members", action: "view-members" });
|
|
26802
26887
|
const data = await _getByUserId(userId);
|
|
26803
26888
|
res.json(data);
|
|
26804
26889
|
return;
|
|
@@ -26848,7 +26933,7 @@ function useMemberController() {
|
|
|
26848
26933
|
const user = req.params.id;
|
|
26849
26934
|
const type = req.params.type;
|
|
26850
26935
|
try {
|
|
26851
|
-
await requireSelfOrPlatformStaff(req, user);
|
|
26936
|
+
await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
|
|
26852
26937
|
const data = await _getByUserIdType(user, type);
|
|
26853
26938
|
res.json(data);
|
|
26854
26939
|
return;
|
|
@@ -26894,11 +26979,11 @@ function useMemberController() {
|
|
|
26894
26979
|
}
|
|
26895
26980
|
try {
|
|
26896
26981
|
if (type === "admin") {
|
|
26897
|
-
await
|
|
26982
|
+
await requireConsolePermission(req, "members", "view-members");
|
|
26898
26983
|
} else if (org) {
|
|
26899
26984
|
await requireOrgAccess(req, org);
|
|
26900
26985
|
} else if (user && user !== callerId(req)) {
|
|
26901
|
-
await
|
|
26986
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
26902
26987
|
}
|
|
26903
26988
|
const items = await _getAll({
|
|
26904
26989
|
search,
|
|
@@ -27093,7 +27178,7 @@ function useMemberController() {
|
|
|
27093
27178
|
const type = req.params.type;
|
|
27094
27179
|
const org = req.query.org;
|
|
27095
27180
|
try {
|
|
27096
|
-
await requireSelfOrPlatformStaff(req, user);
|
|
27181
|
+
await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
|
|
27097
27182
|
const data = await _getByUserIdTypeOrg(
|
|
27098
27183
|
user,
|
|
27099
27184
|
type,
|
|
@@ -28928,7 +29013,7 @@ function useOrgController() {
|
|
|
28928
29013
|
return;
|
|
28929
29014
|
}
|
|
28930
29015
|
try {
|
|
28931
|
-
const createdBy = await
|
|
29016
|
+
const createdBy = await requireConsolePermission(req, "organizations");
|
|
28932
29017
|
await _add({ ...req.body, createdBy });
|
|
28933
29018
|
res.status(201).json({ message: "Successfully created organization." });
|
|
28934
29019
|
return;
|
|
@@ -29034,7 +29119,7 @@ function useOrgController() {
|
|
|
29034
29119
|
const type = req.query.type ?? "";
|
|
29035
29120
|
try {
|
|
29036
29121
|
if (user !== callerId(req)) {
|
|
29037
|
-
await
|
|
29122
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29038
29123
|
}
|
|
29039
29124
|
const data = await getOrgsByMembership({
|
|
29040
29125
|
search,
|
|
@@ -29061,7 +29146,7 @@ function useOrgController() {
|
|
|
29061
29146
|
return;
|
|
29062
29147
|
}
|
|
29063
29148
|
try {
|
|
29064
|
-
await
|
|
29149
|
+
await requireConsolePermission(req, "organizations", "see-organization-details");
|
|
29065
29150
|
const data = await _getByName(name);
|
|
29066
29151
|
res.json(data);
|
|
29067
29152
|
return;
|
|
@@ -29099,7 +29184,7 @@ function useOrgController() {
|
|
|
29099
29184
|
return;
|
|
29100
29185
|
}
|
|
29101
29186
|
try {
|
|
29102
|
-
await
|
|
29187
|
+
await requireConsolePermission(req, "organizations", "see-organization-details");
|
|
29103
29188
|
const data = await _getByEmail(email);
|
|
29104
29189
|
if (!data) {
|
|
29105
29190
|
next(new import_node_server_utils64.NotFoundError("Organization not found."));
|
|
@@ -29129,7 +29214,7 @@ function useOrgController() {
|
|
|
29129
29214
|
try {
|
|
29130
29215
|
const self = await _getUserById(callerId(req)).catch(() => null);
|
|
29131
29216
|
if (!self?.email || self.email.toLowerCase() !== email.toLowerCase()) {
|
|
29132
|
-
await
|
|
29217
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29133
29218
|
}
|
|
29134
29219
|
const data = await _getOrgsByEmail(email);
|
|
29135
29220
|
res.json(data);
|
|
@@ -29189,7 +29274,7 @@ function useOrgController() {
|
|
|
29189
29274
|
const orgId = req.params.id;
|
|
29190
29275
|
const { status } = req.body;
|
|
29191
29276
|
try {
|
|
29192
|
-
const ownerId = await requirePlatformOwner(req);
|
|
29277
|
+
const ownerId = await requirePlatformOwner(req, { resource: "organizations" });
|
|
29193
29278
|
await _updateStatusById(orgId, status);
|
|
29194
29279
|
const subscription = await _getSubscriptionByOrgId(orgId);
|
|
29195
29280
|
if (subscription) {
|
|
@@ -29260,7 +29345,7 @@ function useOrgControllerV2() {
|
|
|
29260
29345
|
const nature = value.nature ?? "";
|
|
29261
29346
|
const status = value.status;
|
|
29262
29347
|
try {
|
|
29263
|
-
await
|
|
29348
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29264
29349
|
const data = await _getAll({
|
|
29265
29350
|
search,
|
|
29266
29351
|
page,
|
|
@@ -29297,7 +29382,7 @@ function useOrgControllerV2() {
|
|
|
29297
29382
|
return;
|
|
29298
29383
|
}
|
|
29299
29384
|
try {
|
|
29300
|
-
await
|
|
29385
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29301
29386
|
const data = await _getOrganizationsWithSubscription({
|
|
29302
29387
|
search: value.search ?? "",
|
|
29303
29388
|
page: value.page ?? 1,
|
|
@@ -31759,7 +31844,7 @@ function useSubscriptionController() {
|
|
|
31759
31844
|
return;
|
|
31760
31845
|
}
|
|
31761
31846
|
try {
|
|
31762
|
-
await
|
|
31847
|
+
await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31763
31848
|
const id = await _add(payload);
|
|
31764
31849
|
res.status(201).json({ message: "Successfully added subscription.", id });
|
|
31765
31850
|
return;
|
|
@@ -31806,7 +31891,7 @@ function useSubscriptionController() {
|
|
|
31806
31891
|
const page = parseInt(req.query.page ?? "1");
|
|
31807
31892
|
const status = req.query.status ?? "active";
|
|
31808
31893
|
try {
|
|
31809
|
-
await
|
|
31894
|
+
await requireConsolePermission(req, "subscriptions", "see-all-subscriptions");
|
|
31810
31895
|
const data = await _getSubscriptions({ search, page, status });
|
|
31811
31896
|
res.json(data);
|
|
31812
31897
|
return;
|
|
@@ -31940,7 +32025,7 @@ function useSubscriptionController() {
|
|
|
31940
32025
|
}
|
|
31941
32026
|
async function createConsoleSubscription(req, res, next) {
|
|
31942
32027
|
try {
|
|
31943
|
-
const staffId = await
|
|
32028
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31944
32029
|
const form = await readConsoleForm(req);
|
|
31945
32030
|
const existing = await _getByOrgId(form.orgId);
|
|
31946
32031
|
if (existing && existing.status !== "ended") {
|
|
@@ -31986,7 +32071,7 @@ function useSubscriptionController() {
|
|
|
31986
32071
|
}
|
|
31987
32072
|
async function updateConsoleSubscription(req, res, next) {
|
|
31988
32073
|
try {
|
|
31989
|
-
const staffId = await
|
|
32074
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31990
32075
|
const form = await readConsoleForm(req);
|
|
31991
32076
|
const existing = await _getByOrgId(form.orgId);
|
|
31992
32077
|
if (!existing?._id) {
|
|
@@ -32026,7 +32111,7 @@ function useSubscriptionController() {
|
|
|
32026
32111
|
}
|
|
32027
32112
|
async function getConsoleSubscription(req, res, next) {
|
|
32028
32113
|
try {
|
|
32029
|
-
await
|
|
32114
|
+
await requireConsolePermission(req, "subscriptions", "see-subscription-details");
|
|
32030
32115
|
const orgId = req.params.id;
|
|
32031
32116
|
if (!/^[0-9a-fA-F]{24}$/.test(orgId ?? "")) {
|
|
32032
32117
|
throw new import_node_server_utils80.BadRequestError("That client could not be found.");
|
|
@@ -32095,7 +32180,7 @@ function useSubscriptionPlanController() {
|
|
|
32095
32180
|
return;
|
|
32096
32181
|
}
|
|
32097
32182
|
try {
|
|
32098
|
-
const staffId = await
|
|
32183
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32099
32184
|
const _id = await _add(req.body);
|
|
32100
32185
|
const data = await _getById(_id);
|
|
32101
32186
|
await recordConsoleAction({
|
|
@@ -32191,7 +32276,7 @@ function useSubscriptionPlanController() {
|
|
|
32191
32276
|
}
|
|
32192
32277
|
const id = req.params.id;
|
|
32193
32278
|
try {
|
|
32194
|
-
const staffId = await
|
|
32279
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32195
32280
|
const before = await _getById(id);
|
|
32196
32281
|
await _update(id, req.body);
|
|
32197
32282
|
const data = await _getById(id);
|
|
@@ -32223,7 +32308,7 @@ function useSubscriptionPlanController() {
|
|
|
32223
32308
|
const id = req.params.id;
|
|
32224
32309
|
const { status } = req.body;
|
|
32225
32310
|
try {
|
|
32226
|
-
const staffId = await
|
|
32311
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32227
32312
|
await _updateStatusById(id, status);
|
|
32228
32313
|
const data = await _getById(id);
|
|
32229
32314
|
await recordConsoleAction({
|
|
@@ -32364,7 +32449,7 @@ function usePromoCodeController() {
|
|
|
32364
32449
|
payload.code = payload.code.trim().toUpperCase();
|
|
32365
32450
|
payload.fixed_rate = parseInt(payload.fixed_rate ?? "0");
|
|
32366
32451
|
try {
|
|
32367
|
-
const staffId = await
|
|
32452
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "create-promo-code");
|
|
32368
32453
|
const created = await _add(payload);
|
|
32369
32454
|
await recordConsoleAction({
|
|
32370
32455
|
action: "promo-code.created" /* PROMO_CODE_CREATED */,
|
|
@@ -32417,7 +32502,7 @@ function usePromoCodeController() {
|
|
|
32417
32502
|
return;
|
|
32418
32503
|
}
|
|
32419
32504
|
try {
|
|
32420
|
-
await
|
|
32505
|
+
await requireConsolePermission(req, "promo-codes", "see-promo-code-details");
|
|
32421
32506
|
const data = await _getById(_id);
|
|
32422
32507
|
res.json(data);
|
|
32423
32508
|
return;
|
|
@@ -32446,7 +32531,7 @@ function usePromoCodeController() {
|
|
|
32446
32531
|
const limit = parseInt(req.query.limit ?? "10");
|
|
32447
32532
|
const status = req.query.status ?? "active";
|
|
32448
32533
|
try {
|
|
32449
|
-
await
|
|
32534
|
+
await requireConsolePermission(req, "promo-codes");
|
|
32450
32535
|
const data = await _getPromoCodes({
|
|
32451
32536
|
search,
|
|
32452
32537
|
page,
|
|
@@ -32471,7 +32556,7 @@ function usePromoCodeController() {
|
|
|
32471
32556
|
return;
|
|
32472
32557
|
}
|
|
32473
32558
|
try {
|
|
32474
|
-
const staffId = await
|
|
32559
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "edit-promo-code-details");
|
|
32475
32560
|
const before = await _getById(req.params.id);
|
|
32476
32561
|
await _updateById(req.params.id, req.body);
|
|
32477
32562
|
await recordConsoleAction({
|
|
@@ -32507,7 +32592,7 @@ function usePromoCodeController() {
|
|
|
32507
32592
|
return;
|
|
32508
32593
|
}
|
|
32509
32594
|
try {
|
|
32510
|
-
const staffId = await
|
|
32595
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "change-promo-code-status");
|
|
32511
32596
|
await _updateStatusById(req.params.id, status.value.status);
|
|
32512
32597
|
await recordConsoleAction({
|
|
32513
32598
|
action: "promo-code.status-changed" /* PROMO_CODE_STATUS_CHANGED */,
|
|
@@ -32536,7 +32621,7 @@ function usePromoCodeController() {
|
|
|
32536
32621
|
return;
|
|
32537
32622
|
}
|
|
32538
32623
|
try {
|
|
32539
|
-
const staffId = await
|
|
32624
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "delete-promo-code");
|
|
32540
32625
|
await _softDeleteById(req.params.id, staffId);
|
|
32541
32626
|
await recordConsoleAction({
|
|
32542
32627
|
action: "promo-code.removed" /* PROMO_CODE_REMOVED */,
|
|
@@ -86346,7 +86431,7 @@ function useUserControllerV2() {
|
|
|
86346
86431
|
return;
|
|
86347
86432
|
}
|
|
86348
86433
|
try {
|
|
86349
|
-
await requireSelfOrPlatformStaff(req, value);
|
|
86434
|
+
await requireSelfOrPlatformStaff(req, value, { resource: "users", action: "see-user-details" });
|
|
86350
86435
|
const user = await _getById(value);
|
|
86351
86436
|
res.json(user);
|
|
86352
86437
|
return;
|
|
@@ -86383,7 +86468,7 @@ function useUserControllerV2() {
|
|
|
86383
86468
|
if (error)
|
|
86384
86469
|
return rejectValidation(error, next);
|
|
86385
86470
|
try {
|
|
86386
|
-
await
|
|
86471
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
86387
86472
|
const users = await _getUsers({
|
|
86388
86473
|
search: value.search ?? "",
|
|
86389
86474
|
page: value.page,
|
|
@@ -86508,7 +86593,7 @@ function useUserControllerV2() {
|
|
|
86508
86593
|
return;
|
|
86509
86594
|
}
|
|
86510
86595
|
try {
|
|
86511
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
86596
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
86512
86597
|
const message = await _updateBirthday({ _id, ...payload });
|
|
86513
86598
|
res.json({ message });
|
|
86514
86599
|
return;
|
|
@@ -86540,7 +86625,7 @@ function useUserControllerV2() {
|
|
|
86540
86625
|
return;
|
|
86541
86626
|
}
|
|
86542
86627
|
try {
|
|
86543
|
-
await requireUserFieldWrite(req, _id, payload.field);
|
|
86628
|
+
await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
|
|
86544
86629
|
const message = await _updateUserFieldById({ _id, ...payload });
|
|
86545
86630
|
res.json({ message });
|
|
86546
86631
|
return;
|
|
@@ -86571,7 +86656,7 @@ function useUserControllerV2() {
|
|
|
86571
86656
|
const newPassword = req.body.newPassword ?? "";
|
|
86572
86657
|
const passwordConfirmation = req.body.passwordConfirmation ?? "";
|
|
86573
86658
|
try {
|
|
86574
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
86659
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
86575
86660
|
await _updatePasswordById(
|
|
86576
86661
|
_id,
|
|
86577
86662
|
currentPassword,
|
|
@@ -86749,7 +86834,7 @@ function useRoleControllerV2() {
|
|
|
86749
86834
|
}
|
|
86750
86835
|
try {
|
|
86751
86836
|
if (value.type === PLATFORM_STAFF_ROLE_TYPE) {
|
|
86752
|
-
await
|
|
86837
|
+
await requireConsolePermission(req, "roles-and-permissions", "add-role");
|
|
86753
86838
|
}
|
|
86754
86839
|
if (value.org) {
|
|
86755
86840
|
await requireOrgReach(req, value.org);
|
|
@@ -91425,7 +91510,7 @@ function usePlatformTermsController() {
|
|
|
91425
91510
|
return id;
|
|
91426
91511
|
}
|
|
91427
91512
|
if (staffMayRead) {
|
|
91428
|
-
return await
|
|
91513
|
+
return await requireConsolePermission(req, "platform-terms", "see-platform-terms");
|
|
91429
91514
|
}
|
|
91430
91515
|
throw new import_node_server_utils298.UnauthorizedError("Not authorized.");
|
|
91431
91516
|
}
|
|
@@ -91517,7 +91602,7 @@ function usePlatformTermsController() {
|
|
|
91517
91602
|
return;
|
|
91518
91603
|
}
|
|
91519
91604
|
try {
|
|
91520
|
-
await
|
|
91605
|
+
await requireConsolePermission(req, "platform-terms", "see-platform-terms");
|
|
91521
91606
|
res.json(
|
|
91522
91607
|
await _listAcceptance({
|
|
91523
91608
|
version: value.version || null,
|
|
@@ -91549,7 +91634,7 @@ function usePlatformTermsController() {
|
|
|
91549
91634
|
return;
|
|
91550
91635
|
}
|
|
91551
91636
|
try {
|
|
91552
|
-
const staffId = await
|
|
91637
|
+
const staffId = await requireConsolePermission(req, "platform-terms", "edit-platform-terms");
|
|
91553
91638
|
const created = await _add({
|
|
91554
91639
|
terms: value.terms,
|
|
91555
91640
|
policies: value.policies,
|
|
@@ -91607,7 +91692,7 @@ function useConsoleAuditController() {
|
|
|
91607
91692
|
}
|
|
91608
91693
|
const to = value.to && value.to.length === 10 ? `${value.to}T23:59:59.999Z` : value.to;
|
|
91609
91694
|
try {
|
|
91610
|
-
await
|
|
91695
|
+
await requireConsolePermission(req, "activity-history", "see-activity-history");
|
|
91611
91696
|
res.json(
|
|
91612
91697
|
await _list({
|
|
91613
91698
|
org: value.org || "",
|
|
@@ -92270,6 +92355,7 @@ function useNotificationPreferenceController() {
|
|
|
92270
92355
|
resolveHidPhysicalCardValue,
|
|
92271
92356
|
resolveInviteActor,
|
|
92272
92357
|
resolveSiteTimezone,
|
|
92358
|
+
resolveStaffRole,
|
|
92273
92359
|
robotSchema,
|
|
92274
92360
|
rtspUrl,
|
|
92275
92361
|
schema,
|