@7365admin1/core 3.74.0 → 3.75.1
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 +12 -0
- package/dist/index.js +48 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/backfill-org-owner-roles.test.mjs +6 -1
- package/test/default-staff-role.test.mjs +1 -1
- package/test/e2e/client-invite-service365.e2e.test.mjs +107 -1
- package/test/org-default-roles.test.mjs +11 -0
- package/test/service-app-type.test.mjs +35 -0
package/dist/index.mjs
CHANGED
|
@@ -3166,6 +3166,30 @@ import {
|
|
|
3166
3166
|
} from "@7365admin1/node-server-utils";
|
|
3167
3167
|
import { v4 as uuidv4 } from "uuid";
|
|
3168
3168
|
|
|
3169
|
+
// src/utils/service-app-type.util.ts
|
|
3170
|
+
var APP_TYPE_ALIASES = Object.freeze({
|
|
3171
|
+
real_estate_developer: "property_management_agency"
|
|
3172
|
+
});
|
|
3173
|
+
function serviceAppType(type) {
|
|
3174
|
+
if (typeof type !== "string")
|
|
3175
|
+
return type;
|
|
3176
|
+
return APP_TYPE_ALIASES[type] ?? type;
|
|
3177
|
+
}
|
|
3178
|
+
function storedAppTypes(type) {
|
|
3179
|
+
const app = serviceAppType(type);
|
|
3180
|
+
return [
|
|
3181
|
+
app,
|
|
3182
|
+
...Object.keys(APP_TYPE_ALIASES).filter((alias) => APP_TYPE_ALIASES[alias] === app)
|
|
3183
|
+
];
|
|
3184
|
+
}
|
|
3185
|
+
function appTypeQuery(type) {
|
|
3186
|
+
const types = storedAppTypes(type);
|
|
3187
|
+
return types.length === 1 ? types[0] : { $in: types };
|
|
3188
|
+
}
|
|
3189
|
+
function sameAppType(a, b) {
|
|
3190
|
+
return !!a && !!b && serviceAppType(a) === serviceAppType(b);
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3169
3193
|
// src/repositories/member.repo.ts
|
|
3170
3194
|
import {
|
|
3171
3195
|
AppError as AppError2,
|
|
@@ -3328,7 +3352,7 @@ function useMemberRepo() {
|
|
|
3328
3352
|
}
|
|
3329
3353
|
async function add(value, session) {
|
|
3330
3354
|
try {
|
|
3331
|
-
value = MMember(value);
|
|
3355
|
+
value = MMember({ ...value, type: serviceAppType(value.type) });
|
|
3332
3356
|
await collection.insertOne(value, { session });
|
|
3333
3357
|
delNamespace().then(() => {
|
|
3334
3358
|
logger7.info(`Cache cleared for namespace: ${namespace_collection3}`);
|
|
@@ -3456,6 +3480,7 @@ function useMemberRepo() {
|
|
|
3456
3480
|
}
|
|
3457
3481
|
}
|
|
3458
3482
|
async function getByUserIdType(user, type) {
|
|
3483
|
+
type = serviceAppType(type);
|
|
3459
3484
|
try {
|
|
3460
3485
|
user = new ObjectId13(user);
|
|
3461
3486
|
} catch (error) {
|
|
@@ -3471,7 +3496,7 @@ function useMemberRepo() {
|
|
|
3471
3496
|
return cachedData;
|
|
3472
3497
|
}
|
|
3473
3498
|
try {
|
|
3474
|
-
const data = await collection.findOne({ user, type });
|
|
3499
|
+
const data = await collection.findOne({ user, type: appTypeQuery(type) });
|
|
3475
3500
|
if (!data) {
|
|
3476
3501
|
throw new NotFoundError5("Member not found.");
|
|
3477
3502
|
}
|
|
@@ -3615,7 +3640,7 @@ function useMemberRepo() {
|
|
|
3615
3640
|
search = search || "";
|
|
3616
3641
|
page = page > 0 ? page - 1 : 0;
|
|
3617
3642
|
const query2 = {
|
|
3618
|
-
type,
|
|
3643
|
+
type: type ? appTypeQuery(type) : type,
|
|
3619
3644
|
status
|
|
3620
3645
|
};
|
|
3621
3646
|
const cacheOptions = {
|
|
@@ -3744,7 +3769,7 @@ function useMemberRepo() {
|
|
|
3744
3769
|
const query2 = {
|
|
3745
3770
|
user,
|
|
3746
3771
|
org: { $nin: [null, ""] },
|
|
3747
|
-
type
|
|
3772
|
+
type: appTypeQuery(type)
|
|
3748
3773
|
};
|
|
3749
3774
|
const cacheOptions = {
|
|
3750
3775
|
page,
|
|
@@ -4137,6 +4162,7 @@ function useMemberRepo() {
|
|
|
4137
4162
|
}
|
|
4138
4163
|
}
|
|
4139
4164
|
async function getByUserIdTypeOrg(user, type, org) {
|
|
4165
|
+
type = serviceAppType(type);
|
|
4140
4166
|
try {
|
|
4141
4167
|
user = new ObjectId13(user);
|
|
4142
4168
|
} catch {
|
|
@@ -4160,7 +4186,7 @@ function useMemberRepo() {
|
|
|
4160
4186
|
try {
|
|
4161
4187
|
const data = await collection.findOne({
|
|
4162
4188
|
user,
|
|
4163
|
-
type,
|
|
4189
|
+
type: appTypeQuery(type),
|
|
4164
4190
|
org
|
|
4165
4191
|
});
|
|
4166
4192
|
if (!data) {
|
|
@@ -9824,7 +9850,7 @@ function pickSiteMembership(rows, type, site, org = "") {
|
|
|
9824
9850
|
if (!site)
|
|
9825
9851
|
return null;
|
|
9826
9852
|
const live = rows.filter(
|
|
9827
|
-
(m) => m.type
|
|
9853
|
+
(m) => sameAppType(m.type, type) && isLiveMembership(m) && (!org || idOf2(m.org) === org)
|
|
9828
9854
|
);
|
|
9829
9855
|
const atSite = live.find((m) => idOf2(m.siteId) === site);
|
|
9830
9856
|
if (atSite)
|
|
@@ -9838,10 +9864,10 @@ function pickLookupMembership(rows, type, site = "", org = "") {
|
|
|
9838
9864
|
const atSite = site ? pickSiteMembership(list, type, site, org) : null;
|
|
9839
9865
|
if (atSite)
|
|
9840
9866
|
return atSite;
|
|
9841
|
-
const inOrg = org ? list.find((m) => m.type
|
|
9867
|
+
const inOrg = org ? list.find((m) => sameAppType(m.type, type) && idOf2(m.org) === org.toLowerCase()) : void 0;
|
|
9842
9868
|
if (inOrg && isLiveMembership(inOrg))
|
|
9843
9869
|
return inOrg;
|
|
9844
|
-
return list.find((m) => m.type
|
|
9870
|
+
return list.find((m) => sameAppType(m.type, type)) ?? null;
|
|
9845
9871
|
}
|
|
9846
9872
|
function memberListSiteScope(memberships, org) {
|
|
9847
9873
|
const inOrg = (memberships ?? []).filter((m) => idOf2(m.org) === idOf2(org));
|
|
@@ -11751,7 +11777,7 @@ function useRoleRepo() {
|
|
|
11751
11777
|
const { delNamespace, setCache, getCache } = useCache14(namespace_collection3);
|
|
11752
11778
|
const { delNamespace: _delDashboardNameSpace } = useCache14("dashboard");
|
|
11753
11779
|
async function addRole(value, session) {
|
|
11754
|
-
value = new MRole(value);
|
|
11780
|
+
value = new MRole({ ...value, type: serviceAppType(value.type) });
|
|
11755
11781
|
try {
|
|
11756
11782
|
const res = await collection.insertOne(value, { session });
|
|
11757
11783
|
delNamespace().then(() => {
|
|
@@ -11815,7 +11841,7 @@ function useRoleRepo() {
|
|
|
11815
11841
|
return cachedData;
|
|
11816
11842
|
}
|
|
11817
11843
|
try {
|
|
11818
|
-
const data = await collection.find({ org, permissions: "*", type, status: "active" }).toArray();
|
|
11844
|
+
const data = await collection.find({ org, permissions: "*", type: appTypeQuery(type), status: "active" }).toArray();
|
|
11819
11845
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
11820
11846
|
logger22.info(`Cache set for key: ${cacheKey}`);
|
|
11821
11847
|
}).catch((err) => {
|
|
@@ -11854,7 +11880,8 @@ function useRoleRepo() {
|
|
|
11854
11880
|
if (!name) {
|
|
11855
11881
|
throw new BadRequestError33("Role name is required.");
|
|
11856
11882
|
}
|
|
11857
|
-
|
|
11883
|
+
type = serviceAppType(type);
|
|
11884
|
+
const query2 = type ? { name, type: appTypeQuery(type) } : { name };
|
|
11858
11885
|
try {
|
|
11859
11886
|
const cacheKey = makeCacheKey11(namespace_collection3, query2);
|
|
11860
11887
|
const cachedData = await getCache(cacheKey);
|
|
@@ -11910,8 +11937,8 @@ function useRoleRepo() {
|
|
|
11910
11937
|
cacheOptions.search = search;
|
|
11911
11938
|
}
|
|
11912
11939
|
if (type) {
|
|
11913
|
-
query2.type = type;
|
|
11914
|
-
cacheOptions.type = type;
|
|
11940
|
+
query2.type = appTypeQuery(type);
|
|
11941
|
+
cacheOptions.type = serviceAppType(type);
|
|
11915
11942
|
}
|
|
11916
11943
|
const cacheKey = makeCacheKey11(namespace_collection3, cacheOptions);
|
|
11917
11944
|
const cachedData = await getCache(cacheKey);
|
|
@@ -14552,13 +14579,14 @@ function defaultOwnerRoles(org, nature, appOwnerPermissions) {
|
|
|
14552
14579
|
{ ...owner, type: "organization" },
|
|
14553
14580
|
{ ...administrator, type: "organization" }
|
|
14554
14581
|
];
|
|
14555
|
-
|
|
14582
|
+
const appType = serviceAppType(nature);
|
|
14583
|
+
if (appType && APP_SERVICE_TYPES.has(appType)) {
|
|
14556
14584
|
roles.push({
|
|
14557
14585
|
...owner,
|
|
14558
|
-
type:
|
|
14586
|
+
type: appType,
|
|
14559
14587
|
...appOwnerPermissions?.length && { permissions: [...appOwnerPermissions] }
|
|
14560
14588
|
});
|
|
14561
|
-
roles.push({ ...administrator, type:
|
|
14589
|
+
roles.push({ ...administrator, type: appType });
|
|
14562
14590
|
}
|
|
14563
14591
|
return roles;
|
|
14564
14592
|
}
|
|
@@ -14643,15 +14671,16 @@ async function moduleCeiling(org, site) {
|
|
|
14643
14671
|
}
|
|
14644
14672
|
async function ownerGrantCeiling(org, type) {
|
|
14645
14673
|
const orgId = org?.toString() ?? "";
|
|
14674
|
+
type = serviceAppType(type);
|
|
14646
14675
|
if (!orgId || !type)
|
|
14647
14676
|
return null;
|
|
14648
14677
|
try {
|
|
14649
14678
|
const orgDoc = await useOrgRepo().getById(orgId).catch(() => null);
|
|
14650
|
-
if (!orgDoc?.invitedRole || orgDoc
|
|
14679
|
+
if (!orgDoc?.invitedRole || !sameAppType(orgDoc?.nature, type))
|
|
14651
14680
|
return null;
|
|
14652
14681
|
const role = await useRoleRepo().getRoleById(String(orgDoc.invitedRole)).catch(() => null);
|
|
14653
14682
|
const permissions = role?.permissions;
|
|
14654
|
-
const chosen = role && String(role.org ?? "") === orgId && role.default === true && role.type
|
|
14683
|
+
const chosen = role && String(role.org ?? "") === orgId && role.default === true && sameAppType(role.type, type) && Array.isArray(permissions) && permissions.length > 0 && !permissions.includes("*");
|
|
14655
14684
|
return chosen ? permissions.map(String) : null;
|
|
14656
14685
|
} catch {
|
|
14657
14686
|
return null;
|
|
@@ -25657,7 +25686,7 @@ function useOrgController() {
|
|
|
25657
25686
|
invitedModules?.permissions
|
|
25658
25687
|
);
|
|
25659
25688
|
const appOwnerRole = invitedModules?.permissions.length ? seededRoles.find(
|
|
25660
|
-
(role) => role.type
|
|
25689
|
+
(role) => sameAppType(role.type, body.nature) && role.name === "owner"
|
|
25661
25690
|
) : void 0;
|
|
25662
25691
|
if (appOwnerRole) {
|
|
25663
25692
|
try {
|