|
|
@@ -501,46 +501,33 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
// find page and check if granted user
|
|
|
- pageSchema.statics.findPage = function(path, userData, revisionId, ignoreNotFound) {
|
|
|
- const self = this;
|
|
|
+ pageSchema.statics.findPage = async function(path, userData, revisionId, ignoreNotFound) {
|
|
|
const PageGroupRelation = crowi.model('PageGroupRelation');
|
|
|
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
- self.findOne({path: path}, function(err, pageData) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
+ const pageData = await this.findOne({path: path});
|
|
|
|
|
|
- if (pageData === null) {
|
|
|
- if (ignoreNotFound) {
|
|
|
- return resolve(null);
|
|
|
- }
|
|
|
+ if (pageData == null) {
|
|
|
+ if (ignoreNotFound) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- const pageNotFoundError = new Error('Page Not Found');
|
|
|
- pageNotFoundError.name = 'Crowi:Page:NotFound';
|
|
|
- return reject(pageNotFoundError);
|
|
|
- }
|
|
|
+ const pageNotFoundError = new Error('Page Not Found');
|
|
|
+ pageNotFoundError.name = 'Crowi:Page:NotFound';
|
|
|
+ throw new Error(pageNotFoundError);
|
|
|
+ }
|
|
|
|
|
|
- if (!pageData.isGrantedFor(userData)) {
|
|
|
- PageGroupRelation.isExistsGrantedGroupForPageAndUser(pageData, userData)
|
|
|
- .then(isExists => {
|
|
|
- if (isExists) {
|
|
|
- // return resolve(pageData);
|
|
|
- self.populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
|
|
|
- }
|
|
|
- else {
|
|
|
- return reject(new UserHasNoGrantException('Page is not granted for the user', userData));
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(function(err) {
|
|
|
- return reject(err);
|
|
|
- });
|
|
|
- }
|
|
|
- else {
|
|
|
- self.populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
+ if (!pageData.isGrantedFor(userData)) {
|
|
|
+ const isRelationExists = await PageGroupRelation.isExistsGrantedGroupForPageAndUser(pageData, userData);
|
|
|
+ if (isRelationExists) {
|
|
|
+ return await this.populatePageData(pageData, revisionId || null);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new UserHasNoGrantException('Page is not granted for the user', userData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return await this.populatePageData(pageData, revisionId || null);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|