Skip to content

Commit

Permalink
fix: 修复管理员无法看到所有分组的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
苏文雄 committed Aug 26, 2019
1 parent eee8679 commit 5a9742c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.8.3
* 修复管理员无法看到所有分组的 bug

## v1.8.2
* 重构分组列表功能实现,大幅度优化首屏加载速度
* 接口运行界面设置 header、query、form 的初始值为其示例值
Expand Down
75 changes: 31 additions & 44 deletions server/controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ class groupController extends baseController {
async list(ctx) {
var groupInst = yapi.getInst(groupModel);
let projectInst = yapi.getInst(projectModel);
let result = await groupInst.getAuthList(this.getUid());

let privateGroup = await groupInst.getByPrivateUid(this.getUid());
let newResult = [];
Expand All @@ -416,53 +415,41 @@ class groupController extends baseController {
});
}

if(result && result.length > 0 ){
for (let i = 0; i < result.length; i++){
result[i] = result[i].toObject();
newResult.unshift(result[i])
if(this.getRole() === 'admin'){
let result = await groupInst.list();
if(result && result.length > 0 ){
for (let i = 0; i < result.length; i++){
result[i] = result[i].toObject();
newResult.unshift(result[i])
}
}
}

const groupIds = newResult.map(item=> item._id);
const newGroupIds = [];

let groupByProject = await projectInst.getAuthList(this.getUid());
if(groupByProject && groupByProject.length > 0){
groupByProject.forEach( _data=>{
const _temp = [...groupIds, ...newGroupIds];
if(!_.find(_temp, id=> id === _data.group_id)){
newGroupIds.push(_data.group_id)
}else{
let result = await groupInst.getAuthList(this.getUid());
if(result && result.length > 0 ){
for (let i = 0; i < result.length; i++){
result[i] = result[i].toObject();
newResult.unshift(result[i])
}
}

const groupIds = newResult.map(item=> item._id);
const newGroupIds = [];

let groupByProject = await projectInst.getAuthList(this.getUid());
if(groupByProject && groupByProject.length > 0){
groupByProject.forEach( _data=>{
const _temp = [...groupIds, ...newGroupIds];
if(!_.find(_temp, id=> id === _data.group_id)){
newGroupIds.push(_data.group_id)
}
})
}
let newData = await groupInst.findByGroups(newGroupIds)
newData.forEach(_data=>{
_data = _data.toObject();
newResult.push(_data);
})
}
let newData = await groupInst.findByGroups(newGroupIds)
newData.forEach(_data=>{
_data = _data.toObject();
newResult.push(_data);
})

// if (result && result.length > 0) {
// for (let i = 0; i < result.length; i++) {
// result[i] = result[i].toObject();
// result[i].role = await this.getProjectRole(result[i]._id, 'group');
// if (result[i].role !== 'member') {
// newResult.unshift(result[i]);
// } else {
// let publicCount = await projectInst.countWithPublic(result[i]._id);
// if (publicCount > 0) {
// newResult.push(result[i]);
// } else {
// let projectCountWithAuth = await projectInst.getProjectWithAuth(
// result[i]._id,
// this.getUid()
// );
// if (projectCountWithAuth > 0) {
// newResult.push(result[i]);
// }
// }
// }
// }
// }
if (privateGroup) {
privateGroup = privateGroup.toObject();
privateGroup.group_name = '个人空间';
Expand Down

0 comments on commit 5a9742c

Please sign in to comment.