@7365admin1/core 3.53.2 → 3.53.4
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 +35 -0
- package/dist/index.d.ts +143 -1
- package/dist/index.js +183 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -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/sp-approvals-console-gate.test.mjs +117 -0
- package/test/staff-console-authz.test.mjs +25 -25
- package/test/terms-acceptance-list.test.mjs +2 -2
package/dist/index.js
CHANGED
|
@@ -5926,6 +5926,7 @@ __export(src_exports, {
|
|
|
5926
5926
|
CLIENT_ACTIONS: () => CLIENT_ACTIONS,
|
|
5927
5927
|
CLOCK_DRIFT_WARN_SECONDS: () => CLOCK_DRIFT_WARN_SECONDS,
|
|
5928
5928
|
CONSOLE_AUDIT_LABELS: () => CONSOLE_AUDIT_LABELS,
|
|
5929
|
+
CONSOLE_PERMISSIONS: () => CONSOLE_PERMISSIONS,
|
|
5929
5930
|
CONTRACTOR_TYPE_LABELS: () => CONTRACTOR_TYPE_LABELS,
|
|
5930
5931
|
CURRENT_TIME_ENDPOINT: () => CURRENT_TIME_ENDPOINT,
|
|
5931
5932
|
CameraType: () => CameraType,
|
|
@@ -6138,6 +6139,9 @@ __export(src_exports, {
|
|
|
6138
6139
|
chatSchema: () => chatSchema,
|
|
6139
6140
|
clampPtzSpeed: () => clampPtzSpeed,
|
|
6140
6141
|
clockDriftSeconds: () => clockDriftSeconds,
|
|
6142
|
+
consoleRoleAllows: () => consoleRoleAllows,
|
|
6143
|
+
consoleRoleAllowsAll: () => consoleRoleAllowsAll,
|
|
6144
|
+
consoleSpellings: () => consoleSpellings,
|
|
6141
6145
|
console_audit_namespace_collection: () => console_audit_namespace_collection,
|
|
6142
6146
|
createManpowerRemarksDaily: () => createManpowerRemarksDaily,
|
|
6143
6147
|
customerSchema: () => customerSchema,
|
|
@@ -6237,6 +6241,8 @@ __export(src_exports, {
|
|
|
6237
6241
|
relayForRecorder: () => relayForRecorder,
|
|
6238
6242
|
remarksSchema: () => remarksSchema,
|
|
6239
6243
|
renderPagePdf: () => renderPagePdf,
|
|
6244
|
+
requireConsolePermission: () => requireConsolePermission,
|
|
6245
|
+
requirePlatformStaff: () => requirePlatformStaff,
|
|
6240
6246
|
resetCameraTransports: () => resetCameraTransports,
|
|
6241
6247
|
residentAppModuleKeys: () => residentAppModuleKeys,
|
|
6242
6248
|
residentFormEntry: () => residentFormEntry,
|
|
@@ -6246,6 +6252,7 @@ __export(src_exports, {
|
|
|
6246
6252
|
resolveHidPhysicalCardValue: () => resolveHidPhysicalCardValue,
|
|
6247
6253
|
resolveInviteActor: () => resolveInviteActor,
|
|
6248
6254
|
resolveSiteTimezone: () => resolveSiteTimezone,
|
|
6255
|
+
resolveStaffRole: () => resolveStaffRole,
|
|
6249
6256
|
robotSchema: () => robotSchema,
|
|
6250
6257
|
rtspUrl: () => rtspUrl,
|
|
6251
6258
|
schema: () => schema,
|
|
@@ -10926,39 +10933,28 @@ var import_mongodb15 = require("mongodb");
|
|
|
10926
10933
|
var import_node_server_utils15 = require("@7365admin1/node-server-utils");
|
|
10927
10934
|
var import_mongodb14 = require("mongodb");
|
|
10928
10935
|
var LIVE_ROLE = { status: { $ne: "deleted" } };
|
|
10929
|
-
async function
|
|
10936
|
+
async function resolveStaffRole(userId) {
|
|
10930
10937
|
const id = userId?.toString() ?? "";
|
|
10931
10938
|
if (!id || !import_mongodb14.ObjectId.isValid(id))
|
|
10932
|
-
return
|
|
10939
|
+
return null;
|
|
10933
10940
|
const db2 = import_node_server_utils15.useAtlas.getDb();
|
|
10934
10941
|
if (!db2)
|
|
10935
|
-
return
|
|
10942
|
+
return null;
|
|
10936
10943
|
const member = await db2.collection("members").findOne({
|
|
10937
10944
|
user: new import_mongodb14.ObjectId(id),
|
|
10938
10945
|
type: "admin",
|
|
10939
10946
|
status: { $ne: "deleted" }
|
|
10940
10947
|
});
|
|
10941
10948
|
if (!member?.role || !import_mongodb14.ObjectId.isValid(member.role.toString()))
|
|
10942
|
-
return
|
|
10949
|
+
return null;
|
|
10943
10950
|
const role = await db2.collection("roles").findOne({ _id: new import_mongodb14.ObjectId(member.role.toString()), ...LIVE_ROLE });
|
|
10944
|
-
return role?.type === "admin";
|
|
10951
|
+
return role?.type === "admin" ? role : null;
|
|
10952
|
+
}
|
|
10953
|
+
async function isSuperAdmin(userId) {
|
|
10954
|
+
return await resolveStaffRole(userId) !== null;
|
|
10945
10955
|
}
|
|
10946
10956
|
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;
|
|
10957
|
+
return (await resolveStaffRole(userId))?.default === true;
|
|
10962
10958
|
}
|
|
10963
10959
|
|
|
10964
10960
|
// src/utils/org-suspension.util.ts
|
|
@@ -18661,32 +18657,127 @@ function usePersonRepo() {
|
|
|
18661
18657
|
|
|
18662
18658
|
// src/utils/console-authz.util.ts
|
|
18663
18659
|
var import_node_server_utils42 = require("@7365admin1/node-server-utils");
|
|
18660
|
+
|
|
18661
|
+
// src/utils/console-permission.util.ts
|
|
18662
|
+
var CONSOLE_PERMISSIONS = Object.freeze({
|
|
18663
|
+
organizations: Object.freeze([
|
|
18664
|
+
"see-all-organizations",
|
|
18665
|
+
"see-organization-details"
|
|
18666
|
+
]),
|
|
18667
|
+
"promo-codes": Object.freeze([
|
|
18668
|
+
"create-promo-code",
|
|
18669
|
+
"see-promo-code-details",
|
|
18670
|
+
"edit-promo-code-details",
|
|
18671
|
+
"change-promo-code-status",
|
|
18672
|
+
"delete-promo-code"
|
|
18673
|
+
]),
|
|
18674
|
+
users: Object.freeze(["see-all-users", "see-user-details"]),
|
|
18675
|
+
invitations: Object.freeze([
|
|
18676
|
+
"create-invitation",
|
|
18677
|
+
"view-invitations",
|
|
18678
|
+
"cancel-invitation"
|
|
18679
|
+
]),
|
|
18680
|
+
subscriptions: Object.freeze([
|
|
18681
|
+
"see-all-subscriptions",
|
|
18682
|
+
"see-subscription-details",
|
|
18683
|
+
"manage-subscription"
|
|
18684
|
+
]),
|
|
18685
|
+
"sp-approvals": Object.freeze([
|
|
18686
|
+
"see-all-sp-approvals",
|
|
18687
|
+
"approve-sp",
|
|
18688
|
+
"reject-sp",
|
|
18689
|
+
"delete-sp-approval"
|
|
18690
|
+
]),
|
|
18691
|
+
"marketplace-vendors": Object.freeze([
|
|
18692
|
+
"see-all-marketplace-vendors",
|
|
18693
|
+
"see-marketplace-vendor-details"
|
|
18694
|
+
]),
|
|
18695
|
+
"platform-terms": Object.freeze([
|
|
18696
|
+
"see-platform-terms",
|
|
18697
|
+
"edit-platform-terms"
|
|
18698
|
+
]),
|
|
18699
|
+
"activity-history": Object.freeze(["see-activity-history"]),
|
|
18700
|
+
members: Object.freeze([
|
|
18701
|
+
"view-members",
|
|
18702
|
+
"assign-member-role",
|
|
18703
|
+
"suspend-member",
|
|
18704
|
+
"activate-member",
|
|
18705
|
+
"delete-member"
|
|
18706
|
+
]),
|
|
18707
|
+
"roles-and-permissions": Object.freeze([
|
|
18708
|
+
"add-role",
|
|
18709
|
+
"see-all-roles",
|
|
18710
|
+
"see-role-details",
|
|
18711
|
+
"update-role",
|
|
18712
|
+
"delete-role"
|
|
18713
|
+
])
|
|
18714
|
+
});
|
|
18715
|
+
var RESOURCE_SPELLINGS = Object.freeze({
|
|
18716
|
+
"roles-and-permissions": Object.freeze([
|
|
18717
|
+
"roles-and-permissions",
|
|
18718
|
+
"roles"
|
|
18719
|
+
]),
|
|
18720
|
+
roles: Object.freeze(["roles", "roles-and-permissions"])
|
|
18721
|
+
});
|
|
18722
|
+
function consoleSpellings(resource, action) {
|
|
18723
|
+
const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
|
|
18724
|
+
return resources.map((name) => `${name}:${action}`);
|
|
18725
|
+
}
|
|
18726
|
+
function consoleRoleAllowsAll(held) {
|
|
18727
|
+
if (!Array.isArray(held) || held.length === 0)
|
|
18728
|
+
return true;
|
|
18729
|
+
return held.includes("*");
|
|
18730
|
+
}
|
|
18731
|
+
function consoleRoleAllows(held, resource, action) {
|
|
18732
|
+
if (consoleRoleAllowsAll(held))
|
|
18733
|
+
return true;
|
|
18734
|
+
const actions = CONSOLE_PERMISSIONS[resource];
|
|
18735
|
+
if (!actions?.length)
|
|
18736
|
+
return false;
|
|
18737
|
+
const wanted = action ? actions.includes(action) ? [action] : [] : actions;
|
|
18738
|
+
return wanted.some(
|
|
18739
|
+
(name) => consoleSpellings(resource, name).some(
|
|
18740
|
+
(spelling) => held.includes(spelling)
|
|
18741
|
+
)
|
|
18742
|
+
);
|
|
18743
|
+
}
|
|
18744
|
+
|
|
18745
|
+
// src/utils/console-authz.util.ts
|
|
18664
18746
|
function callerId(req) {
|
|
18665
18747
|
const user = req.user;
|
|
18666
18748
|
return user?.user?.toString?.() || user?._id?.toString?.() || "";
|
|
18667
18749
|
}
|
|
18668
|
-
async function requirePlatformStaff(req) {
|
|
18750
|
+
async function requirePlatformStaff(req, grant) {
|
|
18669
18751
|
const id = callerId(req);
|
|
18670
|
-
|
|
18752
|
+
const role = id ? await resolveStaffRole(id) : null;
|
|
18753
|
+
if (!role) {
|
|
18754
|
+
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18755
|
+
}
|
|
18756
|
+
if (grant && !consoleRoleAllows(role.permissions, grant.resource, grant.action)) {
|
|
18671
18757
|
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18672
18758
|
}
|
|
18673
18759
|
return id;
|
|
18674
18760
|
}
|
|
18675
|
-
async function
|
|
18761
|
+
async function requireConsolePermission(req, resource, action) {
|
|
18762
|
+
return await requirePlatformStaff(req, { resource, action });
|
|
18763
|
+
}
|
|
18764
|
+
async function requireSelfOrPlatformStaff(req, userId, grant) {
|
|
18676
18765
|
const id = callerId(req);
|
|
18677
18766
|
const target = userId?.toString() ?? "";
|
|
18678
18767
|
if (id && target && target === id)
|
|
18679
18768
|
return id;
|
|
18680
|
-
return await requirePlatformStaff(req);
|
|
18769
|
+
return await requirePlatformStaff(req, grant);
|
|
18681
18770
|
}
|
|
18682
18771
|
async function requireOrgAccess(req, orgId) {
|
|
18683
18772
|
return await requireOrgReach(req, orgId);
|
|
18684
18773
|
}
|
|
18685
|
-
async function requirePlatformOwner(req) {
|
|
18774
|
+
async function requirePlatformOwner(req, grant) {
|
|
18686
18775
|
const id = callerId(req);
|
|
18687
18776
|
if (!id || !await isPlatformOwner(id)) {
|
|
18688
18777
|
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18689
18778
|
}
|
|
18779
|
+
if (grant)
|
|
18780
|
+
await requirePlatformStaff(req, grant);
|
|
18690
18781
|
return id;
|
|
18691
18782
|
}
|
|
18692
18783
|
async function requireOrgReach(req, orgId) {
|
|
@@ -18713,10 +18804,10 @@ async function requireInviteReach(req, org, app) {
|
|
|
18713
18804
|
if (org)
|
|
18714
18805
|
await requireOrgReach(req, org);
|
|
18715
18806
|
}
|
|
18716
|
-
async function requireUserFieldWrite(req, userId, field) {
|
|
18807
|
+
async function requireUserFieldWrite(req, userId, field, grant) {
|
|
18717
18808
|
if (field === "email")
|
|
18718
|
-
return await requirePlatformStaff(req);
|
|
18719
|
-
return await requireSelfOrPlatformStaff(req, userId);
|
|
18809
|
+
return await requirePlatformStaff(req, grant);
|
|
18810
|
+
return await requireSelfOrPlatformStaff(req, userId, grant);
|
|
18720
18811
|
}
|
|
18721
18812
|
|
|
18722
18813
|
// src/utils/user-response.util.ts
|
|
@@ -18756,7 +18847,7 @@ function useUserController() {
|
|
|
18756
18847
|
return;
|
|
18757
18848
|
}
|
|
18758
18849
|
try {
|
|
18759
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
18850
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users", action: "see-user-details" });
|
|
18760
18851
|
const user = await _getById(_id);
|
|
18761
18852
|
res.json(user);
|
|
18762
18853
|
return;
|
|
@@ -18841,7 +18932,7 @@ function useUserController() {
|
|
|
18841
18932
|
const page = parseInt(req.query.page ?? "1");
|
|
18842
18933
|
const status = req.query.status ?? "active";
|
|
18843
18934
|
try {
|
|
18844
|
-
await
|
|
18935
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
18845
18936
|
const data = await _getUsers({ search, page, status });
|
|
18846
18937
|
res.json(data);
|
|
18847
18938
|
return;
|
|
@@ -18936,7 +19027,7 @@ function useUserController() {
|
|
|
18936
19027
|
return;
|
|
18937
19028
|
}
|
|
18938
19029
|
try {
|
|
18939
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
19030
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
18940
19031
|
const message = await _updateBirthday({ _id, ...payload });
|
|
18941
19032
|
res.json({ message });
|
|
18942
19033
|
return;
|
|
@@ -18978,7 +19069,7 @@ function useUserController() {
|
|
|
18978
19069
|
return;
|
|
18979
19070
|
}
|
|
18980
19071
|
try {
|
|
18981
|
-
await requireUserFieldWrite(req, _id, payload.field);
|
|
19072
|
+
await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
|
|
18982
19073
|
let message;
|
|
18983
19074
|
if (payload.field === "plateNumber") {
|
|
18984
19075
|
message = await updatePlateNumberByUserId(
|
|
@@ -19020,7 +19111,7 @@ function useUserController() {
|
|
|
19020
19111
|
const newPassword = req.body.newPassword ?? "";
|
|
19021
19112
|
const passwordConfirmation = req.body.passwordConfirmation ?? "";
|
|
19022
19113
|
try {
|
|
19023
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
19114
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
19024
19115
|
await _updatePasswordById(
|
|
19025
19116
|
_id,
|
|
19026
19117
|
currentPassword,
|
|
@@ -19120,7 +19211,7 @@ function useRoleService() {
|
|
|
19120
19211
|
async function requireRoleOrg(req, org) {
|
|
19121
19212
|
const orgId = org?.toString() ?? "";
|
|
19122
19213
|
if (!orgId) {
|
|
19123
|
-
await
|
|
19214
|
+
await requireConsolePermission(req, "roles-and-permissions");
|
|
19124
19215
|
return;
|
|
19125
19216
|
}
|
|
19126
19217
|
await requireOrgAccess(req, orgId);
|
|
@@ -19162,7 +19253,7 @@ function useRoleController() {
|
|
|
19162
19253
|
}
|
|
19163
19254
|
try {
|
|
19164
19255
|
if (payload.type === PLATFORM_STAFF_ROLE_TYPE) {
|
|
19165
|
-
await
|
|
19256
|
+
await requireConsolePermission(req, "roles-and-permissions", "add-role");
|
|
19166
19257
|
}
|
|
19167
19258
|
if (payload.org) {
|
|
19168
19259
|
await requireOrgReach(req, payload.org);
|
|
@@ -26751,7 +26842,7 @@ async function entitledSites(req) {
|
|
|
26751
26842
|
async function requireMemberOrg(req, org) {
|
|
26752
26843
|
const orgId = org?.toString() ?? "";
|
|
26753
26844
|
if (!orgId) {
|
|
26754
|
-
await
|
|
26845
|
+
await requireConsolePermission(req, "members");
|
|
26755
26846
|
return;
|
|
26756
26847
|
}
|
|
26757
26848
|
await requireOrgAccess(req, orgId);
|
|
@@ -26798,7 +26889,7 @@ function useMemberController() {
|
|
|
26798
26889
|
return;
|
|
26799
26890
|
}
|
|
26800
26891
|
try {
|
|
26801
|
-
await requireSelfOrPlatformStaff(req, userId);
|
|
26892
|
+
await requireSelfOrPlatformStaff(req, userId, { resource: "members", action: "view-members" });
|
|
26802
26893
|
const data = await _getByUserId(userId);
|
|
26803
26894
|
res.json(data);
|
|
26804
26895
|
return;
|
|
@@ -26848,7 +26939,7 @@ function useMemberController() {
|
|
|
26848
26939
|
const user = req.params.id;
|
|
26849
26940
|
const type = req.params.type;
|
|
26850
26941
|
try {
|
|
26851
|
-
await requireSelfOrPlatformStaff(req, user);
|
|
26942
|
+
await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
|
|
26852
26943
|
const data = await _getByUserIdType(user, type);
|
|
26853
26944
|
res.json(data);
|
|
26854
26945
|
return;
|
|
@@ -26894,11 +26985,11 @@ function useMemberController() {
|
|
|
26894
26985
|
}
|
|
26895
26986
|
try {
|
|
26896
26987
|
if (type === "admin") {
|
|
26897
|
-
await
|
|
26988
|
+
await requireConsolePermission(req, "members", "view-members");
|
|
26898
26989
|
} else if (org) {
|
|
26899
26990
|
await requireOrgAccess(req, org);
|
|
26900
26991
|
} else if (user && user !== callerId(req)) {
|
|
26901
|
-
await
|
|
26992
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
26902
26993
|
}
|
|
26903
26994
|
const items = await _getAll({
|
|
26904
26995
|
search,
|
|
@@ -27093,7 +27184,7 @@ function useMemberController() {
|
|
|
27093
27184
|
const type = req.params.type;
|
|
27094
27185
|
const org = req.query.org;
|
|
27095
27186
|
try {
|
|
27096
|
-
await requireSelfOrPlatformStaff(req, user);
|
|
27187
|
+
await requireSelfOrPlatformStaff(req, user, { resource: "members", action: "view-members" });
|
|
27097
27188
|
const data = await _getByUserIdTypeOrg(
|
|
27098
27189
|
user,
|
|
27099
27190
|
type,
|
|
@@ -28928,7 +29019,7 @@ function useOrgController() {
|
|
|
28928
29019
|
return;
|
|
28929
29020
|
}
|
|
28930
29021
|
try {
|
|
28931
|
-
const createdBy = await
|
|
29022
|
+
const createdBy = await requireConsolePermission(req, "organizations");
|
|
28932
29023
|
await _add({ ...req.body, createdBy });
|
|
28933
29024
|
res.status(201).json({ message: "Successfully created organization." });
|
|
28934
29025
|
return;
|
|
@@ -29034,7 +29125,7 @@ function useOrgController() {
|
|
|
29034
29125
|
const type = req.query.type ?? "";
|
|
29035
29126
|
try {
|
|
29036
29127
|
if (user !== callerId(req)) {
|
|
29037
|
-
await
|
|
29128
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29038
29129
|
}
|
|
29039
29130
|
const data = await getOrgsByMembership({
|
|
29040
29131
|
search,
|
|
@@ -29061,7 +29152,7 @@ function useOrgController() {
|
|
|
29061
29152
|
return;
|
|
29062
29153
|
}
|
|
29063
29154
|
try {
|
|
29064
|
-
await
|
|
29155
|
+
await requireConsolePermission(req, "organizations", "see-organization-details");
|
|
29065
29156
|
const data = await _getByName(name);
|
|
29066
29157
|
res.json(data);
|
|
29067
29158
|
return;
|
|
@@ -29099,7 +29190,7 @@ function useOrgController() {
|
|
|
29099
29190
|
return;
|
|
29100
29191
|
}
|
|
29101
29192
|
try {
|
|
29102
|
-
await
|
|
29193
|
+
await requireConsolePermission(req, "organizations", "see-organization-details");
|
|
29103
29194
|
const data = await _getByEmail(email);
|
|
29104
29195
|
if (!data) {
|
|
29105
29196
|
next(new import_node_server_utils64.NotFoundError("Organization not found."));
|
|
@@ -29129,7 +29220,7 @@ function useOrgController() {
|
|
|
29129
29220
|
try {
|
|
29130
29221
|
const self = await _getUserById(callerId(req)).catch(() => null);
|
|
29131
29222
|
if (!self?.email || self.email.toLowerCase() !== email.toLowerCase()) {
|
|
29132
|
-
await
|
|
29223
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29133
29224
|
}
|
|
29134
29225
|
const data = await _getOrgsByEmail(email);
|
|
29135
29226
|
res.json(data);
|
|
@@ -29189,7 +29280,7 @@ function useOrgController() {
|
|
|
29189
29280
|
const orgId = req.params.id;
|
|
29190
29281
|
const { status } = req.body;
|
|
29191
29282
|
try {
|
|
29192
|
-
const ownerId = await requirePlatformOwner(req);
|
|
29283
|
+
const ownerId = await requirePlatformOwner(req, { resource: "organizations" });
|
|
29193
29284
|
await _updateStatusById(orgId, status);
|
|
29194
29285
|
const subscription = await _getSubscriptionByOrgId(orgId);
|
|
29195
29286
|
if (subscription) {
|
|
@@ -29260,7 +29351,7 @@ function useOrgControllerV2() {
|
|
|
29260
29351
|
const nature = value.nature ?? "";
|
|
29261
29352
|
const status = value.status;
|
|
29262
29353
|
try {
|
|
29263
|
-
await
|
|
29354
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29264
29355
|
const data = await _getAll({
|
|
29265
29356
|
search,
|
|
29266
29357
|
page,
|
|
@@ -29297,7 +29388,7 @@ function useOrgControllerV2() {
|
|
|
29297
29388
|
return;
|
|
29298
29389
|
}
|
|
29299
29390
|
try {
|
|
29300
|
-
await
|
|
29391
|
+
await requireConsolePermission(req, "organizations", "see-all-organizations");
|
|
29301
29392
|
const data = await _getOrganizationsWithSubscription({
|
|
29302
29393
|
search: value.search ?? "",
|
|
29303
29394
|
page: value.page ?? 1,
|
|
@@ -31759,7 +31850,7 @@ function useSubscriptionController() {
|
|
|
31759
31850
|
return;
|
|
31760
31851
|
}
|
|
31761
31852
|
try {
|
|
31762
|
-
await
|
|
31853
|
+
await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31763
31854
|
const id = await _add(payload);
|
|
31764
31855
|
res.status(201).json({ message: "Successfully added subscription.", id });
|
|
31765
31856
|
return;
|
|
@@ -31806,7 +31897,7 @@ function useSubscriptionController() {
|
|
|
31806
31897
|
const page = parseInt(req.query.page ?? "1");
|
|
31807
31898
|
const status = req.query.status ?? "active";
|
|
31808
31899
|
try {
|
|
31809
|
-
await
|
|
31900
|
+
await requireConsolePermission(req, "subscriptions", "see-all-subscriptions");
|
|
31810
31901
|
const data = await _getSubscriptions({ search, page, status });
|
|
31811
31902
|
res.json(data);
|
|
31812
31903
|
return;
|
|
@@ -31940,7 +32031,7 @@ function useSubscriptionController() {
|
|
|
31940
32031
|
}
|
|
31941
32032
|
async function createConsoleSubscription(req, res, next) {
|
|
31942
32033
|
try {
|
|
31943
|
-
const staffId = await
|
|
32034
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31944
32035
|
const form = await readConsoleForm(req);
|
|
31945
32036
|
const existing = await _getByOrgId(form.orgId);
|
|
31946
32037
|
if (existing && existing.status !== "ended") {
|
|
@@ -31986,7 +32077,7 @@ function useSubscriptionController() {
|
|
|
31986
32077
|
}
|
|
31987
32078
|
async function updateConsoleSubscription(req, res, next) {
|
|
31988
32079
|
try {
|
|
31989
|
-
const staffId = await
|
|
32080
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
31990
32081
|
const form = await readConsoleForm(req);
|
|
31991
32082
|
const existing = await _getByOrgId(form.orgId);
|
|
31992
32083
|
if (!existing?._id) {
|
|
@@ -32026,7 +32117,7 @@ function useSubscriptionController() {
|
|
|
32026
32117
|
}
|
|
32027
32118
|
async function getConsoleSubscription(req, res, next) {
|
|
32028
32119
|
try {
|
|
32029
|
-
await
|
|
32120
|
+
await requireConsolePermission(req, "subscriptions", "see-subscription-details");
|
|
32030
32121
|
const orgId = req.params.id;
|
|
32031
32122
|
if (!/^[0-9a-fA-F]{24}$/.test(orgId ?? "")) {
|
|
32032
32123
|
throw new import_node_server_utils80.BadRequestError("That client could not be found.");
|
|
@@ -32095,7 +32186,7 @@ function useSubscriptionPlanController() {
|
|
|
32095
32186
|
return;
|
|
32096
32187
|
}
|
|
32097
32188
|
try {
|
|
32098
|
-
const staffId = await
|
|
32189
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32099
32190
|
const _id = await _add(req.body);
|
|
32100
32191
|
const data = await _getById(_id);
|
|
32101
32192
|
await recordConsoleAction({
|
|
@@ -32191,7 +32282,7 @@ function useSubscriptionPlanController() {
|
|
|
32191
32282
|
}
|
|
32192
32283
|
const id = req.params.id;
|
|
32193
32284
|
try {
|
|
32194
|
-
const staffId = await
|
|
32285
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32195
32286
|
const before = await _getById(id);
|
|
32196
32287
|
await _update(id, req.body);
|
|
32197
32288
|
const data = await _getById(id);
|
|
@@ -32223,7 +32314,7 @@ function useSubscriptionPlanController() {
|
|
|
32223
32314
|
const id = req.params.id;
|
|
32224
32315
|
const { status } = req.body;
|
|
32225
32316
|
try {
|
|
32226
|
-
const staffId = await
|
|
32317
|
+
const staffId = await requireConsolePermission(req, "subscriptions", "manage-subscription");
|
|
32227
32318
|
await _updateStatusById(id, status);
|
|
32228
32319
|
const data = await _getById(id);
|
|
32229
32320
|
await recordConsoleAction({
|
|
@@ -32364,7 +32455,7 @@ function usePromoCodeController() {
|
|
|
32364
32455
|
payload.code = payload.code.trim().toUpperCase();
|
|
32365
32456
|
payload.fixed_rate = parseInt(payload.fixed_rate ?? "0");
|
|
32366
32457
|
try {
|
|
32367
|
-
const staffId = await
|
|
32458
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "create-promo-code");
|
|
32368
32459
|
const created = await _add(payload);
|
|
32369
32460
|
await recordConsoleAction({
|
|
32370
32461
|
action: "promo-code.created" /* PROMO_CODE_CREATED */,
|
|
@@ -32417,7 +32508,7 @@ function usePromoCodeController() {
|
|
|
32417
32508
|
return;
|
|
32418
32509
|
}
|
|
32419
32510
|
try {
|
|
32420
|
-
await
|
|
32511
|
+
await requireConsolePermission(req, "promo-codes", "see-promo-code-details");
|
|
32421
32512
|
const data = await _getById(_id);
|
|
32422
32513
|
res.json(data);
|
|
32423
32514
|
return;
|
|
@@ -32446,7 +32537,7 @@ function usePromoCodeController() {
|
|
|
32446
32537
|
const limit = parseInt(req.query.limit ?? "10");
|
|
32447
32538
|
const status = req.query.status ?? "active";
|
|
32448
32539
|
try {
|
|
32449
|
-
await
|
|
32540
|
+
await requireConsolePermission(req, "promo-codes");
|
|
32450
32541
|
const data = await _getPromoCodes({
|
|
32451
32542
|
search,
|
|
32452
32543
|
page,
|
|
@@ -32471,7 +32562,7 @@ function usePromoCodeController() {
|
|
|
32471
32562
|
return;
|
|
32472
32563
|
}
|
|
32473
32564
|
try {
|
|
32474
|
-
const staffId = await
|
|
32565
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "edit-promo-code-details");
|
|
32475
32566
|
const before = await _getById(req.params.id);
|
|
32476
32567
|
await _updateById(req.params.id, req.body);
|
|
32477
32568
|
await recordConsoleAction({
|
|
@@ -32507,7 +32598,7 @@ function usePromoCodeController() {
|
|
|
32507
32598
|
return;
|
|
32508
32599
|
}
|
|
32509
32600
|
try {
|
|
32510
|
-
const staffId = await
|
|
32601
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "change-promo-code-status");
|
|
32511
32602
|
await _updateStatusById(req.params.id, status.value.status);
|
|
32512
32603
|
await recordConsoleAction({
|
|
32513
32604
|
action: "promo-code.status-changed" /* PROMO_CODE_STATUS_CHANGED */,
|
|
@@ -32536,7 +32627,7 @@ function usePromoCodeController() {
|
|
|
32536
32627
|
return;
|
|
32537
32628
|
}
|
|
32538
32629
|
try {
|
|
32539
|
-
const staffId = await
|
|
32630
|
+
const staffId = await requireConsolePermission(req, "promo-codes", "delete-promo-code");
|
|
32540
32631
|
await _softDeleteById(req.params.id, staffId);
|
|
32541
32632
|
await recordConsoleAction({
|
|
32542
32633
|
action: "promo-code.removed" /* PROMO_CODE_REMOVED */,
|
|
@@ -85195,6 +85286,11 @@ function useServiceProviderInviteController() {
|
|
|
85195
85286
|
}
|
|
85196
85287
|
async function approvals(req, res, next) {
|
|
85197
85288
|
try {
|
|
85289
|
+
await requireConsolePermission(
|
|
85290
|
+
req,
|
|
85291
|
+
"sp-approvals",
|
|
85292
|
+
"see-all-sp-approvals"
|
|
85293
|
+
);
|
|
85198
85294
|
const schema2 = import_joi143.default.object({
|
|
85199
85295
|
status: import_joi143.default.string().valid(
|
|
85200
85296
|
"awaiting-approval",
|
|
@@ -85221,6 +85317,11 @@ function useServiceProviderInviteController() {
|
|
|
85221
85317
|
}
|
|
85222
85318
|
async function pendingApprovalCount(req, res, next) {
|
|
85223
85319
|
try {
|
|
85320
|
+
await requireConsolePermission(
|
|
85321
|
+
req,
|
|
85322
|
+
"sp-approvals",
|
|
85323
|
+
"see-all-sp-approvals"
|
|
85324
|
+
);
|
|
85224
85325
|
res.json(await approvalCount({ userId: callerId5(req) }));
|
|
85225
85326
|
} catch (error) {
|
|
85226
85327
|
next(error);
|
|
@@ -85228,6 +85329,7 @@ function useServiceProviderInviteController() {
|
|
|
85228
85329
|
}
|
|
85229
85330
|
async function approve(req, res, next) {
|
|
85230
85331
|
try {
|
|
85332
|
+
await requireConsolePermission(req, "sp-approvals", "approve-sp");
|
|
85231
85333
|
res.json(await _approve({ id: inviteId(req), userId: callerId5(req) }));
|
|
85232
85334
|
} catch (error) {
|
|
85233
85335
|
import_node_server_utils264.logger.log({ level: "error", message: `${error.message}` });
|
|
@@ -85236,6 +85338,7 @@ function useServiceProviderInviteController() {
|
|
|
85236
85338
|
}
|
|
85237
85339
|
async function reject(req, res, next) {
|
|
85238
85340
|
try {
|
|
85341
|
+
await requireConsolePermission(req, "sp-approvals", "reject-sp");
|
|
85239
85342
|
const { error, value } = import_joi143.default.object({
|
|
85240
85343
|
reason: import_joi143.default.string().trim().min(1).max(1e3).required()
|
|
85241
85344
|
}).validate(req.body ?? {});
|
|
@@ -86346,7 +86449,7 @@ function useUserControllerV2() {
|
|
|
86346
86449
|
return;
|
|
86347
86450
|
}
|
|
86348
86451
|
try {
|
|
86349
|
-
await requireSelfOrPlatformStaff(req, value);
|
|
86452
|
+
await requireSelfOrPlatformStaff(req, value, { resource: "users", action: "see-user-details" });
|
|
86350
86453
|
const user = await _getById(value);
|
|
86351
86454
|
res.json(user);
|
|
86352
86455
|
return;
|
|
@@ -86383,7 +86486,7 @@ function useUserControllerV2() {
|
|
|
86383
86486
|
if (error)
|
|
86384
86487
|
return rejectValidation(error, next);
|
|
86385
86488
|
try {
|
|
86386
|
-
await
|
|
86489
|
+
await requireConsolePermission(req, "users", "see-all-users");
|
|
86387
86490
|
const users = await _getUsers({
|
|
86388
86491
|
search: value.search ?? "",
|
|
86389
86492
|
page: value.page,
|
|
@@ -86508,7 +86611,7 @@ function useUserControllerV2() {
|
|
|
86508
86611
|
return;
|
|
86509
86612
|
}
|
|
86510
86613
|
try {
|
|
86511
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
86614
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
86512
86615
|
const message = await _updateBirthday({ _id, ...payload });
|
|
86513
86616
|
res.json({ message });
|
|
86514
86617
|
return;
|
|
@@ -86540,7 +86643,7 @@ function useUserControllerV2() {
|
|
|
86540
86643
|
return;
|
|
86541
86644
|
}
|
|
86542
86645
|
try {
|
|
86543
|
-
await requireUserFieldWrite(req, _id, payload.field);
|
|
86646
|
+
await requireUserFieldWrite(req, _id, payload.field, { resource: "users" });
|
|
86544
86647
|
const message = await _updateUserFieldById({ _id, ...payload });
|
|
86545
86648
|
res.json({ message });
|
|
86546
86649
|
return;
|
|
@@ -86571,7 +86674,7 @@ function useUserControllerV2() {
|
|
|
86571
86674
|
const newPassword = req.body.newPassword ?? "";
|
|
86572
86675
|
const passwordConfirmation = req.body.passwordConfirmation ?? "";
|
|
86573
86676
|
try {
|
|
86574
|
-
await requireSelfOrPlatformStaff(req, _id);
|
|
86677
|
+
await requireSelfOrPlatformStaff(req, _id, { resource: "users" });
|
|
86575
86678
|
await _updatePasswordById(
|
|
86576
86679
|
_id,
|
|
86577
86680
|
currentPassword,
|
|
@@ -86749,7 +86852,7 @@ function useRoleControllerV2() {
|
|
|
86749
86852
|
}
|
|
86750
86853
|
try {
|
|
86751
86854
|
if (value.type === PLATFORM_STAFF_ROLE_TYPE) {
|
|
86752
|
-
await
|
|
86855
|
+
await requireConsolePermission(req, "roles-and-permissions", "add-role");
|
|
86753
86856
|
}
|
|
86754
86857
|
if (value.org) {
|
|
86755
86858
|
await requireOrgReach(req, value.org);
|
|
@@ -91425,7 +91528,7 @@ function usePlatformTermsController() {
|
|
|
91425
91528
|
return id;
|
|
91426
91529
|
}
|
|
91427
91530
|
if (staffMayRead) {
|
|
91428
|
-
return await
|
|
91531
|
+
return await requireConsolePermission(req, "platform-terms", "see-platform-terms");
|
|
91429
91532
|
}
|
|
91430
91533
|
throw new import_node_server_utils298.UnauthorizedError("Not authorized.");
|
|
91431
91534
|
}
|
|
@@ -91517,7 +91620,7 @@ function usePlatformTermsController() {
|
|
|
91517
91620
|
return;
|
|
91518
91621
|
}
|
|
91519
91622
|
try {
|
|
91520
|
-
await
|
|
91623
|
+
await requireConsolePermission(req, "platform-terms", "see-platform-terms");
|
|
91521
91624
|
res.json(
|
|
91522
91625
|
await _listAcceptance({
|
|
91523
91626
|
version: value.version || null,
|
|
@@ -91549,7 +91652,7 @@ function usePlatformTermsController() {
|
|
|
91549
91652
|
return;
|
|
91550
91653
|
}
|
|
91551
91654
|
try {
|
|
91552
|
-
const staffId = await
|
|
91655
|
+
const staffId = await requireConsolePermission(req, "platform-terms", "edit-platform-terms");
|
|
91553
91656
|
const created = await _add({
|
|
91554
91657
|
terms: value.terms,
|
|
91555
91658
|
policies: value.policies,
|
|
@@ -91607,7 +91710,7 @@ function useConsoleAuditController() {
|
|
|
91607
91710
|
}
|
|
91608
91711
|
const to = value.to && value.to.length === 10 ? `${value.to}T23:59:59.999Z` : value.to;
|
|
91609
91712
|
try {
|
|
91610
|
-
await
|
|
91713
|
+
await requireConsolePermission(req, "activity-history", "see-activity-history");
|
|
91611
91714
|
res.json(
|
|
91612
91715
|
await _list({
|
|
91613
91716
|
org: value.org || "",
|
|
@@ -91950,6 +92053,7 @@ function useNotificationPreferenceController() {
|
|
|
91950
92053
|
CLIENT_ACTIONS,
|
|
91951
92054
|
CLOCK_DRIFT_WARN_SECONDS,
|
|
91952
92055
|
CONSOLE_AUDIT_LABELS,
|
|
92056
|
+
CONSOLE_PERMISSIONS,
|
|
91953
92057
|
CONTRACTOR_TYPE_LABELS,
|
|
91954
92058
|
CURRENT_TIME_ENDPOINT,
|
|
91955
92059
|
CameraType,
|
|
@@ -92162,6 +92266,9 @@ function useNotificationPreferenceController() {
|
|
|
92162
92266
|
chatSchema,
|
|
92163
92267
|
clampPtzSpeed,
|
|
92164
92268
|
clockDriftSeconds,
|
|
92269
|
+
consoleRoleAllows,
|
|
92270
|
+
consoleRoleAllowsAll,
|
|
92271
|
+
consoleSpellings,
|
|
92165
92272
|
console_audit_namespace_collection,
|
|
92166
92273
|
createManpowerRemarksDaily,
|
|
92167
92274
|
customerSchema,
|
|
@@ -92261,6 +92368,8 @@ function useNotificationPreferenceController() {
|
|
|
92261
92368
|
relayForRecorder,
|
|
92262
92369
|
remarksSchema,
|
|
92263
92370
|
renderPagePdf,
|
|
92371
|
+
requireConsolePermission,
|
|
92372
|
+
requirePlatformStaff,
|
|
92264
92373
|
resetCameraTransports,
|
|
92265
92374
|
residentAppModuleKeys,
|
|
92266
92375
|
residentFormEntry,
|
|
@@ -92270,6 +92379,7 @@ function useNotificationPreferenceController() {
|
|
|
92270
92379
|
resolveHidPhysicalCardValue,
|
|
92271
92380
|
resolveInviteActor,
|
|
92272
92381
|
resolveSiteTimezone,
|
|
92382
|
+
resolveStaffRole,
|
|
92273
92383
|
robotSchema,
|
|
92274
92384
|
rtspUrl,
|
|
92275
92385
|
schema,
|