@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.mjs
CHANGED
|
@@ -8060,6 +8060,29 @@ function serviceProviderInviteViewStatus(invite, now = /* @__PURE__ */ new Date(
|
|
|
8060
8060
|
return isServiceProviderInviteExpired(invite, now) ? "expired" : String(invite?.status ?? "");
|
|
8061
8061
|
}
|
|
8062
8062
|
var SERVICE_PROVIDER_INVITE_EXPIRED_MESSAGE = "This invitation has expired. Ask the organisation that sent it for a new one.";
|
|
8063
|
+
var RECEIVED_INVITE_TABS = ["pending", "accepted", "declined", "expired"];
|
|
8064
|
+
function receivedInviteTab(invite, now = /* @__PURE__ */ new Date()) {
|
|
8065
|
+
switch (serviceProviderInviteViewStatus(invite, now)) {
|
|
8066
|
+
case "pending":
|
|
8067
|
+
return "pending";
|
|
8068
|
+
case "complete":
|
|
8069
|
+
return "accepted";
|
|
8070
|
+
case "declined":
|
|
8071
|
+
return "declined";
|
|
8072
|
+
case "expired":
|
|
8073
|
+
case "cancelled":
|
|
8074
|
+
return "expired";
|
|
8075
|
+
default:
|
|
8076
|
+
return null;
|
|
8077
|
+
}
|
|
8078
|
+
}
|
|
8079
|
+
var RECEIVED_INVITE_LABELS = {
|
|
8080
|
+
pending: "Waiting for you",
|
|
8081
|
+
complete: "Accepted",
|
|
8082
|
+
declined: "Declined",
|
|
8083
|
+
expired: "Expired",
|
|
8084
|
+
cancelled: "Withdrawn by the client"
|
|
8085
|
+
};
|
|
8063
8086
|
|
|
8064
8087
|
// src/utils/invite-actor.util.ts
|
|
8065
8088
|
import { useAtlas as useAtlas16 } from "@7365admin1/node-server-utils";
|
|
@@ -8106,7 +8129,7 @@ async function resolveInviteActor(userId) {
|
|
|
8106
8129
|
members.map((m) => m.role?.toString?.() ?? "").filter((r) => r && ObjectId25.isValid(r))
|
|
8107
8130
|
)
|
|
8108
8131
|
);
|
|
8109
|
-
const orgLevelRoleIds = await
|
|
8132
|
+
const { orgLevel: orgLevelRoleIds, companyWide: companyWideRoleIds } = await orgRoleSets(db2, memberRoleIds);
|
|
8110
8133
|
return {
|
|
8111
8134
|
id,
|
|
8112
8135
|
name: user?.name ?? adminMember?.name ?? "",
|
|
@@ -8118,6 +8141,7 @@ async function resolveInviteActor(userId) {
|
|
|
8118
8141
|
org: m.org?.toString?.() ?? "",
|
|
8119
8142
|
siteId: m.siteId?.toString?.() ?? "",
|
|
8120
8143
|
orgLevelRole: orgLevelRoleIds.has(m.role?.toString?.() ?? ""),
|
|
8144
|
+
companyWideRole: companyWideRoleIds.has(m.role?.toString?.() ?? ""),
|
|
8121
8145
|
type: m.type ?? ""
|
|
8122
8146
|
}))
|
|
8123
8147
|
};
|
|
@@ -8188,23 +8212,31 @@ async function invitationOffersRole(userId, orgId, roleId) {
|
|
|
8188
8212
|
);
|
|
8189
8213
|
}
|
|
8190
8214
|
async function orgLevelRoles(db2, roles) {
|
|
8215
|
+
return (await orgRoleSets(db2, roles)).orgLevel;
|
|
8216
|
+
}
|
|
8217
|
+
async function orgRoleSets(db2, roles) {
|
|
8191
8218
|
const ids2 = Array.from(
|
|
8192
8219
|
new Set(
|
|
8193
8220
|
roles.map((role) => role?.toString?.() ?? "").filter((role) => role && ObjectId25.isValid(role))
|
|
8194
8221
|
)
|
|
8195
8222
|
);
|
|
8196
8223
|
const orgLevel = /* @__PURE__ */ new Set();
|
|
8224
|
+
const companyWide = /* @__PURE__ */ new Set();
|
|
8197
8225
|
if (!ids2.length)
|
|
8198
|
-
return orgLevel;
|
|
8226
|
+
return { orgLevel, companyWide };
|
|
8199
8227
|
const docs = await db2.collection("roles").find(
|
|
8200
8228
|
{ _id: { $in: ids2.map((id) => new ObjectId25(id)) }, ...LIVE_ROLE },
|
|
8201
|
-
{ projection: { site: 1 } }
|
|
8229
|
+
{ projection: { site: 1, type: 1, permissions: 1 } }
|
|
8202
8230
|
).toArray();
|
|
8203
8231
|
for (const role of docs) {
|
|
8204
|
-
if (
|
|
8205
|
-
|
|
8232
|
+
if (role.site)
|
|
8233
|
+
continue;
|
|
8234
|
+
orgLevel.add(role._id.toString());
|
|
8235
|
+
if (role.type === "organization") {
|
|
8236
|
+
companyWide.add(role._id.toString());
|
|
8237
|
+
}
|
|
8206
8238
|
}
|
|
8207
|
-
return orgLevel;
|
|
8239
|
+
return { orgLevel, companyWide };
|
|
8208
8240
|
}
|
|
8209
8241
|
async function hasOrgOwnership(userId, orgId) {
|
|
8210
8242
|
const id = userId?.toString() ?? "";
|
|
@@ -11869,11 +11901,10 @@ function useCustomerSiteService() {
|
|
|
11869
11901
|
}
|
|
11870
11902
|
const { getById: getVerificationById } = useVerificationRepo();
|
|
11871
11903
|
const {
|
|
11872
|
-
updateVerificationStatusById: _updateVerificationStatusById,
|
|
11873
11904
|
getServiceProviderInviteById: _getInviteFresh,
|
|
11874
11905
|
transitionServiceProviderInvite: _transitionInvite
|
|
11875
11906
|
} = useVerificationRepoV2();
|
|
11876
|
-
async function addViaInvite(invite, actor) {
|
|
11907
|
+
async function addViaInvite(invite, actor, forOrgId) {
|
|
11877
11908
|
const session = useAtlas24.getClient()?.startSession();
|
|
11878
11909
|
session?.startTransaction();
|
|
11879
11910
|
try {
|
|
@@ -11897,7 +11928,7 @@ function useCustomerSiteService() {
|
|
|
11897
11928
|
if (!site) {
|
|
11898
11929
|
throw new NotFoundError11("Site not found.");
|
|
11899
11930
|
}
|
|
11900
|
-
const serviceProvider = await getOrgByEmail(
|
|
11931
|
+
const serviceProvider = forOrgId ? await _getByOrgId(forOrgId) : await getOrgByEmail(
|
|
11901
11932
|
String(verification.email ?? "").trim().toLowerCase()
|
|
11902
11933
|
);
|
|
11903
11934
|
if (!serviceProvider) {
|
|
@@ -11908,9 +11939,25 @@ function useCustomerSiteService() {
|
|
|
11908
11939
|
providerOrgId,
|
|
11909
11940
|
siteId
|
|
11910
11941
|
);
|
|
11942
|
+
const accepted = {
|
|
11943
|
+
"metadata.providerOrg": providerOrgId,
|
|
11944
|
+
"metadata.providerOrgName": serviceProvider.name ?? ""
|
|
11945
|
+
};
|
|
11911
11946
|
if (alreadyEngaged > 0) {
|
|
11912
11947
|
if (verification.status === "pending") {
|
|
11913
|
-
await
|
|
11948
|
+
await _transitionInvite({
|
|
11949
|
+
id: invite,
|
|
11950
|
+
from: ["pending"],
|
|
11951
|
+
to: "complete",
|
|
11952
|
+
event: {
|
|
11953
|
+
action: "accepted",
|
|
11954
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11955
|
+
by: actor?.id ? new ObjectId36(actor.id) : null,
|
|
11956
|
+
byName: actor?.name ?? ""
|
|
11957
|
+
},
|
|
11958
|
+
set: accepted,
|
|
11959
|
+
session
|
|
11960
|
+
});
|
|
11914
11961
|
}
|
|
11915
11962
|
await session?.commitTransaction();
|
|
11916
11963
|
return { message: "This site is already on your list.", accepted: false };
|
|
@@ -11951,6 +11998,7 @@ function useCustomerSiteService() {
|
|
|
11951
11998
|
by: actor?.id ? new ObjectId36(actor.id) : null,
|
|
11952
11999
|
byName: actor?.name ?? ""
|
|
11953
12000
|
},
|
|
12001
|
+
set: accepted,
|
|
11954
12002
|
session
|
|
11955
12003
|
});
|
|
11956
12004
|
if (!closed) {
|
|
@@ -11969,7 +12017,12 @@ function useCustomerSiteService() {
|
|
|
11969
12017
|
session
|
|
11970
12018
|
);
|
|
11971
12019
|
await session?.commitTransaction();
|
|
11972
|
-
return {
|
|
12020
|
+
return {
|
|
12021
|
+
message: "Invite accepted, successfully added site.",
|
|
12022
|
+
accepted: true,
|
|
12023
|
+
providerOrgId,
|
|
12024
|
+
providerOrgName: serviceProvider.name ?? ""
|
|
12025
|
+
};
|
|
11973
12026
|
} catch (error) {
|
|
11974
12027
|
await session?.abortTransaction();
|
|
11975
12028
|
throw error;
|
|
@@ -12610,10 +12663,15 @@ function useServiceProviderInviteService() {
|
|
|
12610
12663
|
await notifyInviter(invite, false);
|
|
12611
12664
|
return { message: "Invitation declined." };
|
|
12612
12665
|
}
|
|
12613
|
-
async function accept({
|
|
12666
|
+
async function accept({
|
|
12667
|
+
id,
|
|
12668
|
+
userId,
|
|
12669
|
+
org
|
|
12670
|
+
}) {
|
|
12614
12671
|
const actor = await actorFor(userId);
|
|
12615
12672
|
const invite = await load(id);
|
|
12616
12673
|
await assertInvitedParty(actor.id, invite);
|
|
12674
|
+
const forOrg = memberOrg(actor, org);
|
|
12617
12675
|
if (![SERVICE_PROVIDER_SIGN_IN_TYPE, SERVICE_PROVIDER_SIGN_UP_TYPE].includes(
|
|
12618
12676
|
String(invite.type ?? "")
|
|
12619
12677
|
)) {
|
|
@@ -12630,10 +12688,11 @@ function useServiceProviderInviteService() {
|
|
|
12630
12688
|
}
|
|
12631
12689
|
let result;
|
|
12632
12690
|
try {
|
|
12633
|
-
result = await useCustomerSiteService().addViaInvite(
|
|
12634
|
-
id
|
|
12635
|
-
name: actor.name
|
|
12636
|
-
|
|
12691
|
+
result = await useCustomerSiteService().addViaInvite(
|
|
12692
|
+
id,
|
|
12693
|
+
{ id: actor.id, name: actor.name },
|
|
12694
|
+
forOrg || void 0
|
|
12695
|
+
);
|
|
12637
12696
|
} catch (error) {
|
|
12638
12697
|
const now = await load(id).catch(() => null);
|
|
12639
12698
|
if (now?.status === "complete" /* COMPLETE */) {
|
|
@@ -12642,21 +12701,21 @@ function useServiceProviderInviteService() {
|
|
|
12642
12701
|
throw error;
|
|
12643
12702
|
}
|
|
12644
12703
|
if (result.accepted)
|
|
12645
|
-
await notifyInviter(invite, true);
|
|
12704
|
+
await notifyInviter(invite, true, result.providerOrgName);
|
|
12646
12705
|
return { message: result.message };
|
|
12647
12706
|
}
|
|
12648
|
-
async function notifyInviter(invite, accepted) {
|
|
12707
|
+
async function notifyInviter(invite, accepted, providerName) {
|
|
12649
12708
|
try {
|
|
12650
12709
|
const to = invite.metadata?.invitedBy?.toString?.() ?? "";
|
|
12651
12710
|
if (!to)
|
|
12652
12711
|
return;
|
|
12653
|
-
const providerOrg = await getOrgByEmail(
|
|
12712
|
+
const providerOrg = providerName ? null : await getOrgByEmail(
|
|
12654
12713
|
String(invite.email ?? "").trim().toLowerCase()
|
|
12655
12714
|
).catch(() => null);
|
|
12656
12715
|
await NotificationService.serviceProviderInviteAnswered({
|
|
12657
12716
|
to,
|
|
12658
12717
|
accepted,
|
|
12659
|
-
providerName: providerOrg?.name || String(invite.email ?? ""),
|
|
12718
|
+
providerName: providerName || providerOrg?.name || String(invite.email ?? ""),
|
|
12660
12719
|
siteName: invite.metadata?.siteName ?? "the site"
|
|
12661
12720
|
});
|
|
12662
12721
|
} catch (error) {
|
|
@@ -12666,61 +12725,114 @@ function useServiceProviderInviteService() {
|
|
|
12666
12725
|
});
|
|
12667
12726
|
}
|
|
12668
12727
|
}
|
|
12669
|
-
|
|
12728
|
+
function memberOrg(actor, org) {
|
|
12729
|
+
const id = String(org ?? "").trim();
|
|
12730
|
+
if (!id)
|
|
12731
|
+
return "";
|
|
12732
|
+
const runs = ObjectId39.isValid(id) && actor.memberships.some(
|
|
12733
|
+
(m) => m.org === id && (m.companyWideRole === true || !m.siteId && m.orgLevelRole === true)
|
|
12734
|
+
);
|
|
12735
|
+
if (!runs) {
|
|
12736
|
+
throw new UnauthorizedError3(
|
|
12737
|
+
"Only an administrator of that company can answer this invitation for it."
|
|
12738
|
+
);
|
|
12739
|
+
}
|
|
12740
|
+
return id;
|
|
12741
|
+
}
|
|
12742
|
+
async function listReceived({
|
|
12743
|
+
userId,
|
|
12744
|
+
org,
|
|
12745
|
+
status = "pending"
|
|
12746
|
+
}) {
|
|
12670
12747
|
const actor = await actorFor(userId);
|
|
12748
|
+
const forOrg = memberOrg(actor, org);
|
|
12749
|
+
const tab = RECEIVED_INVITE_TABS.includes(status) ? status : "pending";
|
|
12750
|
+
const counts = {
|
|
12751
|
+
pending: 0,
|
|
12752
|
+
accepted: 0,
|
|
12753
|
+
declined: 0,
|
|
12754
|
+
expired: 0
|
|
12755
|
+
};
|
|
12671
12756
|
const user = await getUserById(actor.id).catch(() => null);
|
|
12672
12757
|
const email = String(user?.email ?? "").trim().toLowerCase();
|
|
12673
12758
|
if (!email)
|
|
12674
|
-
return { items: [] };
|
|
12759
|
+
return { items: [], counts };
|
|
12675
12760
|
const data = await _list({
|
|
12676
|
-
statuses: [
|
|
12761
|
+
statuses: [
|
|
12762
|
+
"pending" /* PENDING */,
|
|
12763
|
+
"complete" /* COMPLETE */,
|
|
12764
|
+
"declined" /* DECLINED */,
|
|
12765
|
+
"expired" /* EXPIRED */,
|
|
12766
|
+
"cancelled" /* CANCELLED */
|
|
12767
|
+
],
|
|
12677
12768
|
email,
|
|
12678
12769
|
page: 1,
|
|
12679
|
-
limit:
|
|
12770
|
+
limit: 200
|
|
12680
12771
|
});
|
|
12681
|
-
const
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
const
|
|
12772
|
+
const now = /* @__PURE__ */ new Date();
|
|
12773
|
+
const all = data?.items ?? [];
|
|
12774
|
+
const inTab = [];
|
|
12775
|
+
for (const invite of all) {
|
|
12776
|
+
const t = receivedInviteTab(invite, now);
|
|
12777
|
+
if (!t)
|
|
12778
|
+
continue;
|
|
12779
|
+
counts[t] += 1;
|
|
12780
|
+
if (t === tab)
|
|
12781
|
+
inTab.push(invite);
|
|
12782
|
+
}
|
|
12685
12783
|
const items = await Promise.all(
|
|
12686
|
-
|
|
12687
|
-
_id: invite._id,
|
|
12688
|
-
...await inviteContext(invite),
|
|
12689
|
-
status: invite.status,
|
|
12690
|
-
statusLabel: serviceProviderInviteLabel(invite.status),
|
|
12691
|
-
expireAt: invite.expireAt,
|
|
12692
|
-
providerOrgId: providerOrg?._id?.toString() ?? "",
|
|
12693
|
-
providerOrgName: providerOrg?.name ?? ""
|
|
12694
|
-
}))
|
|
12784
|
+
inTab.map((invite) => receivedRow(invite, forOrg))
|
|
12695
12785
|
);
|
|
12696
|
-
return { items };
|
|
12786
|
+
return { items, counts };
|
|
12697
12787
|
}
|
|
12698
|
-
async function
|
|
12699
|
-
id,
|
|
12700
|
-
userId
|
|
12701
|
-
}) {
|
|
12702
|
-
const actor = await actorFor(userId);
|
|
12703
|
-
const invite = await load(id);
|
|
12704
|
-
await assertInvitedParty(actor.id, invite);
|
|
12705
|
-
if (invite.status === "awaiting-approval" /* AWAITING_APPROVAL */) {
|
|
12706
|
-
throw new NotFoundError12("Invitation not found.");
|
|
12707
|
-
}
|
|
12788
|
+
async function receivedRow(invite, forOrg) {
|
|
12708
12789
|
const { orgName, siteName } = await inviteContext(invite);
|
|
12709
12790
|
const status = serviceProviderInviteViewStatus(invite);
|
|
12710
|
-
const
|
|
12711
|
-
|
|
12712
|
-
|
|
12791
|
+
const metadata = invite.metadata ?? {};
|
|
12792
|
+
const siteId = metadata.siteId?.toString?.() ?? "";
|
|
12793
|
+
const history = invite.history ?? [];
|
|
12794
|
+
const answer = [...history].reverse().find((h) => ["accepted", "declined", "cancelled"].includes(h?.action));
|
|
12795
|
+
let providerOrgId = metadata.providerOrg?.toString?.() ?? "";
|
|
12796
|
+
let providerOrgName = String(metadata.providerOrgName ?? "");
|
|
12797
|
+
if (status === "complete" && !providerOrgId) {
|
|
12798
|
+
const byEmail = await getOrgByEmail(
|
|
12799
|
+
String(invite.email ?? "").trim().toLowerCase()
|
|
12800
|
+
).catch(() => null);
|
|
12801
|
+
providerOrgId = byEmail?._id?.toString() ?? "";
|
|
12802
|
+
providerOrgName = byEmail?.name ?? "";
|
|
12803
|
+
}
|
|
12804
|
+
const onThisOrg = status === "complete" && forOrg && siteId ? await useCustomerSiteRepo().countActiveByOrgAndSite(forOrg, siteId).catch(() => 0) > 0 : false;
|
|
12713
12805
|
return {
|
|
12714
12806
|
_id: invite._id,
|
|
12715
12807
|
orgName,
|
|
12716
12808
|
siteName,
|
|
12717
|
-
|
|
12718
|
-
|
|
12809
|
+
siteId,
|
|
12810
|
+
service: String(metadata.app ?? ""),
|
|
12811
|
+
invitedByName: String(metadata.invitedByName ?? ""),
|
|
12812
|
+
createdAt: invite.createdAt,
|
|
12719
12813
|
expireAt: invite.expireAt,
|
|
12720
|
-
|
|
12721
|
-
|
|
12814
|
+
answeredAt: answer?.at ?? null,
|
|
12815
|
+
status,
|
|
12816
|
+
statusLabel: RECEIVED_INVITE_LABELS[status] ?? serviceProviderInviteLabel(status),
|
|
12817
|
+
providerOrgId,
|
|
12818
|
+
providerOrgName,
|
|
12819
|
+
onThisOrg
|
|
12722
12820
|
};
|
|
12723
12821
|
}
|
|
12822
|
+
async function getForProvider({
|
|
12823
|
+
id,
|
|
12824
|
+
userId,
|
|
12825
|
+
org
|
|
12826
|
+
}) {
|
|
12827
|
+
const actor = await actorFor(userId);
|
|
12828
|
+
const invite = await load(id);
|
|
12829
|
+
await assertInvitedParty(actor.id, invite);
|
|
12830
|
+
if (invite.status === "awaiting-approval" /* AWAITING_APPROVAL */ || invite.status === "rejected" /* REJECTED */) {
|
|
12831
|
+
throw new NotFoundError12("Invitation not found.");
|
|
12832
|
+
}
|
|
12833
|
+
const row = await receivedRow(invite, memberOrg(actor, org));
|
|
12834
|
+
return { ...row, tab: receivedInviteTab(invite) };
|
|
12835
|
+
}
|
|
12724
12836
|
return {
|
|
12725
12837
|
listForCaller,
|
|
12726
12838
|
listApprovals,
|
|
@@ -22738,6 +22850,8 @@ function cameraGrant(params) {
|
|
|
22738
22850
|
return atOrg;
|
|
22739
22851
|
const engaged = params.engagedOrgs?.size ? params.memberships.find(
|
|
22740
22852
|
(membership) => !idOf5(membership.siteId) && params.engagedOrgs.has(idOf5(membership.org))
|
|
22853
|
+
) ?? params.memberships.find(
|
|
22854
|
+
(membership) => membership.companyWideRole === true && params.engagedOrgs.has(idOf5(membership.org))
|
|
22741
22855
|
) : void 0;
|
|
22742
22856
|
return engaged ?? null;
|
|
22743
22857
|
}
|
|
@@ -23105,7 +23219,7 @@ function entitledSiteScope(params) {
|
|
|
23105
23219
|
for (const owned of params.sitesByOrg[org] ?? [])
|
|
23106
23220
|
sites.add(owned);
|
|
23107
23221
|
}
|
|
23108
|
-
if (!site) {
|
|
23222
|
+
if (!site || membership.companyWideRole === true) {
|
|
23109
23223
|
for (const engaged of params.engagedSitesByOrg[org] ?? [])
|
|
23110
23224
|
sites.add(engaged);
|
|
23111
23225
|
}
|
|
@@ -24329,19 +24443,20 @@ function useCameraViewService() {
|
|
|
24329
24443
|
}
|
|
24330
24444
|
const siteOrg = idText(params.site?.orgId ?? params.site?.org);
|
|
24331
24445
|
const widenable = memberships.filter(
|
|
24332
|
-
(membership) => idText(membership.siteId) && idText(membership.siteId) !== String(params.siteObjectId) && siteOrg && idText(membership.org) === siteOrg
|
|
24446
|
+
(membership) => idText(membership.siteId) && idText(membership.siteId) !== String(params.siteObjectId) && (siteOrg && idText(membership.org) === siteOrg || engagedOrgs.has(idText(membership.org)))
|
|
24333
24447
|
);
|
|
24334
|
-
const orgLevel = widenable.length ? await
|
|
24448
|
+
const { orgLevel, companyWide } = widenable.length ? await orgRoleSets(
|
|
24335
24449
|
params.db,
|
|
24336
24450
|
widenable.map((membership) => membership.role)
|
|
24337
|
-
) : /* @__PURE__ */ new Set();
|
|
24451
|
+
) : { orgLevel: /* @__PURE__ */ new Set(), companyWide: /* @__PURE__ */ new Set() };
|
|
24338
24452
|
const grant = cameraGrant({
|
|
24339
24453
|
cameraSite: params.siteObjectId,
|
|
24340
24454
|
// `orgId` is the real field; `org` is kept as a fallback only.
|
|
24341
24455
|
cameraOrg: params.site?.orgId ?? params.site?.org,
|
|
24342
24456
|
memberships: orgLevel.size ? memberships.map((membership) => ({
|
|
24343
24457
|
...membership,
|
|
24344
|
-
orgLevelRole: orgLevel.has(idText(membership.role))
|
|
24458
|
+
orgLevelRole: siteOrg !== "" && idText(membership.org) === siteOrg && orgLevel.has(idText(membership.role)),
|
|
24459
|
+
companyWideRole: engagedOrgs.has(idText(membership.org)) && companyWide.has(idText(membership.role))
|
|
24345
24460
|
})) : memberships,
|
|
24346
24461
|
engagedOrgs,
|
|
24347
24462
|
prefer: params.prefer
|
|
@@ -25053,7 +25168,7 @@ async function entitledSites(req) {
|
|
|
25053
25168
|
);
|
|
25054
25169
|
const siteless = Array.from(
|
|
25055
25170
|
new Set(
|
|
25056
|
-
actor.memberships.filter((m) => !m.siteId).map((m) => m.org).filter((org) => org && ObjectId55.isValid(org))
|
|
25171
|
+
actor.memberships.filter((m) => !m.siteId || m.companyWideRole === true).map((m) => m.org).filter((org) => org && ObjectId55.isValid(org))
|
|
25057
25172
|
)
|
|
25058
25173
|
);
|
|
25059
25174
|
const orgObjectIds = orgWide.map((org) => new ObjectId55(org));
|
|
@@ -91682,6 +91797,15 @@ function useServiceProviderInviteController() {
|
|
|
91682
91797
|
const user = req.user;
|
|
91683
91798
|
return user?.user?.toString?.() || user?._id?.toString?.();
|
|
91684
91799
|
}
|
|
91800
|
+
function optionalOrg(value) {
|
|
91801
|
+
const text2 = String(value ?? "").trim();
|
|
91802
|
+
if (!text2)
|
|
91803
|
+
return void 0;
|
|
91804
|
+
if (!/^[a-f0-9]{24}$/i.test(text2)) {
|
|
91805
|
+
throw new BadRequestError240("Invalid organisation.");
|
|
91806
|
+
}
|
|
91807
|
+
return text2;
|
|
91808
|
+
}
|
|
91685
91809
|
function inviteId(req) {
|
|
91686
91810
|
const { error, value } = Joi149.string().hex().length(24).required().validate(String(req.params.id ?? ""));
|
|
91687
91811
|
if (error)
|
|
@@ -91821,14 +91945,26 @@ function useServiceProviderInviteController() {
|
|
|
91821
91945
|
}
|
|
91822
91946
|
async function accept(req, res, next) {
|
|
91823
91947
|
try {
|
|
91824
|
-
res.json(
|
|
91948
|
+
res.json(
|
|
91949
|
+
await _accept({
|
|
91950
|
+
id: inviteId(req),
|
|
91951
|
+
userId: callerId5(req),
|
|
91952
|
+
org: optionalOrg(req.body?.org)
|
|
91953
|
+
})
|
|
91954
|
+
);
|
|
91825
91955
|
} catch (error) {
|
|
91826
91956
|
next(error);
|
|
91827
91957
|
}
|
|
91828
91958
|
}
|
|
91829
91959
|
async function received(req, res, next) {
|
|
91830
91960
|
try {
|
|
91831
|
-
res.json(
|
|
91961
|
+
res.json(
|
|
91962
|
+
await _listReceived({
|
|
91963
|
+
userId: callerId5(req),
|
|
91964
|
+
org: optionalOrg(req.query?.org),
|
|
91965
|
+
status: String(req.query?.status ?? "pending")
|
|
91966
|
+
})
|
|
91967
|
+
);
|
|
91832
91968
|
} catch (error) {
|
|
91833
91969
|
next(error);
|
|
91834
91970
|
}
|
|
@@ -91836,7 +91972,11 @@ function useServiceProviderInviteController() {
|
|
|
91836
91972
|
async function getOne(req, res, next) {
|
|
91837
91973
|
try {
|
|
91838
91974
|
res.json(
|
|
91839
|
-
await _getForProvider({
|
|
91975
|
+
await _getForProvider({
|
|
91976
|
+
id: inviteId(req),
|
|
91977
|
+
userId: callerId5(req),
|
|
91978
|
+
org: optionalOrg(req.query?.org)
|
|
91979
|
+
})
|
|
91840
91980
|
);
|
|
91841
91981
|
} catch (error) {
|
|
91842
91982
|
next(error);
|
|
@@ -98444,6 +98584,8 @@ export {
|
|
|
98444
98584
|
PostSort,
|
|
98445
98585
|
PostStatus,
|
|
98446
98586
|
REALTIME_MAX_FANOUT,
|
|
98587
|
+
RECEIVED_INVITE_LABELS,
|
|
98588
|
+
RECEIVED_INVITE_TABS,
|
|
98447
98589
|
REGISTERED_VEHICLE_CATEGORIES,
|
|
98448
98590
|
ROBOT_APP_SCOPES,
|
|
98449
98591
|
ROBOT_AUDIT_ACTIONS,
|
|
@@ -98687,6 +98829,7 @@ export {
|
|
|
98687
98829
|
orgOwnerRepairHandlers,
|
|
98688
98830
|
orgOwnerRepairOn,
|
|
98689
98831
|
orgQualifiesForOwnerRepair,
|
|
98832
|
+
orgRoleSets,
|
|
98690
98833
|
orgSchema,
|
|
98691
98834
|
overnight_parking_requests_namespace_collection,
|
|
98692
98835
|
parseCameraChannel,
|
|
@@ -98717,6 +98860,7 @@ export {
|
|
|
98717
98860
|
publicCameraFields,
|
|
98718
98861
|
readLiveItems,
|
|
98719
98862
|
readsAsApprovedAccount,
|
|
98863
|
+
receivedInviteTab,
|
|
98720
98864
|
recordConsoleAction,
|
|
98721
98865
|
refuseServiceProviderInviteAction,
|
|
98722
98866
|
registerCameraTransport,
|