@7365admin1/core 3.98.0 → 3.99.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 +6 -0
- package/dist/index.d.ts +83 -8
- package/dist/index.js +212 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +208 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/camera-view.util.test.mjs +47 -0
- package/test/e2e/service-provider-invite-approval.e2e.test.mjs +193 -2
- package/test/service-provider-invite.test.mjs +38 -1
package/dist/index.js
CHANGED
|
@@ -263,6 +263,8 @@ __export(src_exports, {
|
|
|
263
263
|
PostSort: () => PostSort,
|
|
264
264
|
PostStatus: () => PostStatus,
|
|
265
265
|
REALTIME_MAX_FANOUT: () => REALTIME_MAX_FANOUT,
|
|
266
|
+
RECEIVED_INVITE_LABELS: () => RECEIVED_INVITE_LABELS,
|
|
267
|
+
RECEIVED_INVITE_TABS: () => RECEIVED_INVITE_TABS,
|
|
266
268
|
REGISTERED_VEHICLE_CATEGORIES: () => REGISTERED_VEHICLE_CATEGORIES,
|
|
267
269
|
ROBOT_APP_SCOPES: () => ROBOT_APP_SCOPES,
|
|
268
270
|
ROBOT_AUDIT_ACTIONS: () => ROBOT_AUDIT_ACTIONS,
|
|
@@ -506,6 +508,7 @@ __export(src_exports, {
|
|
|
506
508
|
orgOwnerRepairHandlers: () => orgOwnerRepairHandlers,
|
|
507
509
|
orgOwnerRepairOn: () => orgOwnerRepairOn,
|
|
508
510
|
orgQualifiesForOwnerRepair: () => orgQualifiesForOwnerRepair,
|
|
511
|
+
orgRoleSets: () => orgRoleSets,
|
|
509
512
|
orgSchema: () => orgSchema,
|
|
510
513
|
overnight_parking_requests_namespace_collection: () => overnight_parking_requests_namespace_collection,
|
|
511
514
|
parseCameraChannel: () => parseCameraChannel,
|
|
@@ -536,6 +539,7 @@ __export(src_exports, {
|
|
|
536
539
|
publicCameraFields: () => publicCameraFields,
|
|
537
540
|
readLiveItems: () => readLiveItems,
|
|
538
541
|
readsAsApprovedAccount: () => readsAsApprovedAccount,
|
|
542
|
+
receivedInviteTab: () => receivedInviteTab,
|
|
539
543
|
recordConsoleAction: () => recordConsoleAction,
|
|
540
544
|
refuseServiceProviderInviteAction: () => refuseServiceProviderInviteAction,
|
|
541
545
|
registerCameraTransport: () => registerCameraTransport,
|
|
@@ -8963,6 +8967,29 @@ function serviceProviderInviteViewStatus(invite, now = /* @__PURE__ */ new Date(
|
|
|
8963
8967
|
return isServiceProviderInviteExpired(invite, now) ? "expired" : String(invite?.status ?? "");
|
|
8964
8968
|
}
|
|
8965
8969
|
var SERVICE_PROVIDER_INVITE_EXPIRED_MESSAGE = "This invitation has expired. Ask the organisation that sent it for a new one.";
|
|
8970
|
+
var RECEIVED_INVITE_TABS = ["pending", "accepted", "declined", "expired"];
|
|
8971
|
+
function receivedInviteTab(invite, now = /* @__PURE__ */ new Date()) {
|
|
8972
|
+
switch (serviceProviderInviteViewStatus(invite, now)) {
|
|
8973
|
+
case "pending":
|
|
8974
|
+
return "pending";
|
|
8975
|
+
case "complete":
|
|
8976
|
+
return "accepted";
|
|
8977
|
+
case "declined":
|
|
8978
|
+
return "declined";
|
|
8979
|
+
case "expired":
|
|
8980
|
+
case "cancelled":
|
|
8981
|
+
return "expired";
|
|
8982
|
+
default:
|
|
8983
|
+
return null;
|
|
8984
|
+
}
|
|
8985
|
+
}
|
|
8986
|
+
var RECEIVED_INVITE_LABELS = {
|
|
8987
|
+
pending: "Waiting for you",
|
|
8988
|
+
complete: "Accepted",
|
|
8989
|
+
declined: "Declined",
|
|
8990
|
+
expired: "Expired",
|
|
8991
|
+
cancelled: "Withdrawn by the client"
|
|
8992
|
+
};
|
|
8966
8993
|
|
|
8967
8994
|
// src/utils/invite-actor.util.ts
|
|
8968
8995
|
var import_node_server_utils27 = require("@7365admin1/node-server-utils");
|
|
@@ -9009,7 +9036,7 @@ async function resolveInviteActor(userId) {
|
|
|
9009
9036
|
members.map((m) => m.role?.toString?.() ?? "").filter((r) => r && import_mongodb25.ObjectId.isValid(r))
|
|
9010
9037
|
)
|
|
9011
9038
|
);
|
|
9012
|
-
const orgLevelRoleIds = await
|
|
9039
|
+
const { orgLevel: orgLevelRoleIds, companyWide: companyWideRoleIds } = await orgRoleSets(db2, memberRoleIds);
|
|
9013
9040
|
return {
|
|
9014
9041
|
id,
|
|
9015
9042
|
name: user?.name ?? adminMember?.name ?? "",
|
|
@@ -9021,6 +9048,7 @@ async function resolveInviteActor(userId) {
|
|
|
9021
9048
|
org: m.org?.toString?.() ?? "",
|
|
9022
9049
|
siteId: m.siteId?.toString?.() ?? "",
|
|
9023
9050
|
orgLevelRole: orgLevelRoleIds.has(m.role?.toString?.() ?? ""),
|
|
9051
|
+
companyWideRole: companyWideRoleIds.has(m.role?.toString?.() ?? ""),
|
|
9024
9052
|
type: m.type ?? ""
|
|
9025
9053
|
}))
|
|
9026
9054
|
};
|
|
@@ -9091,23 +9119,31 @@ async function invitationOffersRole(userId, orgId, roleId) {
|
|
|
9091
9119
|
);
|
|
9092
9120
|
}
|
|
9093
9121
|
async function orgLevelRoles(db2, roles) {
|
|
9122
|
+
return (await orgRoleSets(db2, roles)).orgLevel;
|
|
9123
|
+
}
|
|
9124
|
+
async function orgRoleSets(db2, roles) {
|
|
9094
9125
|
const ids2 = Array.from(
|
|
9095
9126
|
new Set(
|
|
9096
9127
|
roles.map((role) => role?.toString?.() ?? "").filter((role) => role && import_mongodb25.ObjectId.isValid(role))
|
|
9097
9128
|
)
|
|
9098
9129
|
);
|
|
9099
9130
|
const orgLevel = /* @__PURE__ */ new Set();
|
|
9131
|
+
const companyWide = /* @__PURE__ */ new Set();
|
|
9100
9132
|
if (!ids2.length)
|
|
9101
|
-
return orgLevel;
|
|
9133
|
+
return { orgLevel, companyWide };
|
|
9102
9134
|
const docs = await db2.collection("roles").find(
|
|
9103
9135
|
{ _id: { $in: ids2.map((id) => new import_mongodb25.ObjectId(id)) }, ...LIVE_ROLE },
|
|
9104
|
-
{ projection: { site: 1 } }
|
|
9136
|
+
{ projection: { site: 1, type: 1, permissions: 1 } }
|
|
9105
9137
|
).toArray();
|
|
9106
9138
|
for (const role of docs) {
|
|
9107
|
-
if (
|
|
9108
|
-
|
|
9139
|
+
if (role.site)
|
|
9140
|
+
continue;
|
|
9141
|
+
orgLevel.add(role._id.toString());
|
|
9142
|
+
if (role.type === "organization") {
|
|
9143
|
+
companyWide.add(role._id.toString());
|
|
9144
|
+
}
|
|
9109
9145
|
}
|
|
9110
|
-
return orgLevel;
|
|
9146
|
+
return { orgLevel, companyWide };
|
|
9111
9147
|
}
|
|
9112
9148
|
async function hasOrgOwnership(userId, orgId) {
|
|
9113
9149
|
const id = userId?.toString() ?? "";
|
|
@@ -12727,11 +12763,10 @@ function useCustomerSiteService() {
|
|
|
12727
12763
|
}
|
|
12728
12764
|
const { getById: getVerificationById } = useVerificationRepo();
|
|
12729
12765
|
const {
|
|
12730
|
-
updateVerificationStatusById: _updateVerificationStatusById,
|
|
12731
12766
|
getServiceProviderInviteById: _getInviteFresh,
|
|
12732
12767
|
transitionServiceProviderInvite: _transitionInvite
|
|
12733
12768
|
} = useVerificationRepoV2();
|
|
12734
|
-
async function addViaInvite(invite, actor) {
|
|
12769
|
+
async function addViaInvite(invite, actor, forOrgId) {
|
|
12735
12770
|
const session = import_node_server_utils40.useAtlas.getClient()?.startSession();
|
|
12736
12771
|
session?.startTransaction();
|
|
12737
12772
|
try {
|
|
@@ -12755,7 +12790,7 @@ function useCustomerSiteService() {
|
|
|
12755
12790
|
if (!site) {
|
|
12756
12791
|
throw new import_node_server_utils40.NotFoundError("Site not found.");
|
|
12757
12792
|
}
|
|
12758
|
-
const serviceProvider = await getOrgByEmail(
|
|
12793
|
+
const serviceProvider = forOrgId ? await _getByOrgId(forOrgId) : await getOrgByEmail(
|
|
12759
12794
|
String(verification.email ?? "").trim().toLowerCase()
|
|
12760
12795
|
);
|
|
12761
12796
|
if (!serviceProvider) {
|
|
@@ -12766,9 +12801,25 @@ function useCustomerSiteService() {
|
|
|
12766
12801
|
providerOrgId,
|
|
12767
12802
|
siteId
|
|
12768
12803
|
);
|
|
12804
|
+
const accepted = {
|
|
12805
|
+
"metadata.providerOrg": providerOrgId,
|
|
12806
|
+
"metadata.providerOrgName": serviceProvider.name ?? ""
|
|
12807
|
+
};
|
|
12769
12808
|
if (alreadyEngaged > 0) {
|
|
12770
12809
|
if (verification.status === "pending") {
|
|
12771
|
-
await
|
|
12810
|
+
await _transitionInvite({
|
|
12811
|
+
id: invite,
|
|
12812
|
+
from: ["pending"],
|
|
12813
|
+
to: "complete",
|
|
12814
|
+
event: {
|
|
12815
|
+
action: "accepted",
|
|
12816
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12817
|
+
by: actor?.id ? new import_mongodb36.ObjectId(actor.id) : null,
|
|
12818
|
+
byName: actor?.name ?? ""
|
|
12819
|
+
},
|
|
12820
|
+
set: accepted,
|
|
12821
|
+
session
|
|
12822
|
+
});
|
|
12772
12823
|
}
|
|
12773
12824
|
await session?.commitTransaction();
|
|
12774
12825
|
return { message: "This site is already on your list.", accepted: false };
|
|
@@ -12809,6 +12860,7 @@ function useCustomerSiteService() {
|
|
|
12809
12860
|
by: actor?.id ? new import_mongodb36.ObjectId(actor.id) : null,
|
|
12810
12861
|
byName: actor?.name ?? ""
|
|
12811
12862
|
},
|
|
12863
|
+
set: accepted,
|
|
12812
12864
|
session
|
|
12813
12865
|
});
|
|
12814
12866
|
if (!closed) {
|
|
@@ -12827,7 +12879,12 @@ function useCustomerSiteService() {
|
|
|
12827
12879
|
session
|
|
12828
12880
|
);
|
|
12829
12881
|
await session?.commitTransaction();
|
|
12830
|
-
return {
|
|
12882
|
+
return {
|
|
12883
|
+
message: "Invite accepted, successfully added site.",
|
|
12884
|
+
accepted: true,
|
|
12885
|
+
providerOrgId,
|
|
12886
|
+
providerOrgName: serviceProvider.name ?? ""
|
|
12887
|
+
};
|
|
12831
12888
|
} catch (error) {
|
|
12832
12889
|
await session?.abortTransaction();
|
|
12833
12890
|
throw error;
|
|
@@ -13464,10 +13521,15 @@ function useServiceProviderInviteService() {
|
|
|
13464
13521
|
await notifyInviter(invite, false);
|
|
13465
13522
|
return { message: "Invitation declined." };
|
|
13466
13523
|
}
|
|
13467
|
-
async function accept({
|
|
13524
|
+
async function accept({
|
|
13525
|
+
id,
|
|
13526
|
+
userId,
|
|
13527
|
+
org
|
|
13528
|
+
}) {
|
|
13468
13529
|
const actor = await actorFor(userId);
|
|
13469
13530
|
const invite = await load(id);
|
|
13470
13531
|
await assertInvitedParty(actor.id, invite);
|
|
13532
|
+
const forOrg = memberOrg(actor, org);
|
|
13471
13533
|
if (![SERVICE_PROVIDER_SIGN_IN_TYPE, SERVICE_PROVIDER_SIGN_UP_TYPE].includes(
|
|
13472
13534
|
String(invite.type ?? "")
|
|
13473
13535
|
)) {
|
|
@@ -13484,10 +13546,11 @@ function useServiceProviderInviteService() {
|
|
|
13484
13546
|
}
|
|
13485
13547
|
let result;
|
|
13486
13548
|
try {
|
|
13487
|
-
result = await useCustomerSiteService().addViaInvite(
|
|
13488
|
-
id
|
|
13489
|
-
name: actor.name
|
|
13490
|
-
|
|
13549
|
+
result = await useCustomerSiteService().addViaInvite(
|
|
13550
|
+
id,
|
|
13551
|
+
{ id: actor.id, name: actor.name },
|
|
13552
|
+
forOrg || void 0
|
|
13553
|
+
);
|
|
13491
13554
|
} catch (error) {
|
|
13492
13555
|
const now = await load(id).catch(() => null);
|
|
13493
13556
|
if (now?.status === "complete" /* COMPLETE */) {
|
|
@@ -13496,21 +13559,21 @@ function useServiceProviderInviteService() {
|
|
|
13496
13559
|
throw error;
|
|
13497
13560
|
}
|
|
13498
13561
|
if (result.accepted)
|
|
13499
|
-
await notifyInviter(invite, true);
|
|
13562
|
+
await notifyInviter(invite, true, result.providerOrgName);
|
|
13500
13563
|
return { message: result.message };
|
|
13501
13564
|
}
|
|
13502
|
-
async function notifyInviter(invite, accepted) {
|
|
13565
|
+
async function notifyInviter(invite, accepted, providerName) {
|
|
13503
13566
|
try {
|
|
13504
13567
|
const to = invite.metadata?.invitedBy?.toString?.() ?? "";
|
|
13505
13568
|
if (!to)
|
|
13506
13569
|
return;
|
|
13507
|
-
const providerOrg = await getOrgByEmail(
|
|
13570
|
+
const providerOrg = providerName ? null : await getOrgByEmail(
|
|
13508
13571
|
String(invite.email ?? "").trim().toLowerCase()
|
|
13509
13572
|
).catch(() => null);
|
|
13510
13573
|
await NotificationService.serviceProviderInviteAnswered({
|
|
13511
13574
|
to,
|
|
13512
13575
|
accepted,
|
|
13513
|
-
providerName: providerOrg?.name || String(invite.email ?? ""),
|
|
13576
|
+
providerName: providerName || providerOrg?.name || String(invite.email ?? ""),
|
|
13514
13577
|
siteName: invite.metadata?.siteName ?? "the site"
|
|
13515
13578
|
});
|
|
13516
13579
|
} catch (error) {
|
|
@@ -13520,61 +13583,114 @@ function useServiceProviderInviteService() {
|
|
|
13520
13583
|
});
|
|
13521
13584
|
}
|
|
13522
13585
|
}
|
|
13523
|
-
|
|
13586
|
+
function memberOrg(actor, org) {
|
|
13587
|
+
const id = String(org ?? "").trim();
|
|
13588
|
+
if (!id)
|
|
13589
|
+
return "";
|
|
13590
|
+
const runs = import_mongodb39.ObjectId.isValid(id) && actor.memberships.some(
|
|
13591
|
+
(m) => m.org === id && (m.companyWideRole === true || !m.siteId && m.orgLevelRole === true)
|
|
13592
|
+
);
|
|
13593
|
+
if (!runs) {
|
|
13594
|
+
throw new import_node_server_utils43.UnauthorizedError(
|
|
13595
|
+
"Only an administrator of that company can answer this invitation for it."
|
|
13596
|
+
);
|
|
13597
|
+
}
|
|
13598
|
+
return id;
|
|
13599
|
+
}
|
|
13600
|
+
async function listReceived({
|
|
13601
|
+
userId,
|
|
13602
|
+
org,
|
|
13603
|
+
status = "pending"
|
|
13604
|
+
}) {
|
|
13524
13605
|
const actor = await actorFor(userId);
|
|
13606
|
+
const forOrg = memberOrg(actor, org);
|
|
13607
|
+
const tab = RECEIVED_INVITE_TABS.includes(status) ? status : "pending";
|
|
13608
|
+
const counts = {
|
|
13609
|
+
pending: 0,
|
|
13610
|
+
accepted: 0,
|
|
13611
|
+
declined: 0,
|
|
13612
|
+
expired: 0
|
|
13613
|
+
};
|
|
13525
13614
|
const user = await getUserById(actor.id).catch(() => null);
|
|
13526
13615
|
const email = String(user?.email ?? "").trim().toLowerCase();
|
|
13527
13616
|
if (!email)
|
|
13528
|
-
return { items: [] };
|
|
13617
|
+
return { items: [], counts };
|
|
13529
13618
|
const data = await _list({
|
|
13530
|
-
statuses: [
|
|
13619
|
+
statuses: [
|
|
13620
|
+
"pending" /* PENDING */,
|
|
13621
|
+
"complete" /* COMPLETE */,
|
|
13622
|
+
"declined" /* DECLINED */,
|
|
13623
|
+
"expired" /* EXPIRED */,
|
|
13624
|
+
"cancelled" /* CANCELLED */
|
|
13625
|
+
],
|
|
13531
13626
|
email,
|
|
13532
13627
|
page: 1,
|
|
13533
|
-
limit:
|
|
13628
|
+
limit: 200
|
|
13534
13629
|
});
|
|
13535
|
-
const
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
const
|
|
13630
|
+
const now = /* @__PURE__ */ new Date();
|
|
13631
|
+
const all = data?.items ?? [];
|
|
13632
|
+
const inTab = [];
|
|
13633
|
+
for (const invite of all) {
|
|
13634
|
+
const t = receivedInviteTab(invite, now);
|
|
13635
|
+
if (!t)
|
|
13636
|
+
continue;
|
|
13637
|
+
counts[t] += 1;
|
|
13638
|
+
if (t === tab)
|
|
13639
|
+
inTab.push(invite);
|
|
13640
|
+
}
|
|
13539
13641
|
const items = await Promise.all(
|
|
13540
|
-
|
|
13541
|
-
_id: invite._id,
|
|
13542
|
-
...await inviteContext(invite),
|
|
13543
|
-
status: invite.status,
|
|
13544
|
-
statusLabel: serviceProviderInviteLabel(invite.status),
|
|
13545
|
-
expireAt: invite.expireAt,
|
|
13546
|
-
providerOrgId: providerOrg?._id?.toString() ?? "",
|
|
13547
|
-
providerOrgName: providerOrg?.name ?? ""
|
|
13548
|
-
}))
|
|
13642
|
+
inTab.map((invite) => receivedRow(invite, forOrg))
|
|
13549
13643
|
);
|
|
13550
|
-
return { items };
|
|
13644
|
+
return { items, counts };
|
|
13551
13645
|
}
|
|
13552
|
-
async function
|
|
13553
|
-
id,
|
|
13554
|
-
userId
|
|
13555
|
-
}) {
|
|
13556
|
-
const actor = await actorFor(userId);
|
|
13557
|
-
const invite = await load(id);
|
|
13558
|
-
await assertInvitedParty(actor.id, invite);
|
|
13559
|
-
if (invite.status === "awaiting-approval" /* AWAITING_APPROVAL */) {
|
|
13560
|
-
throw new import_node_server_utils43.NotFoundError("Invitation not found.");
|
|
13561
|
-
}
|
|
13646
|
+
async function receivedRow(invite, forOrg) {
|
|
13562
13647
|
const { orgName, siteName } = await inviteContext(invite);
|
|
13563
13648
|
const status = serviceProviderInviteViewStatus(invite);
|
|
13564
|
-
const
|
|
13565
|
-
|
|
13566
|
-
|
|
13649
|
+
const metadata = invite.metadata ?? {};
|
|
13650
|
+
const siteId = metadata.siteId?.toString?.() ?? "";
|
|
13651
|
+
const history = invite.history ?? [];
|
|
13652
|
+
const answer = [...history].reverse().find((h) => ["accepted", "declined", "cancelled"].includes(h?.action));
|
|
13653
|
+
let providerOrgId = metadata.providerOrg?.toString?.() ?? "";
|
|
13654
|
+
let providerOrgName = String(metadata.providerOrgName ?? "");
|
|
13655
|
+
if (status === "complete" && !providerOrgId) {
|
|
13656
|
+
const byEmail = await getOrgByEmail(
|
|
13657
|
+
String(invite.email ?? "").trim().toLowerCase()
|
|
13658
|
+
).catch(() => null);
|
|
13659
|
+
providerOrgId = byEmail?._id?.toString() ?? "";
|
|
13660
|
+
providerOrgName = byEmail?.name ?? "";
|
|
13661
|
+
}
|
|
13662
|
+
const onThisOrg = status === "complete" && forOrg && siteId ? await useCustomerSiteRepo().countActiveByOrgAndSite(forOrg, siteId).catch(() => 0) > 0 : false;
|
|
13567
13663
|
return {
|
|
13568
13664
|
_id: invite._id,
|
|
13569
13665
|
orgName,
|
|
13570
13666
|
siteName,
|
|
13571
|
-
|
|
13572
|
-
|
|
13667
|
+
siteId,
|
|
13668
|
+
service: String(metadata.app ?? ""),
|
|
13669
|
+
invitedByName: String(metadata.invitedByName ?? ""),
|
|
13670
|
+
createdAt: invite.createdAt,
|
|
13573
13671
|
expireAt: invite.expireAt,
|
|
13574
|
-
|
|
13575
|
-
|
|
13672
|
+
answeredAt: answer?.at ?? null,
|
|
13673
|
+
status,
|
|
13674
|
+
statusLabel: RECEIVED_INVITE_LABELS[status] ?? serviceProviderInviteLabel(status),
|
|
13675
|
+
providerOrgId,
|
|
13676
|
+
providerOrgName,
|
|
13677
|
+
onThisOrg
|
|
13576
13678
|
};
|
|
13577
13679
|
}
|
|
13680
|
+
async function getForProvider({
|
|
13681
|
+
id,
|
|
13682
|
+
userId,
|
|
13683
|
+
org
|
|
13684
|
+
}) {
|
|
13685
|
+
const actor = await actorFor(userId);
|
|
13686
|
+
const invite = await load(id);
|
|
13687
|
+
await assertInvitedParty(actor.id, invite);
|
|
13688
|
+
if (invite.status === "awaiting-approval" /* AWAITING_APPROVAL */ || invite.status === "rejected" /* REJECTED */) {
|
|
13689
|
+
throw new import_node_server_utils43.NotFoundError("Invitation not found.");
|
|
13690
|
+
}
|
|
13691
|
+
const row = await receivedRow(invite, memberOrg(actor, org));
|
|
13692
|
+
return { ...row, tab: receivedInviteTab(invite) };
|
|
13693
|
+
}
|
|
13578
13694
|
return {
|
|
13579
13695
|
listForCaller,
|
|
13580
13696
|
listApprovals,
|
|
@@ -23511,6 +23627,8 @@ function cameraGrant(params) {
|
|
|
23511
23627
|
return atOrg;
|
|
23512
23628
|
const engaged = params.engagedOrgs?.size ? params.memberships.find(
|
|
23513
23629
|
(membership) => !idOf5(membership.siteId) && params.engagedOrgs.has(idOf5(membership.org))
|
|
23630
|
+
) ?? params.memberships.find(
|
|
23631
|
+
(membership) => membership.companyWideRole === true && params.engagedOrgs.has(idOf5(membership.org))
|
|
23514
23632
|
) : void 0;
|
|
23515
23633
|
return engaged ?? null;
|
|
23516
23634
|
}
|
|
@@ -23878,7 +23996,7 @@ function entitledSiteScope(params) {
|
|
|
23878
23996
|
for (const owned of params.sitesByOrg[org] ?? [])
|
|
23879
23997
|
sites.add(owned);
|
|
23880
23998
|
}
|
|
23881
|
-
if (!site) {
|
|
23999
|
+
if (!site || membership.companyWideRole === true) {
|
|
23882
24000
|
for (const engaged of params.engagedSitesByOrg[org] ?? [])
|
|
23883
24001
|
sites.add(engaged);
|
|
23884
24002
|
}
|
|
@@ -25102,19 +25220,20 @@ function useCameraViewService() {
|
|
|
25102
25220
|
}
|
|
25103
25221
|
const siteOrg = idText(params.site?.orgId ?? params.site?.org);
|
|
25104
25222
|
const widenable = memberships.filter(
|
|
25105
|
-
(membership) => idText(membership.siteId) && idText(membership.siteId) !== String(params.siteObjectId) && siteOrg && idText(membership.org) === siteOrg
|
|
25223
|
+
(membership) => idText(membership.siteId) && idText(membership.siteId) !== String(params.siteObjectId) && (siteOrg && idText(membership.org) === siteOrg || engagedOrgs.has(idText(membership.org)))
|
|
25106
25224
|
);
|
|
25107
|
-
const orgLevel = widenable.length ? await
|
|
25225
|
+
const { orgLevel, companyWide } = widenable.length ? await orgRoleSets(
|
|
25108
25226
|
params.db,
|
|
25109
25227
|
widenable.map((membership) => membership.role)
|
|
25110
|
-
) : /* @__PURE__ */ new Set();
|
|
25228
|
+
) : { orgLevel: /* @__PURE__ */ new Set(), companyWide: /* @__PURE__ */ new Set() };
|
|
25111
25229
|
const grant = cameraGrant({
|
|
25112
25230
|
cameraSite: params.siteObjectId,
|
|
25113
25231
|
// `orgId` is the real field; `org` is kept as a fallback only.
|
|
25114
25232
|
cameraOrg: params.site?.orgId ?? params.site?.org,
|
|
25115
25233
|
memberships: orgLevel.size ? memberships.map((membership) => ({
|
|
25116
25234
|
...membership,
|
|
25117
|
-
orgLevelRole: orgLevel.has(idText(membership.role))
|
|
25235
|
+
orgLevelRole: siteOrg !== "" && idText(membership.org) === siteOrg && orgLevel.has(idText(membership.role)),
|
|
25236
|
+
companyWideRole: engagedOrgs.has(idText(membership.org)) && companyWide.has(idText(membership.role))
|
|
25118
25237
|
})) : memberships,
|
|
25119
25238
|
engagedOrgs,
|
|
25120
25239
|
prefer: params.prefer
|
|
@@ -25826,7 +25945,7 @@ async function entitledSites(req) {
|
|
|
25826
25945
|
);
|
|
25827
25946
|
const siteless = Array.from(
|
|
25828
25947
|
new Set(
|
|
25829
|
-
actor.memberships.filter((m) => !m.siteId).map((m) => m.org).filter((org) => org && import_mongodb55.ObjectId.isValid(org))
|
|
25948
|
+
actor.memberships.filter((m) => !m.siteId || m.companyWideRole === true).map((m) => m.org).filter((org) => org && import_mongodb55.ObjectId.isValid(org))
|
|
25830
25949
|
)
|
|
25831
25950
|
);
|
|
25832
25951
|
const orgObjectIds = orgWide.map((org) => new import_mongodb55.ObjectId(org));
|
|
@@ -91792,6 +91911,15 @@ function useServiceProviderInviteController() {
|
|
|
91792
91911
|
const user = req.user;
|
|
91793
91912
|
return user?.user?.toString?.() || user?._id?.toString?.();
|
|
91794
91913
|
}
|
|
91914
|
+
function optionalOrg(value) {
|
|
91915
|
+
const text2 = String(value ?? "").trim();
|
|
91916
|
+
if (!text2)
|
|
91917
|
+
return void 0;
|
|
91918
|
+
if (!/^[a-f0-9]{24}$/i.test(text2)) {
|
|
91919
|
+
throw new import_node_server_utils282.BadRequestError("Invalid organisation.");
|
|
91920
|
+
}
|
|
91921
|
+
return text2;
|
|
91922
|
+
}
|
|
91795
91923
|
function inviteId(req) {
|
|
91796
91924
|
const { error, value } = import_joi149.default.string().hex().length(24).required().validate(String(req.params.id ?? ""));
|
|
91797
91925
|
if (error)
|
|
@@ -91931,14 +92059,26 @@ function useServiceProviderInviteController() {
|
|
|
91931
92059
|
}
|
|
91932
92060
|
async function accept(req, res, next) {
|
|
91933
92061
|
try {
|
|
91934
|
-
res.json(
|
|
92062
|
+
res.json(
|
|
92063
|
+
await _accept({
|
|
92064
|
+
id: inviteId(req),
|
|
92065
|
+
userId: callerId5(req),
|
|
92066
|
+
org: optionalOrg(req.body?.org)
|
|
92067
|
+
})
|
|
92068
|
+
);
|
|
91935
92069
|
} catch (error) {
|
|
91936
92070
|
next(error);
|
|
91937
92071
|
}
|
|
91938
92072
|
}
|
|
91939
92073
|
async function received(req, res, next) {
|
|
91940
92074
|
try {
|
|
91941
|
-
res.json(
|
|
92075
|
+
res.json(
|
|
92076
|
+
await _listReceived({
|
|
92077
|
+
userId: callerId5(req),
|
|
92078
|
+
org: optionalOrg(req.query?.org),
|
|
92079
|
+
status: String(req.query?.status ?? "pending")
|
|
92080
|
+
})
|
|
92081
|
+
);
|
|
91942
92082
|
} catch (error) {
|
|
91943
92083
|
next(error);
|
|
91944
92084
|
}
|
|
@@ -91946,7 +92086,11 @@ function useServiceProviderInviteController() {
|
|
|
91946
92086
|
async function getOne(req, res, next) {
|
|
91947
92087
|
try {
|
|
91948
92088
|
res.json(
|
|
91949
|
-
await _getForProvider({
|
|
92089
|
+
await _getForProvider({
|
|
92090
|
+
id: inviteId(req),
|
|
92091
|
+
userId: callerId5(req),
|
|
92092
|
+
org: optionalOrg(req.query?.org)
|
|
92093
|
+
})
|
|
91950
92094
|
);
|
|
91951
92095
|
} catch (error) {
|
|
91952
92096
|
next(error);
|
|
@@ -98473,6 +98617,8 @@ function usePersonalEmergencyChainController() {
|
|
|
98473
98617
|
PostSort,
|
|
98474
98618
|
PostStatus,
|
|
98475
98619
|
REALTIME_MAX_FANOUT,
|
|
98620
|
+
RECEIVED_INVITE_LABELS,
|
|
98621
|
+
RECEIVED_INVITE_TABS,
|
|
98476
98622
|
REGISTERED_VEHICLE_CATEGORIES,
|
|
98477
98623
|
ROBOT_APP_SCOPES,
|
|
98478
98624
|
ROBOT_AUDIT_ACTIONS,
|
|
@@ -98716,6 +98862,7 @@ function usePersonalEmergencyChainController() {
|
|
|
98716
98862
|
orgOwnerRepairHandlers,
|
|
98717
98863
|
orgOwnerRepairOn,
|
|
98718
98864
|
orgQualifiesForOwnerRepair,
|
|
98865
|
+
orgRoleSets,
|
|
98719
98866
|
orgSchema,
|
|
98720
98867
|
overnight_parking_requests_namespace_collection,
|
|
98721
98868
|
parseCameraChannel,
|
|
@@ -98746,6 +98893,7 @@ function usePersonalEmergencyChainController() {
|
|
|
98746
98893
|
publicCameraFields,
|
|
98747
98894
|
readLiveItems,
|
|
98748
98895
|
readsAsApprovedAccount,
|
|
98896
|
+
receivedInviteTab,
|
|
98749
98897
|
recordConsoleAction,
|
|
98750
98898
|
refuseServiceProviderInviteAction,
|
|
98751
98899
|
registerCameraTransport,
|