@7365admin1/core 3.106.0 → 3.109.0
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 +18 -0
- package/dist/index.d.ts +27 -7
- package/dist/index.js +119 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/e2e/invite-org-scoping.e2e.test.mjs +6 -5
- package/test/e2e/invite-roles-owner-reach.e2e.test.mjs +73 -0
- package/test/e2e/org-invite-scope.e2e.test.mjs +188 -0
- package/test/e2e/site-delete-owner-only.e2e.test.mjs +148 -0
- package/test/invite-origin.test.mjs +42 -0
- package/test/notification-email.util.test.mjs +67 -0
- package/test/site-owner-edit.test.mjs +18 -0
- package/test/verification-scope.test.mjs +2 -1
package/dist/index.mjs
CHANGED
|
@@ -4735,6 +4735,22 @@ import {
|
|
|
4735
4735
|
useCache as useCache8
|
|
4736
4736
|
} from "@7365admin1/node-server-utils";
|
|
4737
4737
|
import { ObjectId as ObjectId17 } from "mongodb";
|
|
4738
|
+
|
|
4739
|
+
// src/utils/invite-origin.util.ts
|
|
4740
|
+
var SEVEN365_INVITE_ORIGIN = "seven365";
|
|
4741
|
+
function seven365InviteQuery() {
|
|
4742
|
+
return {
|
|
4743
|
+
$or: [
|
|
4744
|
+
{ "metadata.origin": SEVEN365_INVITE_ORIGIN },
|
|
4745
|
+
{
|
|
4746
|
+
"metadata.origin": { $exists: false },
|
|
4747
|
+
"metadata.org": { $in: ["", null] }
|
|
4748
|
+
}
|
|
4749
|
+
]
|
|
4750
|
+
};
|
|
4751
|
+
}
|
|
4752
|
+
|
|
4753
|
+
// src/repositories/verification.repo.ts
|
|
4738
4754
|
function useVerificationRepo() {
|
|
4739
4755
|
const db2 = useAtlas11.getDb();
|
|
4740
4756
|
if (!db2) {
|
|
@@ -4821,7 +4837,8 @@ function useVerificationRepo() {
|
|
|
4821
4837
|
type = {},
|
|
4822
4838
|
email = "",
|
|
4823
4839
|
siteId = "",
|
|
4824
|
-
orgId = ""
|
|
4840
|
+
orgId = "",
|
|
4841
|
+
origin = ""
|
|
4825
4842
|
}) {
|
|
4826
4843
|
page = page > 0 ? page - 1 : 0;
|
|
4827
4844
|
const query2 = { status };
|
|
@@ -4866,6 +4883,10 @@ function useVerificationRepo() {
|
|
|
4866
4883
|
query2["metadata.org"] = { $in: orgCandidates };
|
|
4867
4884
|
cacheOptions.orgId = orgId;
|
|
4868
4885
|
}
|
|
4886
|
+
if (origin === SEVEN365_INVITE_ORIGIN) {
|
|
4887
|
+
Object.assign(query2, seven365InviteQuery());
|
|
4888
|
+
cacheOptions.origin = origin;
|
|
4889
|
+
}
|
|
4869
4890
|
const cacheKey = makeCacheKey6(namespace_collection3, cacheOptions);
|
|
4870
4891
|
const cachedData = await getCache(cacheKey);
|
|
4871
4892
|
if (cachedData) {
|
|
@@ -9358,11 +9379,25 @@ var EMAIL_CODE_RESEND_MS = 60 * 1e3;
|
|
|
9358
9379
|
function normalizeEmail(value) {
|
|
9359
9380
|
return String(value ?? "").trim().toLowerCase();
|
|
9360
9381
|
}
|
|
9361
|
-
function
|
|
9382
|
+
function isProductionWebBase(base = webBase()) {
|
|
9383
|
+
let host = "";
|
|
9384
|
+
try {
|
|
9385
|
+
host = new URL(base).hostname.toLowerCase();
|
|
9386
|
+
} catch {
|
|
9387
|
+
return false;
|
|
9388
|
+
}
|
|
9389
|
+
return host === "iservice365.org" || host.endsWith(".iservice365.org");
|
|
9390
|
+
}
|
|
9391
|
+
function effectiveEmailAllowlist(list = process.env.EMAIL_NOTIFICATIONS_ALLOWLIST, base = webBase()) {
|
|
9392
|
+
if (list !== void 0 && list.trim() !== "")
|
|
9393
|
+
return list;
|
|
9394
|
+
return isProductionWebBase(base) ? "*" : DEFAULT_EMAIL_ALLOWLIST;
|
|
9395
|
+
}
|
|
9396
|
+
function isEmailAllowed(address, list = process.env.EMAIL_NOTIFICATIONS_ALLOWLIST, base = webBase()) {
|
|
9362
9397
|
const email = normalizeEmail(address);
|
|
9363
9398
|
if (!email || !email.includes("@"))
|
|
9364
9399
|
return false;
|
|
9365
|
-
const raw = list
|
|
9400
|
+
const raw = effectiveEmailAllowlist(list, base);
|
|
9366
9401
|
const domain = email.slice(email.lastIndexOf("@") + 1);
|
|
9367
9402
|
return raw.split(/[\s,]+/).map((e) => e.trim().toLowerCase()).filter(Boolean).some((entry) => {
|
|
9368
9403
|
if (entry === "*")
|
|
@@ -9374,8 +9409,8 @@ function isEmailAllowed(address, list = process.env.EMAIL_NOTIFICATIONS_ALLOWLIS
|
|
|
9374
9409
|
return email === entry;
|
|
9375
9410
|
});
|
|
9376
9411
|
}
|
|
9377
|
-
function emailOpenToEveryone(list = process.env.EMAIL_NOTIFICATIONS_ALLOWLIST) {
|
|
9378
|
-
return
|
|
9412
|
+
function emailOpenToEveryone(list = process.env.EMAIL_NOTIFICATIONS_ALLOWLIST, base = webBase()) {
|
|
9413
|
+
return effectiveEmailAllowlist(list, base).split(/[\s,]+/).some((e) => e.trim() === "*");
|
|
9379
9414
|
}
|
|
9380
9415
|
function newSecret() {
|
|
9381
9416
|
return crypto2.randomBytes(32).toString("hex");
|
|
@@ -12990,6 +13025,23 @@ async function requireRoleInvitable(role, org, apps, site) {
|
|
|
12990
13025
|
if (refusal)
|
|
12991
13026
|
throw new BadRequestError33(refusal);
|
|
12992
13027
|
}
|
|
13028
|
+
async function requireInviteOrigin(req, org, role, fromConsole = false) {
|
|
13029
|
+
if (!org) {
|
|
13030
|
+
await requirePlatformStaff(req);
|
|
13031
|
+
return { origin: SEVEN365_INVITE_ORIGIN };
|
|
13032
|
+
}
|
|
13033
|
+
if (!role)
|
|
13034
|
+
throw new BadRequestError33("Choose a role for this invitation.");
|
|
13035
|
+
if (fromConsole) {
|
|
13036
|
+
const staff = await requirePlatformStaff(req).then(
|
|
13037
|
+
() => true,
|
|
13038
|
+
() => false
|
|
13039
|
+
);
|
|
13040
|
+
if (staff)
|
|
13041
|
+
return { origin: SEVEN365_INVITE_ORIGIN };
|
|
13042
|
+
}
|
|
13043
|
+
return {};
|
|
13044
|
+
}
|
|
12993
13045
|
async function requireInviteReach(req, org, app, role, site) {
|
|
12994
13046
|
const apps = Array.isArray(app) ? app : [app];
|
|
12995
13047
|
if (apps.some((a) => a === PLATFORM_STAFF_MEMBER_TYPE)) {
|
|
@@ -26656,6 +26708,7 @@ function useVerificationController() {
|
|
|
26656
26708
|
const siteName = req.body.siteName ?? "";
|
|
26657
26709
|
try {
|
|
26658
26710
|
await requireInviteReach(req, org, app, role, siteId);
|
|
26711
|
+
const origin = await requireInviteOrigin(req, org, role);
|
|
26659
26712
|
await _createUserInvite({
|
|
26660
26713
|
email,
|
|
26661
26714
|
metadata: {
|
|
@@ -26664,7 +26717,8 @@ function useVerificationController() {
|
|
|
26664
26717
|
name,
|
|
26665
26718
|
org,
|
|
26666
26719
|
siteId,
|
|
26667
|
-
siteName
|
|
26720
|
+
siteName,
|
|
26721
|
+
...origin
|
|
26668
26722
|
}
|
|
26669
26723
|
});
|
|
26670
26724
|
res.status(201).json({ message: "Successfully invited user." });
|
|
@@ -26757,6 +26811,7 @@ function useVerificationController() {
|
|
|
26757
26811
|
clientModules.residentAppModules = residentAppModules;
|
|
26758
26812
|
}
|
|
26759
26813
|
await requireInviteReach(req, org, app, role, siteId);
|
|
26814
|
+
const origin = await requireInviteOrigin(req, org, role, true);
|
|
26760
26815
|
const verificationIds = await _createSimpleUserInvite({
|
|
26761
26816
|
email,
|
|
26762
26817
|
metadata: {
|
|
@@ -26766,7 +26821,8 @@ function useVerificationController() {
|
|
|
26766
26821
|
org,
|
|
26767
26822
|
siteId,
|
|
26768
26823
|
siteName,
|
|
26769
|
-
...clientModules
|
|
26824
|
+
...clientModules,
|
|
26825
|
+
...origin
|
|
26770
26826
|
}
|
|
26771
26827
|
});
|
|
26772
26828
|
const responseBody = {
|
|
@@ -26822,6 +26878,7 @@ function useVerificationController() {
|
|
|
26822
26878
|
const siteName = req.body.siteName ?? "";
|
|
26823
26879
|
try {
|
|
26824
26880
|
await requireInviteReach(req, org, app, role, siteId);
|
|
26881
|
+
const origin = await requireInviteOrigin(req, org, role);
|
|
26825
26882
|
await _createSimpleMemberInvite({
|
|
26826
26883
|
email,
|
|
26827
26884
|
metadata: {
|
|
@@ -26830,7 +26887,8 @@ function useVerificationController() {
|
|
|
26830
26887
|
name,
|
|
26831
26888
|
org,
|
|
26832
26889
|
siteId,
|
|
26833
|
-
siteName
|
|
26890
|
+
siteName,
|
|
26891
|
+
...origin
|
|
26834
26892
|
}
|
|
26835
26893
|
});
|
|
26836
26894
|
const responseBody = {
|
|
@@ -27000,6 +27058,8 @@ function useVerificationController() {
|
|
|
27000
27058
|
email: Joi29.string().optional().allow("", null),
|
|
27001
27059
|
siteId: Joi29.string().hex().optional().allow("", null),
|
|
27002
27060
|
orgId: Joi29.string().hex().optional().allow("", null),
|
|
27061
|
+
// "seven365": only the invitations Seven365 sent (the console's lists).
|
|
27062
|
+
origin: Joi29.string().valid(SEVEN365_INVITE_ORIGIN).optional().allow("", null),
|
|
27003
27063
|
limit: Joi29.number().integer().min(1).allow("", null).default(10)
|
|
27004
27064
|
});
|
|
27005
27065
|
const query2 = { ...req.query };
|
|
@@ -27017,6 +27077,7 @@ function useVerificationController() {
|
|
|
27017
27077
|
const siteId = req.query.siteId ?? "";
|
|
27018
27078
|
const orgId = req.query.orgId ?? "";
|
|
27019
27079
|
const limit = parseInt(req.query.limit ?? "10");
|
|
27080
|
+
const origin = req.query.origin ?? "";
|
|
27020
27081
|
const type = req.query.type ? String(req.query.type).split(",") : "";
|
|
27021
27082
|
const typeObj = {};
|
|
27022
27083
|
if (type && Array.isArray(type) && type.length) {
|
|
@@ -27025,8 +27086,9 @@ function useVerificationController() {
|
|
|
27025
27086
|
});
|
|
27026
27087
|
}
|
|
27027
27088
|
try {
|
|
27028
|
-
await requireVerificationListReach(req, orgId);
|
|
27089
|
+
await requireVerificationListReach(req, origin ? null : orgId);
|
|
27029
27090
|
const data = await _getVerifications({
|
|
27091
|
+
origin,
|
|
27030
27092
|
search,
|
|
27031
27093
|
page,
|
|
27032
27094
|
status,
|
|
@@ -38054,17 +38116,49 @@ function siteOwnerOnlyMessage(ownerName) {
|
|
|
38054
38116
|
async function requireSiteOwnerEdit(actor, staff, siteId) {
|
|
38055
38117
|
if (staff)
|
|
38056
38118
|
return;
|
|
38119
|
+
const ownerOrg = await ownerOfSite(siteId);
|
|
38120
|
+
if (mayEditSiteDetails({ staff, actorOrgIds: actor.orgIds, ownerOrg }))
|
|
38121
|
+
return;
|
|
38122
|
+
throw new AppError18(siteOwnerOnlyMessage(await ownerOrgName(ownerOrg)), 403);
|
|
38123
|
+
}
|
|
38124
|
+
async function ownerOfSite(siteId) {
|
|
38057
38125
|
const id = String(siteId?.toString?.() ?? "");
|
|
38058
38126
|
const db2 = useAtlas60.getDb();
|
|
38059
38127
|
const site = db2 && ObjectId79.isValid(id) ? await db2.collection("sites").findOne({ _id: new ObjectId79(id) }, { projection: { orgId: 1, org: 1 } }) : null;
|
|
38060
|
-
|
|
38061
|
-
|
|
38128
|
+
return site?.orgId ?? site?.org;
|
|
38129
|
+
}
|
|
38130
|
+
async function ownerOrgName(ownerOrg) {
|
|
38131
|
+
if (!ownerOrg || !ObjectId79.isValid(String(ownerOrg)))
|
|
38132
|
+
return void 0;
|
|
38133
|
+
const owner = await useAtlas60.getDb()?.collection("organizations").findOne({ _id: new ObjectId79(String(ownerOrg)) }, { projection: { name: 1 } });
|
|
38134
|
+
return owner?.name;
|
|
38135
|
+
}
|
|
38136
|
+
var DELETE_SITE_PERMISSION = "sites:delete-site";
|
|
38137
|
+
var NO_SITE_DELETE_PERMISSION = "You do not have permission to delete this site.";
|
|
38138
|
+
function siteDeleteOwnerOnlyMessage(ownerName) {
|
|
38139
|
+
const name = String(ownerName ?? "").trim() || "another organisation";
|
|
38140
|
+
return `This site belongs to ${name}. Only they can delete it. You can remove it from your Sites list instead.`;
|
|
38141
|
+
}
|
|
38142
|
+
function mayDeleteSite(permissions) {
|
|
38143
|
+
return permissions.includes("*") || permissions.includes(DELETE_SITE_PERMISSION);
|
|
38144
|
+
}
|
|
38145
|
+
async function requireSiteOwnerDelete(actor, staff, siteId) {
|
|
38146
|
+
if (staff)
|
|
38062
38147
|
return;
|
|
38063
|
-
const owner =
|
|
38064
|
-
|
|
38065
|
-
|
|
38066
|
-
|
|
38067
|
-
|
|
38148
|
+
const owner = String(await ownerOfSite(siteId) ?? "");
|
|
38149
|
+
if (owner && ObjectId79.isValid(owner) && ObjectId79.isValid(actor.id)) {
|
|
38150
|
+
const member = await useAtlas60.getDb()?.collection("members").findOne(
|
|
38151
|
+
{ user: new ObjectId79(actor.id), org: new ObjectId79(owner), type: "organization", status: "active" },
|
|
38152
|
+
{ projection: { role: 1 } }
|
|
38153
|
+
);
|
|
38154
|
+
if (member) {
|
|
38155
|
+
const permissions = member.role ? await getUserPermissions({ user: actor.id, org: owner, role: member.role }) : [];
|
|
38156
|
+
if (mayDeleteSite(permissions))
|
|
38157
|
+
return;
|
|
38158
|
+
throw new AppError18(NO_SITE_DELETE_PERMISSION, 403);
|
|
38159
|
+
}
|
|
38160
|
+
}
|
|
38161
|
+
throw new AppError18(siteDeleteOwnerOnlyMessage(await ownerOrgName(owner)), 403);
|
|
38068
38162
|
}
|
|
38069
38163
|
|
|
38070
38164
|
// src/controllers/site.controller.ts
|
|
@@ -38375,7 +38469,8 @@ function useSiteController() {
|
|
|
38375
38469
|
return;
|
|
38376
38470
|
}
|
|
38377
38471
|
try {
|
|
38378
|
-
await requireSiteWrite(req, _id);
|
|
38472
|
+
const actor = await requireSiteWrite(req, _id);
|
|
38473
|
+
await requireSiteOwnerDelete(actor, staffMayBypass(actor), _id);
|
|
38379
38474
|
await _deleteSite(_id);
|
|
38380
38475
|
res.json({ message: "Successfully deleted site." });
|
|
38381
38476
|
return;
|
|
@@ -93563,6 +93658,7 @@ function useVerificationControllerV2() {
|
|
|
93563
93658
|
const { email, app, role, name, org, siteId, siteName } = value;
|
|
93564
93659
|
try {
|
|
93565
93660
|
await requireInviteReach(req, org, app, role, siteId);
|
|
93661
|
+
const origin = await requireInviteOrigin(req, org, role);
|
|
93566
93662
|
await _createUserInvite({
|
|
93567
93663
|
email,
|
|
93568
93664
|
metadata: {
|
|
@@ -93571,7 +93667,8 @@ function useVerificationControllerV2() {
|
|
|
93571
93667
|
name,
|
|
93572
93668
|
org,
|
|
93573
93669
|
siteId,
|
|
93574
|
-
siteName
|
|
93670
|
+
siteName,
|
|
93671
|
+
...origin
|
|
93575
93672
|
}
|
|
93576
93673
|
});
|
|
93577
93674
|
res.status(201).json({ message: "Successfully invited user." });
|
|
@@ -101129,6 +101226,7 @@ export {
|
|
|
101129
101226
|
deviceProbeTtlSeconds,
|
|
101130
101227
|
disconnectedState,
|
|
101131
101228
|
doorModeOf,
|
|
101229
|
+
effectiveEmailAllowlist,
|
|
101132
101230
|
emailOpenToEveryone,
|
|
101133
101231
|
emitNotificationCreated,
|
|
101134
101232
|
emptyPersonalEmergencyChain,
|
|
@@ -101185,6 +101283,7 @@ export {
|
|
|
101185
101283
|
isLiveVehicleStatus,
|
|
101186
101284
|
isPatrolCctvCamera,
|
|
101187
101285
|
isPlatformOwner,
|
|
101286
|
+
isProductionWebBase,
|
|
101188
101287
|
isPromoCodeExpired,
|
|
101189
101288
|
isRelayPlayerUrl,
|
|
101190
101289
|
isSafeRelativePath,
|