|
|
@@ -459,7 +459,18 @@ module.exports = function(crowi) {
|
|
|
Page.findPageById(id)
|
|
|
.then(function(pageData) {
|
|
|
if (userData && !pageData.isGrantedFor(userData)) {
|
|
|
- return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
|
|
|
+ Page.isExistsGrantedGroupFor(pageData, userData)
|
|
|
+ .then(function (checkResult) {
|
|
|
+ debug('isExistsGrantedGroupFor checkResult is ', checkResult);
|
|
|
+ if (!checkResult) {
|
|
|
+ return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
|
|
|
+ } else {
|
|
|
+ return resolve(pageData);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ return reject(err);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
return resolve(pageData);
|
|
|
@@ -489,8 +500,19 @@ module.exports = function(crowi) {
|
|
|
return reject(pageNotFoundError);
|
|
|
}
|
|
|
|
|
|
- if (!pageData.isGrantedFor(userData) && !self.isExistsGrantedGroupFor(pageData, userData)) {
|
|
|
- return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
|
|
|
+ if (!pageData.isGrantedFor(userData)) {
|
|
|
+ self.isExistsGrantedGroupFor(pageData, userData)
|
|
|
+ .then(function (checkResult) {
|
|
|
+ debug('isExistsGrantedGroupFor checkResult is ', checkResult);
|
|
|
+ if (!checkResult) {
|
|
|
+ return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
|
|
|
+ } else {
|
|
|
+ return resolve(pageData);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function (err) {
|
|
|
+ return reject(err);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
self.populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
|
|
|
@@ -758,12 +780,13 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.updateGrant = function (page, grant, userData, grantUserGroup) {
|
|
|
+ pageSchema.statics.updateGrant = function (page, grant, userData, grantUserGroupId) {
|
|
|
var Page = this;
|
|
|
var PageGroupRelation = crowi.model('PageGroupRelation');
|
|
|
+ var UserGroupRelation = crowi.model('UserGroupRelation');
|
|
|
var provGrant = page.grant;
|
|
|
|
|
|
- if (grant == GRANT_USER_GROUP && grantUserGroup == null) {
|
|
|
+ if (grant == GRANT_USER_GROUP && grantUserGroupId == null) {
|
|
|
grant = GRANT_PUBLIC;
|
|
|
}
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
@@ -781,18 +804,30 @@ module.exports = function(crowi) {
|
|
|
return reject(err);
|
|
|
}
|
|
|
|
|
|
- // グループから外れたとき、関係性を削除
|
|
|
- if (provGrant == GRANT_USER_GROUP && provGrant != grant) {
|
|
|
- PageGroupRelation.removeRelationByUserGroupAndPage(grantUserGroup, page, function (err, result) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
+ // グループの場合
|
|
|
+ if (grant == GRANT_USER_GROUP) {
|
|
|
+ debug('grant is usergroup', grantUserGroupId);
|
|
|
+ UserGroupRelation.findByGroupIdAndUser(grantUserGroupId, userData)
|
|
|
+ .then(function(relation) {
|
|
|
+ if (relation != null) {
|
|
|
+ return PageGroupRelation.checkIsExistsRelationForPageAndGroup(page, relation.relatedGroup);
|
|
|
}
|
|
|
+ else { return reject(new Error('No UserGroup is exists. userGroupId : ', grantUserGroupId)); }
|
|
|
+ })
|
|
|
+ .then(function(isAlreadyExists) {
|
|
|
+ if (!isAlreadyExists) {
|
|
|
+ debug('create new Page and Group relations', relation.relatedGroup);
|
|
|
+ PageGroupRelation.createRelation(relation.relatedGroup, page, function (err, relationData) {
|
|
|
+ if (err) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return Promise.resolve();
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- // グループに紐づけられたとき、関係性を生成
|
|
|
- if (provGrant != GRANT_USER_GROUP && grant == GRANT_USER_GROUP) {
|
|
|
- PageGroupRelation.createRelation(userGroupData, page, function (err, relationData) {
|
|
|
+ else {
|
|
|
+ PageGroupRelation.removeAllByPage(page, function (err, result) {
|
|
|
if (err) {
|
|
|
return reject(err);
|
|
|
}
|
|
|
@@ -803,30 +838,6 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.updateGrantUserGroup = function(page, userGroupData) {
|
|
|
- var Page = this
|
|
|
- , PageGroupRelation = crowi.model('PageGroupRelation');
|
|
|
-
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- page.grant = GRANT_USER_GROUP;
|
|
|
-
|
|
|
- page.save(function (err, data) {
|
|
|
- debug('Page.updateGrant, saved grantedUsers.', err, data);
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- PageGroupRelation.createRelation(userGroupData, page, function(err, relationData) {
|
|
|
- debug('Page.updateGrant, saved grantedUsers.', err, relationData);
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
- });
|
|
|
- return resolve(relationData);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
// Instance method でいいのでは
|
|
|
pageSchema.statics.pushToGrantedUsers = function(page, userData) {
|
|
|
|
|
|
@@ -884,7 +895,7 @@ module.exports = function(crowi) {
|
|
|
, format = options.format || 'markdown'
|
|
|
, grant = options.grant || GRANT_PUBLIC
|
|
|
, redirectTo = options.redirectTo || null
|
|
|
- , grantUserGroup = options.grantUserGroup || null;
|
|
|
+ , grantUserGroupId = options.grantUserGroupId || null;
|
|
|
|
|
|
// force public
|
|
|
if (isPortalPath(path)) {
|
|
|
@@ -914,8 +925,8 @@ module.exports = function(crowi) {
|
|
|
return reject(err);
|
|
|
}
|
|
|
|
|
|
- if (newPage.grant == Page.GRANT_USER_GROUP && grantUserGroup != null) {
|
|
|
- UserGroupRelation.createRelation(grantUserGroup, newPage, function (err, relationData) {
|
|
|
+ if (newPage.grant == Page.GRANT_USER_GROUP && grantUserGroupId != null) {
|
|
|
+ PageGroupRelation.createRelation(grantUserGroupId, newPage, function (err, relationData) {
|
|
|
if (err) {
|
|
|
return reject(err);
|
|
|
}
|
|
|
@@ -938,7 +949,7 @@ module.exports = function(crowi) {
|
|
|
var Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, grant = options.grant || null
|
|
|
- , grantUserGroup = options.grantUserGroup || null;
|
|
|
+ , grantUserGroupId = options.grantUserGroupId || null
|
|
|
;
|
|
|
// update existing page
|
|
|
var newRevision = Revision.prepareRevision(pageData, body, user);
|
|
|
@@ -947,7 +958,7 @@ module.exports = function(crowi) {
|
|
|
Page.pushRevision(pageData, newRevision, user)
|
|
|
.then(function(revision) {
|
|
|
if (grant != pageData.grant) {
|
|
|
- return Page.updateGrant(pageData, grant, user, grantUserGroup).then(function(data) {
|
|
|
+ return Page.updateGrant(pageData, grant, user, grantUserGroupId).then(function(data) {
|
|
|
debug('Page grant update:', data);
|
|
|
resolve(data);
|
|
|
pageEvent.emit('update', data, user);
|
|
|
@@ -1227,7 +1238,11 @@ module.exports = function(crowi) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
PageGroupRelation.findByPage(pageData)
|
|
|
.then(function (pageRelation) {
|
|
|
- UserGroupRelation.checkIsRelatedUserForGroup(userData, data.relatedGroup)
|
|
|
+ if (pageRelation == null) {
|
|
|
+ debug('isExistsGrantedGroupFor is return resolve(false);');
|
|
|
+ return resolve(false);
|
|
|
+ }
|
|
|
+ return UserGroupRelation.checkIsRelatedUserForGroup(userData, pageRelation.relatedGroup)
|
|
|
.then(function (checkResult) {
|
|
|
return resolve(checkResult);
|
|
|
})
|