mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-07 14:16:52 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
71b3971112
@ -6,7 +6,6 @@ import { Home, ProjectGroups, Interface, News, AddInterface } from './containers
|
||||
import User from './containers/User/User.js';
|
||||
import Header from './components/Header/Header';
|
||||
import Footer from './components/Footer/Footer';
|
||||
import Breadcrumb from './components/Breadcrumb/Breadcrumb';
|
||||
import Loading from './components/Loading/Loading';
|
||||
import { checkLoginState } from './reducer/modules/login';
|
||||
import { requireAuthentication } from './components/AuthenticatedComponent';
|
||||
@ -50,7 +49,6 @@ export default class App extends Component {
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<div className="router-container">
|
||||
<Breadcrumb />
|
||||
<Route path="/" component={Home} exact />
|
||||
<Switch>
|
||||
<Redirect exact from='/group' to='/group/1' />
|
||||
|
37
client/components/Subnav/Subnav.js
Normal file
37
client/components/Subnav/Subnav.js
Normal file
@ -0,0 +1,37 @@
|
||||
import './Subnav.scss';
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Menu } from 'antd';
|
||||
|
||||
class Subnav extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
static propTypes = {
|
||||
data: PropTypes.array
|
||||
}
|
||||
render () {
|
||||
console.log(this.props);
|
||||
return (
|
||||
<div className="m-subnav">
|
||||
<Menu
|
||||
onClick={this.handleClick}
|
||||
selectedKeys={[this.props.data[0].name]}
|
||||
defaultSelectedKeys={[this.props.data[0].name]}
|
||||
mode="horizontal"
|
||||
className="g-row m-subnav-menu"
|
||||
>
|
||||
{this.props.data.map((item, index) => {
|
||||
return (
|
||||
<Menu.Item className="item" key={item.name}>
|
||||
{this.props.data[index].name}
|
||||
</Menu.Item>
|
||||
)
|
||||
})}
|
||||
</Menu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Subnav
|
16
client/components/Subnav/Subnav.scss
Normal file
16
client/components/Subnav/Subnav.scss
Normal file
@ -0,0 +1,16 @@
|
||||
@import '../../styles/common.scss';
|
||||
|
||||
.m-subnav {
|
||||
margin-bottom: .24rem;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0 .04rem rgba(0, 0, 0, .08);
|
||||
font-size: .14rem;
|
||||
border: none;
|
||||
.m-subnav-menu {
|
||||
border: none;
|
||||
.item {
|
||||
line-height: .54rem;
|
||||
padding: 0 .36rem;
|
||||
}
|
||||
}
|
||||
}
|
28
client/containers/Follows/Follows.js
Normal file
28
client/containers/Follows/Follows.js
Normal file
@ -0,0 +1,28 @@
|
||||
import React, { Component } from 'react';
|
||||
import Subnav from '../../components/Subnav/Subnav.js';
|
||||
import { Row, Col } from 'antd';
|
||||
|
||||
import './ProjectGroups.scss'
|
||||
|
||||
export default class ProjectGroups extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div>
|
||||
<Subnav data={[{
|
||||
name: '项目广场',
|
||||
path: '/test'
|
||||
}, {
|
||||
name: '我的关注',
|
||||
path: '/test'
|
||||
}]}/>
|
||||
<div className="g-doc">
|
||||
doc
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import GroupList from './GroupList/GroupList.js';
|
||||
import ProjectList from './ProjectList/ProjectList.js';
|
||||
import Subnav from '../../components/Subnav/Subnav.js';
|
||||
import { Row, Col } from 'antd';
|
||||
|
||||
import './ProjectGroups.scss'
|
||||
@ -12,15 +13,24 @@ export default class ProjectGroups extends Component {
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div className="g-doc">
|
||||
<Row gutter={16}>
|
||||
<Col span={6}>
|
||||
<GroupList></GroupList>
|
||||
</Col>
|
||||
<Col span={18}>
|
||||
<ProjectList/>
|
||||
</Col>
|
||||
</Row>
|
||||
<div>
|
||||
<Subnav data={[{
|
||||
name: '项目广场',
|
||||
path: '/test'
|
||||
}, {
|
||||
name: '我的关注',
|
||||
path: '/test'
|
||||
}]}/>
|
||||
<div className="g-doc">
|
||||
<Row gutter={16}>
|
||||
<Col span={6}>
|
||||
<GroupList></GroupList>
|
||||
</Col>
|
||||
<Col span={18}>
|
||||
<ProjectList/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -5,14 +5,12 @@ import project from './project.js'
|
||||
import Interface from './interface.js'
|
||||
import news from './news.js'
|
||||
import addInterface from './addInterface.js'
|
||||
import user from './user.js'
|
||||
import menu from './menu.js'
|
||||
|
||||
export default combineReducers({
|
||||
group,
|
||||
login,
|
||||
Interface,
|
||||
user,
|
||||
project,
|
||||
news,
|
||||
addInterface,
|
||||
|
@ -1,28 +0,0 @@
|
||||
const CHANGE_CUR_UID = 'yapi/user/CHANGE_CUR_UID';
|
||||
|
||||
// Reducer
|
||||
const initialState = {
|
||||
curUid: "0"
|
||||
};
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case CHANGE_CUR_UID: {
|
||||
return {
|
||||
...state,
|
||||
curUid: action.data
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
// Action Creators
|
||||
export function changeCurUid(curUid) {
|
||||
return {
|
||||
type: CHANGE_CUR_UID,
|
||||
data: curUid
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
background: #f1f3f6;
|
||||
background: #ececec;
|
||||
}
|
||||
|
||||
div, article, p, table, tr, td, th, ul, ol, li, h1, h2, h3, form, dl, dt, dd {
|
||||
@ -52,3 +52,11 @@ em {
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
// 布局容器 guitter: 16px
|
||||
.g-row {
|
||||
max-width: 12.08rem; // Col宽度 (1208+16)/24 = 51
|
||||
min-width: 7.52rem; // Col宽度 (752+16)/24 = 32
|
||||
margin: 0 auto;
|
||||
padding: 0 .24rem;
|
||||
}
|
||||
|
77
package.json
77
package.json
@ -20,14 +20,37 @@
|
||||
"dependencies": {
|
||||
"assets-webpack-plugin": "^3.5.1",
|
||||
"axios": "^0.16.2",
|
||||
"babel": "^6.5.2",
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.8.0",
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
||||
"babel-plugin-transform-runtime": "^6.9.0",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-react": "^6.5.0",
|
||||
"babel-preset-stage-3": "^6.24.1",
|
||||
"babel-register": "^6.9.0",
|
||||
"babel-runtime": "^6.9.2",
|
||||
"buffer-shims": "^1.0.0",
|
||||
"chalk": "^2.0.1",
|
||||
"clipboard": "^1.7.1",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"core-decorators": "^0.17.0",
|
||||
"cross-request": "^1.0.1",
|
||||
"css-loader": "^0.28.4",
|
||||
"eslint": "^3.19.0",
|
||||
"eslint-loader": "^1.9.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-react": "^7.1.0",
|
||||
"express": "^4.15.3",
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
"fast-sass-loader": "^1.2.5",
|
||||
"fs-extra": "^3.0.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^6.1.2",
|
||||
"gulp-watch": "^4.3.11",
|
||||
"json2html": "0.0.8",
|
||||
"jsoneditor": "^5.9.3",
|
||||
"jsonwebtoken": "^7.4.1",
|
||||
@ -46,58 +69,36 @@
|
||||
"monaco-editor": "^0.9.0",
|
||||
"mongoose": "4.10.8",
|
||||
"mongoose-auto-increment": "^5.0.1",
|
||||
"node-sass": "^4.5.3",
|
||||
"node-sass-china": "^4.5.0",
|
||||
"nodemailer": "^4.0.1",
|
||||
"ora": "^1.3.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"rc-queue-anim": "^1.2.0",
|
||||
"rc-scroll-anim": "^1.0.7",
|
||||
"react-monaco-editor": "^0.8.1",
|
||||
"redux": "^3.7.1",
|
||||
"redux-promise": "^0.5.3",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"request": "^2.81.0",
|
||||
"sha1": "^1.1.1",
|
||||
"string-replace-webpack-plugin": "^0.1.3",
|
||||
"universal-cookie": "^2.0.8",
|
||||
"url": "^0.11.0",
|
||||
"wangeditor": "^3.0.4",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4",
|
||||
"babel": "^6.5.2",
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.8.0",
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
||||
"babel-plugin-transform-runtime": "^6.9.0",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-react": "^6.5.0",
|
||||
"babel-preset-stage-3": "^6.24.1",
|
||||
"babel-register": "^6.9.0",
|
||||
"babel-runtime": "^6.9.2",
|
||||
"buffer-shims": "^1.0.0",
|
||||
"chalk": "^2.0.1",
|
||||
"css-loader": "^0.28.4",
|
||||
"eslint": "^3.19.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-react": "^7.1.0",
|
||||
"express": "^4.15.3",
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^6.1.2",
|
||||
"gulp-watch": "^4.3.11",
|
||||
"node-sass": "^4.5.3",
|
||||
"ora": "^1.3.0",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-monaco-editor": "^0.8.1",
|
||||
"react-redux": "^5.0.5",
|
||||
"react-router-dom": "^4.1.1",
|
||||
"react-router-redux": "^4.0.8",
|
||||
"react-scripts": "1.0.10",
|
||||
"redux": "^3.7.1",
|
||||
"redux-promise": "^0.5.3",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"request": "^2.81.0",
|
||||
"sass-loader": "^6.0.6",
|
||||
"scss-loader": "0.0.1",
|
||||
"sha1": "^1.1.1",
|
||||
"string-replace-webpack-plugin": "^0.1.3",
|
||||
"style-loader": "^0.18.2",
|
||||
"validate-commit-msg": "^2.12.2"
|
||||
"underscore": "^1.8.3",
|
||||
"universal-cookie": "^2.0.8",
|
||||
"url": "^0.11.0",
|
||||
"validate-commit-msg": "^2.12.2",
|
||||
"wangeditor": "^3.0.4",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ghooks": "^2.0.0",
|
||||
|
@ -1,6 +1,10 @@
|
||||
import yapi from '../yapi.js';
|
||||
import projectModel from '../models/project.js';
|
||||
import userModel from '../models/user.js';
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import groupModel from '../models/group.js'
|
||||
|
||||
import _ from 'underscore'
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
class baseController {
|
||||
@ -60,7 +64,7 @@ class baseController {
|
||||
|
||||
async getLoginStatus(ctx) {
|
||||
if (await this.checkLogin(ctx) === true) {
|
||||
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time','role']);
|
||||
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time', 'role']);
|
||||
result.server_ip = yapi.WEBCONFIG.server_ip;
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
}
|
||||
@ -71,44 +75,77 @@ class baseController {
|
||||
return this.$user.role;
|
||||
}
|
||||
|
||||
async jungeProjectAuth(id) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
/**
|
||||
*
|
||||
* @param {*} id type对应的id
|
||||
* @param {*} type enum[interface, project, group]
|
||||
* @param {*} action enum[ danger , edit ] danger只有owner或管理员才能操作,edit只要是dev或以上就能执行
|
||||
*/
|
||||
async checkAuth(id, type, action) {
|
||||
let result = {};
|
||||
try {
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
if (type === 'interface') {
|
||||
let interfaceInst = yapi.getInst(interfaceModel);
|
||||
let interfaceData = await interfaceInst.get(id)
|
||||
result.interfaceData = interfaceData;
|
||||
if (interfaceData.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
}
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
if (type === 'project') {
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
let projectData = await projectInst.get(id);
|
||||
if(projectData.uid === this.getUid()){
|
||||
return true;
|
||||
}
|
||||
let memberData = _.find(projectData.members, (m) => {
|
||||
if (m.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
||||
if (memberData && memberData.role) {
|
||||
if(action === 'danger' && memberData.role === 'owner'){
|
||||
return true;
|
||||
}
|
||||
if(action === 'edit'){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
type = 'group';
|
||||
id = projectData.group_id
|
||||
}
|
||||
|
||||
if (type === 'group') {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let groupData = await groupInst.get(id);
|
||||
let groupMemberData = _.find(groupData.members, (m) => {
|
||||
if (m.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
if (groupMemberData && groupMemberData.role) {
|
||||
if(action === 'danger' && groupMemberData.role === 'owner'){
|
||||
return true;
|
||||
}
|
||||
if(action === 'edit'){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.get(id);
|
||||
|
||||
if (result.uid === this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async jungeMemberAuth(id, member_uid) {
|
||||
let model = yapi.getInst(projectModel);
|
||||
|
||||
if (this.getRole() === 'admin') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!id || !member_uid) {
|
||||
catch (e) {
|
||||
yapi.commons.log(e.message, 'error')
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = await model.checkMemberRepeat(id, member_uid);
|
||||
|
||||
if (result > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import groupModel from '../models/group.js';
|
||||
import yapi from '../yapi.js';
|
||||
import baseController from './base.js';
|
||||
import projectModel from '../models/project.js';
|
||||
import userModel from '../models/user.js';
|
||||
|
||||
class groupController extends baseController {
|
||||
constructor(ctx) {
|
||||
@ -15,7 +16,8 @@ class groupController extends baseController {
|
||||
* @category group
|
||||
* @foldnumber 10
|
||||
* @param {String} group_name 项目分组名称,不能为空
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @param {String} owner_uid 组长uid
|
||||
* @returns {Object}
|
||||
* @example ./api/group/add.json
|
||||
*/
|
||||
@ -24,7 +26,8 @@ class groupController extends baseController {
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
group_desc: 'string',
|
||||
owner_uid: 'number'
|
||||
});
|
||||
|
||||
if (this.getRole() !== 'admin') {
|
||||
@ -35,6 +38,14 @@ class groupController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空');
|
||||
}
|
||||
|
||||
if(!params.owner_uid){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组必须添加一个组长');
|
||||
}
|
||||
|
||||
let groupUserdata = await this.getUserdata(params.owner_uid, 'owner');
|
||||
if(groupUserdata === null){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '组长uid不存在')
|
||||
}
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
|
||||
let checkRepeat = await groupInst.checkRepeat(params.group_name);
|
||||
@ -48,13 +59,14 @@ class groupController extends baseController {
|
||||
group_desc: params.group_desc,
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
up_time: yapi.commons.time(),
|
||||
members: [groupUserdata]
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await groupInst.save(data);
|
||||
|
||||
result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid', 'members']);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -62,6 +74,84 @@ class groupController extends baseController {
|
||||
|
||||
}
|
||||
|
||||
async getUserdata(uid, role){
|
||||
role = role || 'dev';
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let userData = await userInst.findById(uid);
|
||||
if(!userData){
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
role: role,
|
||||
uid: userData._id,
|
||||
username: userData.username,
|
||||
email: userData.email
|
||||
}
|
||||
}
|
||||
|
||||
async addMember(ctx){
|
||||
let params = ctx.request.body;
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
if (!params.member_uid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '分组成员uid不能为空');
|
||||
}
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '分组id不能为空');
|
||||
}
|
||||
|
||||
var check = await groupInst.checkMemberRepeat(params.id, params.member_uid);
|
||||
if (check > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '成员已存在');
|
||||
}
|
||||
let groupUserdata = await this.getUserdata(params.member_uid);
|
||||
if(groupUserdata === null){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '组长uid不存在')
|
||||
}
|
||||
try {
|
||||
let result = await groupInst.addMember(params.id, groupUserdata);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async getMemberList(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
let group = await groupInst.get(params.id);
|
||||
ctx.body = yapi.commons.resReturn(group.members);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async delMember(ctx) {
|
||||
let params = ctx.request.body;
|
||||
let groupInst = yapi.getInst(groupModel);
|
||||
if (!params.member_uid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '分组成员uid不能为空');
|
||||
}
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '分组id不能为空');
|
||||
}
|
||||
var check = await groupInst.checkMemberRepeat(params.id, params.member_uid);
|
||||
if (check === 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '分组成员不存在');
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await groupInst.delMember(params.id, params.member_uid);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目分组列表
|
||||
* @interface /group/list
|
||||
|
@ -99,7 +99,7 @@ class projectController extends baseController {
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
protocol: params.protocol || 'http',
|
||||
members: [this.getUid()],
|
||||
members: [],
|
||||
uid: this.getUid(),
|
||||
group_id: params.group_id,
|
||||
add_time: yapi.commons.time(),
|
||||
@ -138,8 +138,15 @@ class projectController extends baseController {
|
||||
if (check > 0) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
|
||||
}
|
||||
|
||||
let userdata = await this.getUserdata(params.member_uid);
|
||||
if(userdata === null){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '成员uid不存在')
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
let result = await this.Model.addMember(params.id, params.member_uid);
|
||||
let result = await this.Model.addMember(params.id, userdata);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
@ -179,6 +186,22 @@ class projectController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getUserdata(uid, role){
|
||||
role = role || 'dev';
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let userData = await userInst.findById(uid);
|
||||
if(!userData){
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
role: role,
|
||||
uid: userData._id,
|
||||
username: userData.username,
|
||||
email: userData.email
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list
|
||||
@ -198,10 +221,7 @@ class projectController extends baseController {
|
||||
|
||||
try {
|
||||
let project = await this.Model.get(params.id);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let result = await userInst.findByUids(project.members);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
ctx.body = yapi.commons.resReturn(project.members);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
@ -238,8 +258,6 @@ class projectController extends baseController {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [page] 分页页码
|
||||
* @param {Number} [limit] 每页数据条目,默认为10
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
@ -254,8 +272,7 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await this.Model.listWithPaging(group_id, page, limit);
|
||||
let count = await this.Model.listCount(group_id);
|
||||
let result = await this.Model.list(group_id);
|
||||
let uids = [];
|
||||
result.forEach((item) => {
|
||||
if (uids.indexOf(item.uid) === -1) {
|
||||
@ -268,7 +285,6 @@ class projectController extends baseController {
|
||||
_users[item._id] = item;
|
||||
});
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: Math.ceil(count / limit),
|
||||
list: result,
|
||||
userinfo: _users
|
||||
});
|
||||
@ -300,7 +316,7 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
|
||||
}
|
||||
|
||||
if (await this.jungeProjectAuth(id) !== true) {
|
||||
if (await this.checkAuth(id, 'project', 'owner') !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
let result = await this.Model.del(id);
|
||||
@ -345,7 +361,7 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
|
||||
if (await this.jungeMemberAuth(id, this.getUid()) !== true) {
|
||||
if (await this.checkAuth(id, 'project', 'edit') !== true) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
|
||||
@ -382,7 +398,6 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
let data = {
|
||||
uid: this.getUid(),
|
||||
up_time: yapi.commons.time()
|
||||
};
|
||||
|
||||
|
@ -521,6 +521,7 @@ class userController extends baseController {
|
||||
let interfaceData = await interfaceInst.get(id)
|
||||
result["interface_id"] = interfaceData._id;
|
||||
result["interface_name"] = interfaceData.path;
|
||||
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
}
|
||||
|
@ -12,7 +12,15 @@ class groupModel extends baseModel {
|
||||
group_name: String,
|
||||
group_desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
up_time: Number,
|
||||
members: [
|
||||
{
|
||||
uid: Number,
|
||||
role: {type: String, enum:['owner', 'dev']},
|
||||
username: String,
|
||||
email: String
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
@ -33,6 +41,33 @@ class groupModel extends baseModel {
|
||||
});
|
||||
}
|
||||
|
||||
addMember(id, data){
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
}, {
|
||||
$push: { members: data }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delMember(id, uid) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
}, {
|
||||
$pull: { members: {uid: uid} }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
checkMemberRepeat(id, uid){
|
||||
return this.model.count({
|
||||
_id: id,
|
||||
"members.uid": uid
|
||||
});
|
||||
}
|
||||
|
||||
list() {
|
||||
return this.model.find().select('group_name _id group_desc add_time up_time').exec();
|
||||
}
|
||||
|
@ -8,12 +8,14 @@ class projectModel extends baseModel {
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
uid: {type: Number, required: true},
|
||||
name: { type: String, required: true },
|
||||
basepath: {type: String },
|
||||
desc: String,
|
||||
group_id: { type: Number, required: true },
|
||||
members: Array,
|
||||
members: [
|
||||
{uid: Number, role: {type: String, enum:['owner', 'dev'], username: String, email: String}}
|
||||
],
|
||||
protocol: { type: String, required: true },
|
||||
prd_host: { type: String, required: true },
|
||||
env: [
|
||||
@ -93,12 +95,12 @@ class projectModel extends baseModel {
|
||||
}, data, { runValidators: true });
|
||||
}
|
||||
|
||||
addMember(id, uid) {
|
||||
addMember(id, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
}, {
|
||||
$push: { members: uid }
|
||||
$push: { members: data }
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -116,7 +118,7 @@ class projectModel extends baseModel {
|
||||
checkMemberRepeat(id, uid) {
|
||||
return this.model.count({
|
||||
_id: id,
|
||||
members: {$in: [uid]}
|
||||
"members.uid": uid
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class userModel extends baseModel {
|
||||
}
|
||||
|
||||
findById(id) {
|
||||
return this.model.findById({
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
238
server/router.js
238
server/router.js
@ -9,6 +9,14 @@ import logController from './controllers/log.js';
|
||||
|
||||
const router = koaRouter();
|
||||
|
||||
const authLevel = {
|
||||
admin: 0,
|
||||
owner: 10,
|
||||
dev: 20,
|
||||
member:30,
|
||||
guest:100
|
||||
}
|
||||
|
||||
const INTERFACE_CONFIG = {
|
||||
interface: {
|
||||
prefix: '/interface/',
|
||||
@ -32,47 +40,195 @@ const INTERFACE_CONFIG = {
|
||||
}
|
||||
};
|
||||
|
||||
//group
|
||||
createAction('group', 'list', 'get', 'list');
|
||||
createAction('group', 'add', 'post', 'add');
|
||||
createAction('group', 'up', 'post', 'up');
|
||||
createAction('group', 'del', 'post', 'del');
|
||||
const routerConfig = {
|
||||
"group": [
|
||||
{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "addMember",
|
||||
"path": "add_member",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "delMember",
|
||||
"path": "del_member",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "getMemberList",
|
||||
"path": "members",
|
||||
"method": "get"
|
||||
}
|
||||
],
|
||||
"user": [
|
||||
{
|
||||
"action": "login",
|
||||
"path": "login",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "reg",
|
||||
"path": "reg",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "findById",
|
||||
"path": "find",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"path": "update",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "getLoginStatus",
|
||||
"path": "status",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "logout",
|
||||
"path": "logout",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "loginByToken",
|
||||
"path": "login_by_token",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "changePassword",
|
||||
"path": "change_password",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "search",
|
||||
"path": "search",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "nav",
|
||||
"path": "nav",
|
||||
"method": "get"
|
||||
}
|
||||
],
|
||||
"project": [
|
||||
{
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"path": "get",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "addMember",
|
||||
"path": "add_member",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "delMember",
|
||||
"path": "del_member",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "getMemberList",
|
||||
"path": "get_member_list",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "search",
|
||||
"path": "search",
|
||||
"method": "get"
|
||||
}
|
||||
],
|
||||
"interface": [
|
||||
{
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "get",
|
||||
"path": "get",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
},
|
||||
{
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}
|
||||
],
|
||||
"log": [
|
||||
{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
//user
|
||||
createAction('user', 'login', 'post', 'login');
|
||||
createAction('user', 'reg', 'post', 'reg');
|
||||
createAction('user', 'list', 'get', 'list');
|
||||
createAction('user', 'find', 'get', 'findById');
|
||||
createAction('user', 'update', 'post', 'update');
|
||||
createAction('user', 'del', 'post', 'del');
|
||||
createAction('user', 'status', 'get', 'getLoginStatus');
|
||||
createAction('user', 'logout', 'get', 'logout');
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
createAction('user', 'search', 'get', 'search');
|
||||
createAction('user', 'nav', 'get', 'nav')
|
||||
|
||||
|
||||
//project
|
||||
createAction('project', 'add', 'post', 'add');
|
||||
createAction('project', 'list', 'get', 'list');
|
||||
createAction('project', 'get', 'get', 'get');
|
||||
createAction('project', 'up', 'post', 'up');
|
||||
createAction('project', 'del', 'post', 'del');
|
||||
createAction('project', 'add_member', 'post', 'addMember');
|
||||
createAction('project', 'del_member', 'post', 'delMember');
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList');
|
||||
createAction('project', 'search', 'get', 'search');
|
||||
|
||||
//interface
|
||||
createAction('interface', 'add', 'post', 'add');
|
||||
createAction('interface', 'list', 'get', 'list');
|
||||
createAction('interface', 'get', 'get', 'get');
|
||||
createAction('interface', 'up', 'post', 'up');
|
||||
createAction('interface', 'del', 'post', 'del');
|
||||
|
||||
//node
|
||||
createAction('log', 'list', 'get', 'list');
|
||||
for(let ctrl in routerConfig){
|
||||
let actions = routerConfig[ctrl];
|
||||
actions.forEach( (item) => {
|
||||
createAction(ctrl, item.action, item.path, item.method);
|
||||
} )
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -81,7 +237,7 @@ createAction('log', 'list', 'get', 'list');
|
||||
* @param {*} method request_method , post get put delete ...
|
||||
* @param {*} action controller_action_name
|
||||
*/
|
||||
function createAction(controller, path, method, action) {
|
||||
function createAction(controller, action, path, method) {
|
||||
router[method](INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
|
||||
let inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
||||
|
||||
|
@ -28,6 +28,18 @@ var _user = require('../models/user.js');
|
||||
|
||||
var _user2 = _interopRequireDefault(_user);
|
||||
|
||||
var _interface = require('../models/interface.js');
|
||||
|
||||
var _interface2 = _interopRequireDefault(_interface);
|
||||
|
||||
var _group = require('../models/group.js');
|
||||
|
||||
var _group2 = _interopRequireDefault(_group);
|
||||
|
||||
var _underscore = require('underscore');
|
||||
|
||||
var _underscore2 = _interopRequireDefault(_underscore);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var jwt = require('jsonwebtoken');
|
||||
@ -197,119 +209,173 @@ var baseController = function () {
|
||||
value: function getRole() {
|
||||
return this.$user.role;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} id type对应的id
|
||||
* @param {*} type enum[interface, project, group]
|
||||
* @param {*} action enum[ danger , edit ] danger只有owner或管理员才能操作,edit只要是dev或以上就能执行
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'jungeProjectAuth',
|
||||
key: 'checkAuth',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(id) {
|
||||
var model, result;
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(id, type, action) {
|
||||
var _this = this;
|
||||
|
||||
var result, interfaceInst, interfaceData, projectInst, projectData, memberData, groupInst, groupData, groupMemberData;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
model = _yapi2.default.getInst(_project2.default);
|
||||
result = {};
|
||||
_context4.prev = 1;
|
||||
|
||||
if (!(this.getRole() === 'admin')) {
|
||||
_context4.next = 3;
|
||||
_context4.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 3:
|
||||
if (id) {
|
||||
_context4.next = 5;
|
||||
case 4:
|
||||
if (!(type === 'interface')) {
|
||||
_context4.next = 14;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', false);
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
_context4.next = 8;
|
||||
return interfaceInst.get(id);
|
||||
|
||||
case 5:
|
||||
_context4.next = 7;
|
||||
return model.get(id);
|
||||
case 8:
|
||||
interfaceData = _context4.sent;
|
||||
|
||||
case 7:
|
||||
result = _context4.sent;
|
||||
result.interfaceData = interfaceData;
|
||||
|
||||
if (!(result.uid === this.getUid())) {
|
||||
_context4.next = 10;
|
||||
if (!(interfaceData.uid === this.getUid())) {
|
||||
_context4.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 10:
|
||||
case 12:
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
|
||||
case 14:
|
||||
if (!(type === 'project')) {
|
||||
_context4.next = 29;
|
||||
break;
|
||||
}
|
||||
|
||||
projectInst = _yapi2.default.getInst(_project2.default);
|
||||
_context4.next = 18;
|
||||
return projectInst.get(id);
|
||||
|
||||
case 18:
|
||||
projectData = _context4.sent;
|
||||
|
||||
if (!(projectData.uid === this.getUid())) {
|
||||
_context4.next = 21;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 21:
|
||||
memberData = _underscore2.default.find(projectData.members, function (m) {
|
||||
if (m.uid === _this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!(memberData && memberData.role)) {
|
||||
_context4.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(action === 'danger' && memberData.role === 'owner')) {
|
||||
_context4.next = 25;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 25:
|
||||
if (!(action === 'edit')) {
|
||||
_context4.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 27:
|
||||
type = 'group';
|
||||
id = projectData.group_id;
|
||||
|
||||
case 29:
|
||||
if (!(type === 'group')) {
|
||||
_context4.next = 40;
|
||||
break;
|
||||
}
|
||||
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context4.next = 33;
|
||||
return groupInst.get(id);
|
||||
|
||||
case 33:
|
||||
groupData = _context4.sent;
|
||||
groupMemberData = _underscore2.default.find(groupData.members, function (m) {
|
||||
if (m.uid === _this.getUid()) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!(groupMemberData && groupMemberData.role)) {
|
||||
_context4.next = 40;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(action === 'danger' && groupMemberData.role === 'owner')) {
|
||||
_context4.next = 38;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 38:
|
||||
if (!(action === 'edit')) {
|
||||
_context4.next = 40;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', true);
|
||||
|
||||
case 40:
|
||||
return _context4.abrupt('return', false);
|
||||
|
||||
case 11:
|
||||
case 43:
|
||||
_context4.prev = 43;
|
||||
_context4.t0 = _context4['catch'](1);
|
||||
|
||||
_yapi2.default.commons.log(_context4.t0.message, 'error');
|
||||
return _context4.abrupt('return', false);
|
||||
|
||||
case 47:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this);
|
||||
}, _callee4, this, [[1, 43]]);
|
||||
}));
|
||||
|
||||
function jungeProjectAuth(_x4) {
|
||||
function checkAuth(_x4, _x5, _x6) {
|
||||
return _ref4.apply(this, arguments);
|
||||
}
|
||||
|
||||
return jungeProjectAuth;
|
||||
}()
|
||||
}, {
|
||||
key: 'jungeMemberAuth',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(id, member_uid) {
|
||||
var model, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
case 0:
|
||||
model = _yapi2.default.getInst(_project2.default);
|
||||
|
||||
if (!(this.getRole() === 'admin')) {
|
||||
_context5.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', true);
|
||||
|
||||
case 3:
|
||||
if (!(!id || !member_uid)) {
|
||||
_context5.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', false);
|
||||
|
||||
case 5:
|
||||
_context5.next = 7;
|
||||
return model.checkMemberRepeat(id, member_uid);
|
||||
|
||||
case 7:
|
||||
result = _context5.sent;
|
||||
|
||||
if (!(result > 0)) {
|
||||
_context5.next = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', true);
|
||||
|
||||
case 10:
|
||||
return _context5.abrupt('return', false);
|
||||
|
||||
case 11:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this);
|
||||
}));
|
||||
|
||||
function jungeMemberAuth(_x5, _x6) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return jungeMemberAuth;
|
||||
return checkAuth;
|
||||
}()
|
||||
}]);
|
||||
return baseController;
|
||||
|
@ -48,6 +48,10 @@ var _project = require('../models/project.js');
|
||||
|
||||
var _project2 = _interopRequireDefault(_project);
|
||||
|
||||
var _user = require('../models/user.js');
|
||||
|
||||
var _user2 = _interopRequireDefault(_user);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var groupController = function (_baseController) {
|
||||
@ -65,7 +69,8 @@ var groupController = function (_baseController) {
|
||||
* @category group
|
||||
* @foldnumber 10
|
||||
* @param {String} group_name 项目分组名称,不能为空
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @param {String} owner_uid 组长uid
|
||||
* @returns {Object}
|
||||
* @example ./api/group/add.json
|
||||
*/
|
||||
@ -75,7 +80,7 @@ var groupController = function (_baseController) {
|
||||
key: 'add',
|
||||
value: function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var params, groupInst, checkRepeat, data, result;
|
||||
var params, groupUserdata, groupInst, checkRepeat, data, result;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
@ -85,7 +90,8 @@ var groupController = function (_baseController) {
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
group_desc: 'string',
|
||||
owner_uid: 'number'
|
||||
});
|
||||
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
@ -104,53 +110,76 @@ var groupController = function (_baseController) {
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组名不能为空'));
|
||||
|
||||
case 6:
|
||||
if (params.owner_uid) {
|
||||
_context.next = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组必须添加一个组长'));
|
||||
|
||||
case 8:
|
||||
_context.next = 10;
|
||||
return this.getUserdata(params.owner_uid, 'owner');
|
||||
|
||||
case 10:
|
||||
groupUserdata = _context.sent;
|
||||
|
||||
if (!(groupUserdata === null)) {
|
||||
_context.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '组长uid不存在'));
|
||||
|
||||
case 13:
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context.next = 9;
|
||||
_context.next = 16;
|
||||
return groupInst.checkRepeat(params.group_name);
|
||||
|
||||
case 9:
|
||||
case 16:
|
||||
checkRepeat = _context.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context.next = 12;
|
||||
_context.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目分组名已存在'));
|
||||
|
||||
case 12:
|
||||
case 19:
|
||||
data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
uid: this.getUid(),
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
up_time: _yapi2.default.commons.time(),
|
||||
members: [groupUserdata]
|
||||
};
|
||||
_context.prev = 13;
|
||||
_context.next = 16;
|
||||
_context.prev = 20;
|
||||
_context.next = 23;
|
||||
return groupInst.save(data);
|
||||
|
||||
case 16:
|
||||
case 23:
|
||||
result = _context.sent;
|
||||
|
||||
|
||||
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid', 'members']);
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 24;
|
||||
_context.next = 31;
|
||||
break;
|
||||
|
||||
case 21:
|
||||
_context.prev = 21;
|
||||
_context.t0 = _context['catch'](13);
|
||||
case 28:
|
||||
_context.prev = 28;
|
||||
_context.t0 = _context['catch'](20);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 24:
|
||||
case 31:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[13, 21]]);
|
||||
}, _callee, this, [[20, 28]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -159,6 +188,263 @@ var groupController = function (_baseController) {
|
||||
|
||||
return add;
|
||||
}()
|
||||
}, {
|
||||
key: 'getUserdata',
|
||||
value: function () {
|
||||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(uid, role) {
|
||||
var userInst, userData;
|
||||
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
case 0:
|
||||
role = role || 'dev';
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context2.next = 4;
|
||||
return userInst.findById(uid);
|
||||
|
||||
case 4:
|
||||
userData = _context2.sent;
|
||||
|
||||
if (userData) {
|
||||
_context2.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context2.abrupt('return', null);
|
||||
|
||||
case 7:
|
||||
return _context2.abrupt('return', {
|
||||
role: role,
|
||||
uid: userData._id,
|
||||
username: userData.username,
|
||||
email: userData.email
|
||||
});
|
||||
|
||||
case 8:
|
||||
case 'end':
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2, this);
|
||||
}));
|
||||
|
||||
function getUserdata(_x2, _x3) {
|
||||
return _ref2.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getUserdata;
|
||||
}()
|
||||
}, {
|
||||
key: 'addMember',
|
||||
value: function () {
|
||||
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
|
||||
var params, groupInst, check, groupUserdata, result;
|
||||
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
||||
while (1) {
|
||||
switch (_context3.prev = _context3.next) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
|
||||
if (params.member_uid) {
|
||||
_context3.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
|
||||
|
||||
case 4:
|
||||
if (params.id) {
|
||||
_context3.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context3.next = 8;
|
||||
return groupInst.checkMemberRepeat(params.id, params.member_uid);
|
||||
|
||||
case 8:
|
||||
check = _context3.sent;
|
||||
|
||||
if (!(check > 0)) {
|
||||
_context3.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '成员已存在'));
|
||||
|
||||
case 11:
|
||||
_context3.next = 13;
|
||||
return this.getUserdata(params.member_uid);
|
||||
|
||||
case 13:
|
||||
groupUserdata = _context3.sent;
|
||||
|
||||
if (!(groupUserdata === null)) {
|
||||
_context3.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '组长uid不存在'));
|
||||
|
||||
case 16:
|
||||
_context3.prev = 16;
|
||||
_context3.next = 19;
|
||||
return groupInst.addMember(params.id, groupUserdata);
|
||||
|
||||
case 19:
|
||||
result = _context3.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context3.next = 26;
|
||||
break;
|
||||
|
||||
case 23:
|
||||
_context3.prev = 23;
|
||||
_context3.t0 = _context3['catch'](16);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
|
||||
|
||||
case 26:
|
||||
case 'end':
|
||||
return _context3.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3, this, [[16, 23]]);
|
||||
}));
|
||||
|
||||
function addMember(_x4) {
|
||||
return _ref3.apply(this, arguments);
|
||||
}
|
||||
|
||||
return addMember;
|
||||
}()
|
||||
}, {
|
||||
key: 'getMemberList',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
||||
var params, groupInst, group;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
params = ctx.request.query;
|
||||
|
||||
if (params.id) {
|
||||
_context4.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 3:
|
||||
_context4.prev = 3;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context4.next = 7;
|
||||
return groupInst.get(params.id);
|
||||
|
||||
case 7:
|
||||
group = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(group.members);
|
||||
_context4.next = 14;
|
||||
break;
|
||||
|
||||
case 11:
|
||||
_context4.prev = 11;
|
||||
_context4.t0 = _context4['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 14:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[3, 11]]);
|
||||
}));
|
||||
|
||||
function getMemberList(_x5) {
|
||||
return _ref4.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getMemberList;
|
||||
}()
|
||||
}, {
|
||||
key: 'delMember',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var params, groupInst, check, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
|
||||
if (params.member_uid) {
|
||||
_context5.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
|
||||
|
||||
case 4:
|
||||
if (params.id) {
|
||||
_context5.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context5.next = 8;
|
||||
return groupInst.checkMemberRepeat(params.id, params.member_uid);
|
||||
|
||||
case 8:
|
||||
check = _context5.sent;
|
||||
|
||||
if (!(check === 0)) {
|
||||
_context5.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
|
||||
|
||||
case 11:
|
||||
_context5.prev = 11;
|
||||
_context5.next = 14;
|
||||
return groupInst.delMember(params.id, params.member_uid);
|
||||
|
||||
case 14:
|
||||
result = _context5.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 21;
|
||||
break;
|
||||
|
||||
case 18:
|
||||
_context5.prev = 18;
|
||||
_context5.t0 = _context5['catch'](11);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[11, 18]]);
|
||||
}));
|
||||
|
||||
function delMember(_x6) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delMember;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取项目分组列表
|
||||
@ -173,40 +459,40 @@ var groupController = function (_baseController) {
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var groupInst, result;
|
||||
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
case 0:
|
||||
_context2.prev = 0;
|
||||
_context6.prev = 0;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context2.next = 4;
|
||||
_context6.next = 4;
|
||||
return groupInst.list();
|
||||
|
||||
case 4:
|
||||
result = _context2.sent;
|
||||
result = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context2.next = 11;
|
||||
_context6.next = 11;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
_context2.prev = 8;
|
||||
_context2.t0 = _context2['catch'](0);
|
||||
_context6.prev = 8;
|
||||
_context6.t0 = _context6['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 11:
|
||||
case 'end':
|
||||
return _context2.stop();
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2, this, [[0, 8]]);
|
||||
}, _callee6, this, [[0, 8]]);
|
||||
}));
|
||||
|
||||
function list(_x2) {
|
||||
return _ref2.apply(this, arguments);
|
||||
function list(_x7) {
|
||||
return _ref6.apply(this, arguments);
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -226,73 +512,73 @@ var groupController = function (_baseController) {
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var groupInst, projectInst, id, count, result;
|
||||
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context3.prev = _context3.next) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context3.next = 2;
|
||||
_context7.next = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 2:
|
||||
_context3.prev = 2;
|
||||
_context7.prev = 2;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
projectInst = _yapi2.default.getInst(_project2.default);
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context3.next = 8;
|
||||
_context7.next = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
|
||||
|
||||
case 8:
|
||||
_context3.next = 10;
|
||||
_context7.next = 10;
|
||||
return projectInst.countByGroupId(id);
|
||||
|
||||
case 10:
|
||||
count = _context3.sent;
|
||||
count = _context7.sent;
|
||||
|
||||
if (!(count > 0)) {
|
||||
_context3.next = 13;
|
||||
_context7.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
|
||||
|
||||
case 13:
|
||||
_context3.next = 15;
|
||||
_context7.next = 15;
|
||||
return groupInst.del(id);
|
||||
|
||||
case 15:
|
||||
result = _context3.sent;
|
||||
result = _context7.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context3.next = 22;
|
||||
_context7.next = 22;
|
||||
break;
|
||||
|
||||
case 19:
|
||||
_context3.prev = 19;
|
||||
_context3.t0 = _context3['catch'](2);
|
||||
_context7.prev = 19;
|
||||
_context7.t0 = _context7['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
|
||||
|
||||
case 22:
|
||||
case 'end':
|
||||
return _context3.stop();
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3, this, [[2, 19]]);
|
||||
}, _callee7, this, [[2, 19]]);
|
||||
}));
|
||||
|
||||
function del(_x3) {
|
||||
return _ref3.apply(this, arguments);
|
||||
function del(_x8) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return del;
|
||||
@ -314,21 +600,21 @@ var groupController = function (_baseController) {
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var groupInst, id, data, result;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context4.next = 2;
|
||||
_context8.next = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 2:
|
||||
_context4.prev = 2;
|
||||
_context8.prev = 2;
|
||||
|
||||
|
||||
ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, {
|
||||
@ -345,32 +631,32 @@ var groupController = function (_baseController) {
|
||||
if ((0, _keys2.default)(data).length === 0) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
_context4.next = 12;
|
||||
_context8.next = 12;
|
||||
return groupInst.up(id, data);
|
||||
|
||||
case 12:
|
||||
result = _context4.sent;
|
||||
result = _context8.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 19;
|
||||
_context8.next = 19;
|
||||
break;
|
||||
|
||||
case 16:
|
||||
_context4.prev = 16;
|
||||
_context4.t0 = _context4['catch'](2);
|
||||
_context8.prev = 16;
|
||||
_context8.t0 = _context8['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t0.message);
|
||||
|
||||
case 19:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[2, 16]]);
|
||||
}, _callee8, this, [[2, 16]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
return _ref4.apply(this, arguments);
|
||||
function up(_x9) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return up;
|
||||
|
@ -206,7 +206,7 @@ var projectController = function (_baseController) {
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
protocol: params.protocol || 'http',
|
||||
members: [this.getUid()],
|
||||
members: [],
|
||||
uid: this.getUid(),
|
||||
group_id: params.group_id,
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
@ -259,7 +259,7 @@ var projectController = function (_baseController) {
|
||||
key: 'addMember',
|
||||
value: function () {
|
||||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
|
||||
var params, check, result;
|
||||
var params, check, userdata, result;
|
||||
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
@ -296,29 +296,43 @@ var projectController = function (_baseController) {
|
||||
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员已存在'));
|
||||
|
||||
case 10:
|
||||
_context2.prev = 10;
|
||||
_context2.next = 13;
|
||||
return this.Model.addMember(params.id, params.member_uid);
|
||||
_context2.next = 12;
|
||||
return this.getUserdata(params.member_uid);
|
||||
|
||||
case 13:
|
||||
case 12:
|
||||
userdata = _context2.sent;
|
||||
|
||||
if (!(userdata === null)) {
|
||||
_context2.next = 15;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '成员uid不存在'));
|
||||
|
||||
case 15:
|
||||
_context2.prev = 15;
|
||||
_context2.next = 18;
|
||||
return this.Model.addMember(params.id, userdata);
|
||||
|
||||
case 18:
|
||||
result = _context2.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context2.next = 20;
|
||||
_context2.next = 25;
|
||||
break;
|
||||
|
||||
case 17:
|
||||
_context2.prev = 17;
|
||||
_context2.t0 = _context2['catch'](10);
|
||||
case 22:
|
||||
_context2.prev = 22;
|
||||
_context2.t0 = _context2['catch'](15);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
|
||||
|
||||
case 20:
|
||||
case 25:
|
||||
case 'end':
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2, this, [[10, 17]]);
|
||||
}, _callee2, this, [[15, 22]]);
|
||||
}));
|
||||
|
||||
function addMember(_x2) {
|
||||
@ -411,6 +425,52 @@ var projectController = function (_baseController) {
|
||||
|
||||
return delMember;
|
||||
}()
|
||||
}, {
|
||||
key: 'getUserdata',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(uid, role) {
|
||||
var userInst, userData;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
role = role || 'dev';
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context4.next = 4;
|
||||
return userInst.findById(uid);
|
||||
|
||||
case 4:
|
||||
userData = _context4.sent;
|
||||
|
||||
if (userData) {
|
||||
_context4.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', null);
|
||||
|
||||
case 7:
|
||||
return _context4.abrupt('return', {
|
||||
role: role,
|
||||
uid: userData._id,
|
||||
username: userData.username,
|
||||
email: userData.email
|
||||
});
|
||||
|
||||
case 8:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this);
|
||||
}));
|
||||
|
||||
function getUserdata(_x4, _x5) {
|
||||
return _ref4.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getUserdata;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
@ -425,78 +485,9 @@ var projectController = function (_baseController) {
|
||||
|
||||
}, {
|
||||
key: 'getMemberList',
|
||||
value: function () {
|
||||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
|
||||
var params, project, userInst, result;
|
||||
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
params = ctx.request.query;
|
||||
|
||||
if (params.id) {
|
||||
_context4.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 3:
|
||||
_context4.prev = 3;
|
||||
_context4.next = 6;
|
||||
return this.Model.get(params.id);
|
||||
|
||||
case 6:
|
||||
project = _context4.sent;
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_context4.next = 10;
|
||||
return userInst.findByUids(project.members);
|
||||
|
||||
case 10:
|
||||
result = _context4.sent;
|
||||
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 17;
|
||||
break;
|
||||
|
||||
case 14:
|
||||
_context4.prev = 14;
|
||||
_context4.t0 = _context4['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[3, 14]]);
|
||||
}));
|
||||
|
||||
function getMemberList(_x4) {
|
||||
return _ref4.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getMemberList;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/get.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var params, result;
|
||||
var params, project;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
@ -516,9 +507,9 @@ var projectController = function (_baseController) {
|
||||
return this.Model.get(params.id);
|
||||
|
||||
case 6:
|
||||
result = _context5.sent;
|
||||
project = _context5.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
ctx.body = _yapi2.default.commons.resReturn(project.members);
|
||||
_context5.next = 13;
|
||||
break;
|
||||
|
||||
@ -536,10 +527,72 @@ var projectController = function (_baseController) {
|
||||
}, _callee5, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function get(_x5) {
|
||||
function getMemberList(_x6) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getMemberList;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/get.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'get',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var params, result;
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
case 0:
|
||||
params = ctx.request.query;
|
||||
|
||||
if (params.id) {
|
||||
_context6.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 3:
|
||||
_context6.prev = 3;
|
||||
_context6.next = 6;
|
||||
return this.Model.get(params.id);
|
||||
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context6.next = 13;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context6.prev = 10;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 13:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function get(_x7) {
|
||||
return _ref6.apply(this, arguments);
|
||||
}
|
||||
|
||||
return get;
|
||||
}()
|
||||
|
||||
@ -550,8 +603,6 @@ var projectController = function (_baseController) {
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} group_id 项目group_id,不能为空
|
||||
* @param {Number} [page] 分页页码
|
||||
* @param {Number} [limit] 每页数据条目,默认为10
|
||||
* @returns {Object}
|
||||
* @example ./api/project/list.json
|
||||
*/
|
||||
@ -559,34 +610,29 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var group_id, page, limit, result, count, uids, _users, users;
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var group_id, page, limit, result, uids, _users, users;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
group_id = ctx.request.query.group_id, page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10;
|
||||
|
||||
if (group_id) {
|
||||
_context6.next = 3;
|
||||
_context7.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
||||
|
||||
case 3:
|
||||
_context6.prev = 3;
|
||||
_context6.next = 6;
|
||||
return this.Model.listWithPaging(group_id, page, limit);
|
||||
_context7.prev = 3;
|
||||
_context7.next = 6;
|
||||
return this.Model.list(group_id);
|
||||
|
||||
case 6:
|
||||
result = _context6.sent;
|
||||
_context6.next = 9;
|
||||
return this.Model.listCount(group_id);
|
||||
|
||||
case 9:
|
||||
count = _context6.sent;
|
||||
result = _context7.sent;
|
||||
uids = [];
|
||||
|
||||
result.forEach(function (item) {
|
||||
@ -595,39 +641,38 @@ var projectController = function (_baseController) {
|
||||
}
|
||||
});
|
||||
_users = {};
|
||||
_context6.next = 15;
|
||||
_context7.next = 12;
|
||||
return _yapi2.default.getInst(_user2.default).findByUids(uids);
|
||||
|
||||
case 15:
|
||||
users = _context6.sent;
|
||||
case 12:
|
||||
users = _context7.sent;
|
||||
|
||||
users.forEach(function (item) {
|
||||
_users[item._id] = item;
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn({
|
||||
total: Math.ceil(count / limit),
|
||||
list: result,
|
||||
userinfo: _users
|
||||
});
|
||||
_context6.next = 23;
|
||||
_context7.next = 20;
|
||||
break;
|
||||
|
||||
case 17:
|
||||
_context7.prev = 17;
|
||||
_context7.t0 = _context7['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
|
||||
|
||||
case 20:
|
||||
_context6.prev = 20;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
|
||||
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context6.stop();
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee6, this, [[3, 20]]);
|
||||
}, _callee7, this, [[3, 17]]);
|
||||
}));
|
||||
|
||||
function list(_x6) {
|
||||
return _ref6.apply(this, arguments);
|
||||
function list(_x8) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -647,78 +692,78 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var id, interfaceInst, count, result;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
_context7.prev = 0;
|
||||
_context8.prev = 0;
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context7.next = 4;
|
||||
_context8.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 4:
|
||||
interfaceInst = _yapi2.default.getInst(_interface2.default);
|
||||
_context7.next = 7;
|
||||
_context8.next = 7;
|
||||
return interfaceInst.countByProjectId(id);
|
||||
|
||||
case 7:
|
||||
count = _context7.sent;
|
||||
count = _context8.sent;
|
||||
|
||||
if (!(count > 0)) {
|
||||
_context7.next = 10;
|
||||
_context8.next = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
|
||||
|
||||
case 10:
|
||||
_context7.next = 12;
|
||||
return this.jungeProjectAuth(id);
|
||||
_context8.next = 12;
|
||||
return this.checkAuth(id, 'project', 'owner');
|
||||
|
||||
case 12:
|
||||
_context7.t0 = _context7.sent;
|
||||
_context8.t0 = _context8.sent;
|
||||
|
||||
if (!(_context7.t0 !== true)) {
|
||||
_context7.next = 15;
|
||||
if (!(_context8.t0 !== true)) {
|
||||
_context8.next = 15;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 15:
|
||||
_context7.next = 17;
|
||||
_context8.next = 17;
|
||||
return this.Model.del(id);
|
||||
|
||||
case 17:
|
||||
result = _context7.sent;
|
||||
result = _context8.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context7.next = 24;
|
||||
_context8.next = 24;
|
||||
break;
|
||||
|
||||
case 21:
|
||||
_context7.prev = 21;
|
||||
_context7.t1 = _context7['catch'](0);
|
||||
_context8.prev = 21;
|
||||
_context8.t1 = _context8['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
||||
|
||||
case 24:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 21]]);
|
||||
}, _callee8, this, [[0, 21]]);
|
||||
}));
|
||||
|
||||
function del(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
function del(_x9) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return del;
|
||||
@ -745,13 +790,13 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var id, params, projectData, checkRepeat, checkRepeatDomain, data, result;
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context8.prev = 0;
|
||||
_context9.prev = 0;
|
||||
id = ctx.request.body.id;
|
||||
params = ctx.request.body;
|
||||
|
||||
@ -766,47 +811,47 @@ var projectController = function (_baseController) {
|
||||
});
|
||||
|
||||
if (id) {
|
||||
_context8.next = 7;
|
||||
_context9.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 7:
|
||||
_context8.next = 9;
|
||||
return this.jungeMemberAuth(id, this.getUid());
|
||||
_context9.next = 9;
|
||||
return this.checkAuth(id, 'project', 'edit');
|
||||
|
||||
case 9:
|
||||
_context8.t0 = _context8.sent;
|
||||
_context9.t0 = _context9.sent;
|
||||
|
||||
if (!(_context8.t0 !== true)) {
|
||||
_context8.next = 12;
|
||||
if (!(_context9.t0 !== true)) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context8.next = 14;
|
||||
_context9.next = 14;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 14:
|
||||
projectData = _context8.sent;
|
||||
projectData = _context9.sent;
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context8.next = 17;
|
||||
_context9.next = 17;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 17:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context8.next = 19;
|
||||
_context9.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 19:
|
||||
|
||||
@ -819,45 +864,44 @@ var projectController = function (_baseController) {
|
||||
}
|
||||
|
||||
if (!params.name) {
|
||||
_context8.next = 27;
|
||||
_context9.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 24;
|
||||
_context9.next = 24;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 24:
|
||||
checkRepeat = _context8.sent;
|
||||
checkRepeat = _context9.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context8.next = 27;
|
||||
_context9.next = 27;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 27:
|
||||
if (!(params.basepath && params.prd_host)) {
|
||||
_context8.next = 33;
|
||||
_context9.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 30;
|
||||
_context9.next = 30;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 30:
|
||||
checkRepeatDomain = _context8.sent;
|
||||
checkRepeatDomain = _context9.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context8.next = 33;
|
||||
_context9.next = 33;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 33:
|
||||
data = {
|
||||
uid: this.getUid(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
|
||||
@ -871,32 +915,32 @@ var projectController = function (_baseController) {
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
_context8.next = 41;
|
||||
_context9.next = 41;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 41:
|
||||
result = _context8.sent;
|
||||
result = _context9.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context8.next = 48;
|
||||
_context9.next = 48;
|
||||
break;
|
||||
|
||||
case 45:
|
||||
_context8.prev = 45;
|
||||
_context8.t1 = _context8['catch'](0);
|
||||
_context9.prev = 45;
|
||||
_context9.t1 = _context9['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t1.message);
|
||||
|
||||
case 48:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 45]]);
|
||||
}, _callee9, this, [[0, 45]]);
|
||||
}));
|
||||
|
||||
function up(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
function up(_x10) {
|
||||
return _ref9.apply(this, arguments);
|
||||
}
|
||||
|
||||
return up;
|
||||
@ -916,40 +960,40 @@ var projectController = function (_baseController) {
|
||||
}, {
|
||||
key: 'search',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var q, projectList, groupList, projectRules, groupRules, queryList;
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
case 0:
|
||||
q = ctx.request.query.q;
|
||||
|
||||
if (q) {
|
||||
_context9.next = 3;
|
||||
_context10.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
|
||||
|
||||
case 3:
|
||||
if (_yapi2.default.commons.validateSearchKeyword(q)) {
|
||||
_context9.next = 5;
|
||||
_context10.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
|
||||
|
||||
case 5:
|
||||
_context9.next = 7;
|
||||
_context10.next = 7;
|
||||
return this.Model.search(q);
|
||||
|
||||
case 7:
|
||||
projectList = _context9.sent;
|
||||
_context9.next = 10;
|
||||
projectList = _context10.sent;
|
||||
_context10.next = 10;
|
||||
return this.groupModel.search(q);
|
||||
|
||||
case 10:
|
||||
groupList = _context9.sent;
|
||||
groupList = _context10.sent;
|
||||
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'prd_host', alias: 'prdHost' }, { key: 'add_time', alias: 'addTime' }];
|
||||
groupRules = ['_id', 'uid', { key: 'group_name', alias: 'groupName' }, { key: 'group_desc', alias: 'groupDesc' }, { key: 'add_time', alias: 'addTime' }, { key: 'up_time', alias: 'upTime' }];
|
||||
|
||||
@ -961,18 +1005,18 @@ var projectController = function (_baseController) {
|
||||
project: projectList,
|
||||
group: groupList
|
||||
};
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this);
|
||||
}, _callee10, this);
|
||||
}));
|
||||
|
||||
function search(_x9) {
|
||||
return _ref9.apply(this, arguments);
|
||||
function search(_x11) {
|
||||
return _ref10.apply(this, arguments);
|
||||
}
|
||||
|
||||
return search;
|
||||
|
@ -1091,6 +1091,7 @@ var userController = function (_baseController) {
|
||||
|
||||
result["interface_id"] = interfaceData._id;
|
||||
result["interface_name"] = interfaceData.path;
|
||||
|
||||
type = 'project';
|
||||
id = interfaceData.project_id;
|
||||
|
||||
|
@ -51,7 +51,13 @@ var groupModel = function (_baseModel) {
|
||||
group_name: String,
|
||||
group_desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
up_time: Number,
|
||||
members: [{
|
||||
uid: Number,
|
||||
role: { type: String, enum: ['owner', 'dev'] },
|
||||
username: String,
|
||||
email: String
|
||||
}]
|
||||
};
|
||||
}
|
||||
}, {
|
||||
@ -74,6 +80,32 @@ var groupModel = function (_baseModel) {
|
||||
group_name: name
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'addMember',
|
||||
value: function addMember(id, data) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
$push: { members: data }
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'delMember',
|
||||
value: function delMember(id, uid) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
$pull: { members: { uid: uid } }
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'checkMemberRepeat',
|
||||
value: function checkMemberRepeat(id, uid) {
|
||||
return this.model.count({
|
||||
_id: id,
|
||||
"members.uid": uid
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list() {
|
||||
|
@ -52,7 +52,7 @@ var projectModel = function (_baseModel) {
|
||||
basepath: { type: String },
|
||||
desc: String,
|
||||
group_id: { type: Number, required: true },
|
||||
members: Array,
|
||||
members: [{ uid: Number, role: { type: String, enum: ['owner', 'dev'], username: String, email: String } }],
|
||||
protocol: { type: String, required: true },
|
||||
prd_host: { type: String, required: true },
|
||||
env: [{ name: String, domain: String }],
|
||||
@ -142,11 +142,11 @@ var projectModel = function (_baseModel) {
|
||||
}
|
||||
}, {
|
||||
key: 'addMember',
|
||||
value: function addMember(id, uid) {
|
||||
value: function addMember(id, data) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
$push: { members: uid }
|
||||
$push: { members: data }
|
||||
});
|
||||
}
|
||||
}, {
|
||||
@ -163,7 +163,7 @@ var projectModel = function (_baseModel) {
|
||||
value: function checkMemberRepeat(id, uid) {
|
||||
return this.model.count({
|
||||
_id: id,
|
||||
members: { $in: [uid] }
|
||||
"members.uid": uid
|
||||
});
|
||||
}
|
||||
}, {
|
||||
|
@ -106,7 +106,7 @@ var userModel = function (_baseModel) {
|
||||
}, {
|
||||
key: 'findById',
|
||||
value: function findById(id) {
|
||||
return this.model.findById({
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
@ -40,69 +40,191 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
||||
|
||||
var router = (0, _koaRouter2.default)();
|
||||
|
||||
var INTERFACE_CONFIG = {
|
||||
interface: {
|
||||
prefix: '/interface/',
|
||||
controller: _interface2.default
|
||||
},
|
||||
user: {
|
||||
prefix: '/user/',
|
||||
controller: _user2.default
|
||||
},
|
||||
group: {
|
||||
prefix: '/group/',
|
||||
controller: _group2.default
|
||||
},
|
||||
project: {
|
||||
prefix: '/project/',
|
||||
controller: _project2.default
|
||||
},
|
||||
log: {
|
||||
prefix: '/log/',
|
||||
controller: _log2.default
|
||||
}
|
||||
var authLevel = {
|
||||
admin: 0,
|
||||
owner: 10,
|
||||
dev: 20,
|
||||
member: 30,
|
||||
guest: 100
|
||||
};
|
||||
|
||||
//group
|
||||
createAction('group', 'list', 'get', 'list');
|
||||
createAction('group', 'add', 'post', 'add');
|
||||
createAction('group', 'up', 'post', 'up');
|
||||
createAction('group', 'del', 'post', 'del');
|
||||
var INTERFACE_CONFIG = {
|
||||
interface: {
|
||||
prefix: '/interface/',
|
||||
controller: _interface2.default
|
||||
},
|
||||
user: {
|
||||
prefix: '/user/',
|
||||
controller: _user2.default
|
||||
},
|
||||
group: {
|
||||
prefix: '/group/',
|
||||
controller: _group2.default
|
||||
},
|
||||
project: {
|
||||
prefix: '/project/',
|
||||
controller: _project2.default
|
||||
},
|
||||
log: {
|
||||
prefix: '/log/',
|
||||
controller: _log2.default
|
||||
}
|
||||
};
|
||||
|
||||
//user
|
||||
createAction('user', 'login', 'post', 'login');
|
||||
createAction('user', 'reg', 'post', 'reg');
|
||||
createAction('user', 'list', 'get', 'list');
|
||||
createAction('user', 'find', 'get', 'findById');
|
||||
createAction('user', 'update', 'post', 'update');
|
||||
createAction('user', 'del', 'post', 'del');
|
||||
createAction('user', 'status', 'get', 'getLoginStatus');
|
||||
createAction('user', 'logout', 'get', 'logout');
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
createAction('user', 'search', 'get', 'search');
|
||||
createAction('user', 'nav', 'get', 'nav');
|
||||
var routerConfig = {
|
||||
"group": [{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "addMember",
|
||||
"path": "add_member",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "delMember",
|
||||
"path": "del_member",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "getMemberList",
|
||||
"path": "members",
|
||||
"method": "get"
|
||||
}],
|
||||
"user": [{
|
||||
"action": "login",
|
||||
"path": "login",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "reg",
|
||||
"path": "reg",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "findById",
|
||||
"path": "find",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "update",
|
||||
"path": "update",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "getLoginStatus",
|
||||
"path": "status",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "logout",
|
||||
"path": "logout",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "loginByToken",
|
||||
"path": "login_by_token",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "changePassword",
|
||||
"path": "change_password",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "search",
|
||||
"path": "search",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "nav",
|
||||
"path": "nav",
|
||||
"method": "get"
|
||||
}],
|
||||
"project": [{
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "get",
|
||||
"path": "get",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "addMember",
|
||||
"path": "add_member",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "delMember",
|
||||
"path": "del_member",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "getMemberList",
|
||||
"path": "get_member_list",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "search",
|
||||
"path": "search",
|
||||
"method": "get"
|
||||
}],
|
||||
"interface": [{
|
||||
"action": "add",
|
||||
"path": "add",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "get",
|
||||
"path": "get",
|
||||
"method": "get"
|
||||
}, {
|
||||
"action": "up",
|
||||
"path": "up",
|
||||
"method": "post"
|
||||
}, {
|
||||
"action": "del",
|
||||
"path": "del",
|
||||
"method": "post"
|
||||
}],
|
||||
"log": [{
|
||||
"action": "list",
|
||||
"path": "list",
|
||||
"method": "get"
|
||||
}]
|
||||
};
|
||||
|
||||
//project
|
||||
createAction('project', 'add', 'post', 'add');
|
||||
createAction('project', 'list', 'get', 'list');
|
||||
createAction('project', 'get', 'get', 'get');
|
||||
createAction('project', 'up', 'post', 'up');
|
||||
createAction('project', 'del', 'post', 'del');
|
||||
createAction('project', 'add_member', 'post', 'addMember');
|
||||
createAction('project', 'del_member', 'post', 'delMember');
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList');
|
||||
createAction('project', 'search', 'get', 'search');
|
||||
var _loop = function _loop(ctrl) {
|
||||
var actions = routerConfig[ctrl];
|
||||
actions.forEach(function (item) {
|
||||
createAction(ctrl, item.action, item.path, item.method);
|
||||
});
|
||||
};
|
||||
|
||||
//interface
|
||||
createAction('interface', 'add', 'post', 'add');
|
||||
createAction('interface', 'list', 'get', 'list');
|
||||
createAction('interface', 'get', 'get', 'get');
|
||||
createAction('interface', 'up', 'post', 'up');
|
||||
createAction('interface', 'del', 'post', 'del');
|
||||
|
||||
//node
|
||||
createAction('log', 'list', 'get', 'list');
|
||||
for (var ctrl in routerConfig) {
|
||||
_loop(ctrl);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -111,48 +233,48 @@ createAction('log', 'list', 'get', 'list');
|
||||
* @param {*} method request_method , post get put delete ...
|
||||
* @param {*} action controller_action_name
|
||||
*/
|
||||
function createAction(controller, path, method, action) {
|
||||
var _this = this;
|
||||
function createAction(controller, action, path, method) {
|
||||
var _this = this;
|
||||
|
||||
router[method](INTERFACE_CONFIG[controller].prefix + path, function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var inst;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
||||
_context.next = 3;
|
||||
return inst.init(ctx);
|
||||
router[method](INTERFACE_CONFIG[controller].prefix + path, function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var inst;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
||||
_context.next = 3;
|
||||
return inst.init(ctx);
|
||||
|
||||
case 3:
|
||||
if (!(inst.$auth === true)) {
|
||||
_context.next = 8;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
if (!(inst.$auth === true)) {
|
||||
_context.next = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 6;
|
||||
return inst[action].call(inst, ctx);
|
||||
_context.next = 6;
|
||||
return inst[action].call(inst, ctx);
|
||||
|
||||
case 6:
|
||||
_context.next = 9;
|
||||
break;
|
||||
case 6:
|
||||
_context.next = 9;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, 'Without Permission.');
|
||||
case 8:
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, 'Without Permission.');
|
||||
|
||||
case 9:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, _this);
|
||||
}));
|
||||
case 9:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, _this);
|
||||
}));
|
||||
|
||||
return function (_x) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
return function (_x) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
}
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in New Issue
Block a user