|
@@ -157,18 +157,20 @@ schema.statics.getParentIdAndFillAncestors = async function(path: string): Promi
|
|
|
return parentId;
|
|
return parentId;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-schema.statics.findByPathAndViewerV5 = async function(path: string | null, user, userGroups): Promise<IPage[]> {
|
|
|
|
|
|
|
+schema.statics.findByPathAndViewer = async function(path: string | null, user, userGroups, useFindOne = true): Promise<IPage[]> {
|
|
|
if (path == null) {
|
|
if (path == null) {
|
|
|
throw new Error('path is required.');
|
|
throw new Error('path is required.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const baseQuery = useFindOne ? this.findOne({ path }) : this.find({ path });
|
|
|
|
|
+
|
|
|
let relatedUserGroups = userGroups;
|
|
let relatedUserGroups = userGroups;
|
|
|
if (user != null && relatedUserGroups == null) {
|
|
if (user != null && relatedUserGroups == null) {
|
|
|
const UserGroupRelation: any = mongoose.model('UserGroupRelation');
|
|
const UserGroupRelation: any = mongoose.model('UserGroupRelation');
|
|
|
relatedUserGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
relatedUserGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const queryBuilder = new PageQueryBuilder(this.find({ path }));
|
|
|
|
|
|
|
+ const queryBuilder = new PageQueryBuilder(baseQuery);
|
|
|
queryBuilder.addConditionToFilteringByViewer(user, relatedUserGroups, true);
|
|
queryBuilder.addConditionToFilteringByViewer(user, relatedUserGroups, true);
|
|
|
|
|
|
|
|
return queryBuilder.query.exec();
|
|
return queryBuilder.query.exec();
|