|
@@ -10,8 +10,8 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
pageGroupRelationSchema = new mongoose.Schema({
|
|
pageGroupRelationSchema = new mongoose.Schema({
|
|
|
pageGroupRelationId: String,
|
|
pageGroupRelationId: String,
|
|
|
- relatedGroup: { type: ObjectId, ref: 'UserGroup' },
|
|
|
|
|
- targetPage: { type: ObjectId, ref: 'Page' },
|
|
|
|
|
|
|
+ relatedGroup: { type: ObjectId, ref: 'UserGroup', required: true },
|
|
|
|
|
+ targetPage: { type: ObjectId, ref: 'Page', required: true },
|
|
|
createdAt: { type: Date, default: Date.now },
|
|
createdAt: { type: Date, default: Date.now },
|
|
|
},{
|
|
},{
|
|
|
toJSON: { getters: true },
|
|
toJSON: { getters: true },
|
|
@@ -24,18 +24,9 @@ module.exports = function(crowi) {
|
|
|
debug('findAllRelations is called');
|
|
debug('findAllRelations is called');
|
|
|
var PageGroupRelation = this;
|
|
var PageGroupRelation = this;
|
|
|
|
|
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
|
|
- PageGroupRelation
|
|
|
|
|
- .find({ relatedGroup: group} )
|
|
|
|
|
|
|
+ return PageGroupRelation.find({ relatedGroup: group} )
|
|
|
.populate('targetPage')
|
|
.populate('targetPage')
|
|
|
- .exec(function (err, pageGroupRelationData) {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return resolve(pageGroupRelationData);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ .exec();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 指定グループに対するすべてのグループ所属関係を取得
|
|
// 指定グループに対するすべてのグループ所属関係を取得
|
|
@@ -43,17 +34,9 @@ module.exports = function(crowi) {
|
|
|
debug('findAllRelation is called', userGroup);
|
|
debug('findAllRelation is called', userGroup);
|
|
|
var PageGroupRelation = this;
|
|
var PageGroupRelation = this;
|
|
|
|
|
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
|
|
- PageGroupRelation
|
|
|
|
|
- .find({ relatedGroup: userGroup.id })
|
|
|
|
|
|
|
+ return PageGroupRelation.find({ relatedGroup: userGroup.id })
|
|
|
.populate('targetPage')
|
|
.populate('targetPage')
|
|
|
- .exec(function (err, pageGroupRelationData) {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
- return resolve(pageGroupRelationData);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ .exec();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// ページネーション利用の検索
|
|
// ページネーション利用の検索
|
|
@@ -69,8 +52,8 @@ module.exports = function(crowi) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // ページとグループを元に関係性を取得
|
|
|
|
|
- pageGroupRelationSchema.statics.checkIsExistsRelationForPageAndGroup = function (page, userGroup) {
|
|
|
|
|
|
|
+ // ページとグループを元に関係性が存在するか確認
|
|
|
|
|
+ pageGroupRelationSchema.statics.isExistsRelationForPageAndGroup = function (page, userGroup) {
|
|
|
var PageGroupRelation = this
|
|
var PageGroupRelation = this
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
return new Promise(function (resolve, reject) {
|
|
@@ -89,84 +72,55 @@ module.exports = function(crowi) {
|
|
|
pageGroupRelationSchema.statics.findByPage = function(page) {
|
|
pageGroupRelationSchema.statics.findByPage = function(page) {
|
|
|
var PageGroupRelation = this
|
|
var PageGroupRelation = this
|
|
|
|
|
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
|
|
- PageGroupRelation
|
|
|
|
|
- .findOne({ targetPage: page.id })
|
|
|
|
|
|
|
+ return PageGroupRelation.find({ targetPage: page.id })
|
|
|
.populate('relatedGroup')
|
|
.populate('relatedGroup')
|
|
|
- .exec(function (err, data) {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
- return resolve(data);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ .exec();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 関係性の生成
|
|
// 関係性の生成
|
|
|
- pageGroupRelationSchema.statics.createRelation = function(userGroup, page, callback) {
|
|
|
|
|
|
|
+ pageGroupRelationSchema.statics.createRelation = function(userGroup, page) {
|
|
|
var PageGroupRelation = this
|
|
var PageGroupRelation = this
|
|
|
, newPageGroupRelation = new PageGroupRelation();
|
|
, newPageGroupRelation = new PageGroupRelation();
|
|
|
|
|
|
|
|
- if (userGroup == null || page == null) {
|
|
|
|
|
- return callback(new Error('userGroup or page is null'));
|
|
|
|
|
- }
|
|
|
|
|
debug('create new page-group-relation for group ', userGroup);
|
|
debug('create new page-group-relation for group ', userGroup);
|
|
|
newPageGroupRelation.relatedGroup = userGroup.id;
|
|
newPageGroupRelation.relatedGroup = userGroup.id;
|
|
|
newPageGroupRelation.targetPage = page.id;
|
|
newPageGroupRelation.targetPage = page.id;
|
|
|
newPageGroupRelation.createdAt = Date.now();
|
|
newPageGroupRelation.createdAt = Date.now();
|
|
|
|
|
|
|
|
debug('create new page-group-relation ', newPageGroupRelation);
|
|
debug('create new page-group-relation ', newPageGroupRelation);
|
|
|
- newPageGroupRelation.save(function(err, pageGroupRelationData) {
|
|
|
|
|
- return callback(err, pageGroupRelationData);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return newPageGroupRelation.save();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// グループに紐づく関係性の全削除
|
|
// グループに紐づく関係性の全削除
|
|
|
- pageGroupRelationSchema.statics.removeAllByUserGroup = function (userGroup, callback) {
|
|
|
|
|
-
|
|
|
|
|
- if (userGroup === null) { return callback(null); }
|
|
|
|
|
|
|
+ pageGroupRelationSchema.statics.removeAllByUserGroup = function (userGroup) {
|
|
|
var PageGroupRelation = this
|
|
var PageGroupRelation = this
|
|
|
- var relations = PageGroupRelation.findAllRelation(userGroup);
|
|
|
|
|
|
|
|
|
|
- // 関係性削除の実装
|
|
|
|
|
- relations.array.forEach(relation => {
|
|
|
|
|
- PageGroupRelation.removeById(relation.id, function(err) {
|
|
|
|
|
- if (err) { return callback(err); }
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- return callback(null);
|
|
|
|
|
|
|
+ return PageGroupRelation.findAllRelationForUserGroup(userGroup)
|
|
|
|
|
+ .then( function(relations) {
|
|
|
|
|
+ if (relations == null) {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ relations.map(relation => relation.remove());
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ページに紐づく関係性の全削除
|
|
// ページに紐づく関係性の全削除
|
|
|
- pageGroupRelationSchema.statics.removeAllByPage = function (page, callback) {
|
|
|
|
|
-
|
|
|
|
|
- if (page === null) { return callback(null); }
|
|
|
|
|
|
|
+ pageGroupRelationSchema.statics.removeAllByPage = function (page) {
|
|
|
var PageGroupRelation = this
|
|
var PageGroupRelation = this
|
|
|
- var relations = PageGroupRelation.findByPage(page);
|
|
|
|
|
-
|
|
|
|
|
- if (relations != null && relations.length > 0) {
|
|
|
|
|
- // 関係性削除の実装
|
|
|
|
|
- relations.array.forEach(relation => {
|
|
|
|
|
- PageGroupRelation.removeById(relation.id, function (err) {
|
|
|
|
|
- if (err) { return callback(err); }
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- return callback(null);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ debug('removeAllByPage is called', page);
|
|
|
|
|
|
|
|
- // ページに紐づくグループの関係性の削除
|
|
|
|
|
- pageGroupRelationSchema.statics.removeRelationByUserGroupAndPage = function (userGroup, page, callback) {
|
|
|
|
|
- if (userGroup == null) { return callback(null); }
|
|
|
|
|
- if (page == null) { return callback(null); }
|
|
|
|
|
- var PageGroupRelation = this
|
|
|
|
|
- var relation = PageGroupRelation.findOne()({relatedGroup: userGroup.id, targetPage: page.id });
|
|
|
|
|
-
|
|
|
|
|
- if (relation == null) { return callback(); }
|
|
|
|
|
- PageGroupRelation.removeById(relation.id, function (err) {
|
|
|
|
|
- if (err) { return callback(err); }
|
|
|
|
|
|
|
+ return PageGroupRelation.findByPage(page)
|
|
|
|
|
+ .then(function(relations) {
|
|
|
|
|
+ debug('remove relations are ', relations);
|
|
|
|
|
+ if (relations == null) {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ relations.map(relation => relation.remove());
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- return callback(null);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ユーザグループの関係性を削除
|
|
// ユーザグループの関係性を削除
|