From 6dab9faec2247eae23cd67faec572a717164d4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=96=87=E9=9B=84?= Date: Fri, 23 Aug 2019 16:56:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=A7=E5=B9=85=E5=BA=A6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=A6=96=E9=A1=B5=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../containers/Project/Interface/Interface.js | 7 ++- client/reducer/modules/group.js | 7 ++- server/controllers/group.js | 61 +++++++++++++------ server/models/group.js | 22 +++++++ server/models/project.js | 11 ++++ 5 files changed, 85 insertions(+), 23 deletions(-) diff --git a/client/containers/Project/Interface/Interface.js b/client/containers/Project/Interface/Interface.js index 9d089572..3b95598f 100755 --- a/client/containers/Project/Interface/Interface.js +++ b/client/containers/Project/Interface/Interface.js @@ -35,12 +35,17 @@ const InterfaceRoute = props => { C = InterfaceColContent; } else if (props.match.params.action === 'case') { C = InterfaceCaseContent; + } else { + const params = props.match.params; + props.history.replace('/project/' + params.id + '/interface/api'); + return null; } return ; }; InterfaceRoute.propTypes = { - match: PropTypes.object + match: PropTypes.object, + history: PropTypes.object }; @connect( diff --git a/client/reducer/modules/group.js b/client/reducer/modules/group.js index 05b87596..b9fa4ad2 100755 --- a/client/reducer/modules/group.js +++ b/client/reducer/modules/group.js @@ -48,7 +48,7 @@ export default (state = initialState, action) => { case SET_CURR_GROUP: { return { ...state, - currGroup: action.payload + currGroup: action.payload.data.data }; } case FETCH_GROUP_MEMBER: { @@ -58,6 +58,7 @@ export default (state = initialState, action) => { }; } case FETCH_GROUP_MSG: { + console.log(action.payload) // const {role,group_name,group_desc,} = action.payload.data.data return { ...state, @@ -154,6 +155,8 @@ export function fetchGroupList() { export function setCurrGroup(group) { return { type: SET_CURR_GROUP, - payload: group + payload: axios.get('/api/group/get', { + params: { id: group._id } + }) }; } diff --git a/server/controllers/group.js b/server/controllers/group.js index 013f1b49..226837d2 100755 --- a/server/controllers/group.js +++ b/server/controllers/group.js @@ -6,6 +6,7 @@ const userModel = require('../models/user.js'); const interfaceModel = require('../models/interface.js'); const interfaceColModel = require('../models/interfaceCol.js'); const interfaceCaseModel = require('../models/interfaceCase.js'); +const _ = require('underscore') const rolename = { owner: '组长', @@ -400,7 +401,7 @@ class groupController extends baseController { async list(ctx) { var groupInst = yapi.getInst(groupModel); let projectInst = yapi.getInst(projectModel); - let result = await groupInst.list(); + let result = await groupInst.getAuthList(this.getUid()); let privateGroup = await groupInst.getByPrivateUid(this.getUid()); let newResult = []; @@ -415,28 +416,48 @@ class groupController extends baseController { }); } - if (result && result.length > 0) { - for (let i = 0; i < result.length; i++) { + 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]); - } - } - } + newResult.unshift(result[i]) } } + + const groupIds = newResult.map(item=> item._id); + + let groupByProject = await projectInst.getAuthList(this.getUid()); + if(groupByProject && groupByProject.length > 0){ + groupByProject.forEach( _data=>{ + if(!_.find(groupIds, id=> id === _data.group_id)){ + groupIds.push(_data.group_id) + } + }) + } + + newResult = await groupInst.findByGroups(groupIds) + + // 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 = '个人空间'; diff --git a/server/models/group.js b/server/models/group.js index 7aa9df53..0310e1aa 100755 --- a/server/models/group.js +++ b/server/models/group.js @@ -146,6 +146,28 @@ class groupModel extends baseModel { .exec(); } + getAuthList(uid){ + return this.model.find({ + $or: [{ + 'members.uid': uid, + 'type': 'public' + }, { + 'type': 'public', + uid + }] + }).select(' _id group_desc add_time up_time type uid custom_field1') + .exec(); + + } + + findByGroups(ids = []){ + return this.model.find({ + _id: { + $in: ids + } + }) + } + del(id) { return this.model.remove({ _id: id diff --git a/server/models/project.js b/server/models/project.js index 827eb9dd..f22a8851 100755 --- a/server/models/project.js +++ b/server/models/project.js @@ -11,6 +11,17 @@ class projectModel extends baseModel { this.handleEnvNullData = this.handleEnvNullData.bind(this) } + getAuthList(uid){ + return this.model.find({ + $or: [{ + 'members.uid': uid + }, { + uid + }] + }).select('group_id') + .exec(); + } + getSchema() { return { uid: { type: Number, required: true },