@7365admin1/core 3.47.1-staging.146 → 3.47.1-staging.147
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/dist/index.d.ts +1 -0
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/document-scope.e2e.test.mjs +299 -0
- package/test/e2e/harness.mjs +25 -0
package/dist/index.d.ts
CHANGED
|
@@ -5472,6 +5472,7 @@ declare function useDocumentManagementRepo(): {
|
|
|
5472
5472
|
pageRange: string;
|
|
5473
5473
|
} | TDocumentManagement>;
|
|
5474
5474
|
getDocumentById: (_id: string | ObjectId) => Promise<bson.Document>;
|
|
5475
|
+
getDocumentScope: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
5475
5476
|
updateDocumentById: (_id: string | ObjectId, value: TDocumentManagement) => Promise<number>;
|
|
5476
5477
|
updateFolderById: (_id: string | ObjectId, value: TFolderUpdate) => Promise<number>;
|
|
5477
5478
|
deleteDocumentById: (_id: string | ObjectId, session?: ClientSession) => Promise<number>;
|
package/dist/index.js
CHANGED
|
@@ -55480,12 +55480,25 @@ function useDocumentManagementRepo() {
|
|
|
55480
55480
|
throw error;
|
|
55481
55481
|
}
|
|
55482
55482
|
}
|
|
55483
|
+
async function getDocumentScope(_id) {
|
|
55484
|
+
let id;
|
|
55485
|
+
try {
|
|
55486
|
+
id = new import_mongodb102.ObjectId(_id);
|
|
55487
|
+
} catch (error) {
|
|
55488
|
+
throw new import_node_server_utils164.BadRequestError("Invalid document ID format.");
|
|
55489
|
+
}
|
|
55490
|
+
return await collection.findOne(
|
|
55491
|
+
{ _id: id },
|
|
55492
|
+
{ projection: { site: 1, org: 1 } }
|
|
55493
|
+
);
|
|
55494
|
+
}
|
|
55483
55495
|
return {
|
|
55484
55496
|
createIndex,
|
|
55485
55497
|
createTextIndex,
|
|
55486
55498
|
add,
|
|
55487
55499
|
getAll,
|
|
55488
55500
|
getDocumentById,
|
|
55501
|
+
getDocumentScope,
|
|
55489
55502
|
updateDocumentById,
|
|
55490
55503
|
updateFolderById,
|
|
55491
55504
|
deleteDocumentById,
|
|
@@ -55740,8 +55753,24 @@ function useDocumentManagementController() {
|
|
|
55740
55753
|
updateFolderById: _updateFolderById,
|
|
55741
55754
|
deleteDocumentById: _deleteDocumentById,
|
|
55742
55755
|
deleteFolderById: _deleteFolderById,
|
|
55743
|
-
getDocumentManagementBySiteId: _getDocumentManagementBySiteId
|
|
55756
|
+
getDocumentManagementBySiteId: _getDocumentManagementBySiteId,
|
|
55757
|
+
getDocumentScope: _getDocumentScope
|
|
55744
55758
|
} = useDocumentManagementRepo();
|
|
55759
|
+
async function requireDocumentReach(req, _id) {
|
|
55760
|
+
const doc = await _getDocumentScope(_id);
|
|
55761
|
+
const site = doc?.site?.toString() ?? "";
|
|
55762
|
+
if (site) {
|
|
55763
|
+
await requireSiteReach(req, site);
|
|
55764
|
+
return;
|
|
55765
|
+
}
|
|
55766
|
+
const actor = await resolveInviteActor(callerId(req));
|
|
55767
|
+
if (actor.isSuperAdmin)
|
|
55768
|
+
return;
|
|
55769
|
+
const org = doc?.org?.toString() ?? "";
|
|
55770
|
+
if (!org || !actor.orgIds.includes(org)) {
|
|
55771
|
+
throw new import_node_server_utils166.NotFoundError("Document not found.");
|
|
55772
|
+
}
|
|
55773
|
+
}
|
|
55745
55774
|
async function add(req, res, next) {
|
|
55746
55775
|
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
55747
55776
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
@@ -55834,6 +55863,7 @@ function useDocumentManagementController() {
|
|
|
55834
55863
|
return;
|
|
55835
55864
|
}
|
|
55836
55865
|
try {
|
|
55866
|
+
await requireDocumentReach(req, _id);
|
|
55837
55867
|
const data = await _getDocumentById(_id);
|
|
55838
55868
|
res.json(data);
|
|
55839
55869
|
return;
|
|
@@ -55875,6 +55905,7 @@ function useDocumentManagementController() {
|
|
|
55875
55905
|
return;
|
|
55876
55906
|
}
|
|
55877
55907
|
try {
|
|
55908
|
+
await requireDocumentReach(req, _id);
|
|
55878
55909
|
await _updateDocumentById(_id, payload);
|
|
55879
55910
|
res.json({ message: "Successfully updated document." });
|
|
55880
55911
|
return;
|
|
@@ -55907,6 +55938,7 @@ function useDocumentManagementController() {
|
|
|
55907
55938
|
return;
|
|
55908
55939
|
}
|
|
55909
55940
|
try {
|
|
55941
|
+
await requireDocumentReach(req, _id);
|
|
55910
55942
|
await _updateFolderById(_id, payload);
|
|
55911
55943
|
res.json({ message: "Successfully updated folder." });
|
|
55912
55944
|
return;
|
|
@@ -55926,6 +55958,7 @@ function useDocumentManagementController() {
|
|
|
55926
55958
|
return;
|
|
55927
55959
|
}
|
|
55928
55960
|
try {
|
|
55961
|
+
await requireDocumentReach(req, _id);
|
|
55929
55962
|
await _deleteDocumentById(_id);
|
|
55930
55963
|
res.json({ message: "Successfully deleted document." });
|
|
55931
55964
|
return;
|
|
@@ -55945,6 +55978,7 @@ function useDocumentManagementController() {
|
|
|
55945
55978
|
return;
|
|
55946
55979
|
}
|
|
55947
55980
|
try {
|
|
55981
|
+
await requireDocumentReach(req, _id);
|
|
55948
55982
|
await _deleteFolderById(_id);
|
|
55949
55983
|
res.json({ message: "Successfully deleted folder." });
|
|
55950
55984
|
return;
|
|
@@ -55965,6 +55999,7 @@ function useDocumentManagementController() {
|
|
|
55965
55999
|
return;
|
|
55966
56000
|
}
|
|
55967
56001
|
try {
|
|
56002
|
+
await requireSiteReach(req, _id);
|
|
55968
56003
|
const data = await _getDocumentManagementBySiteId(_id, type);
|
|
55969
56004
|
res.json(data);
|
|
55970
56005
|
return;
|