Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
wenbo.dong 2017-08-08 20:27:21 +08:00
commit 93de0a586b
23 changed files with 1249 additions and 271 deletions

View File

@ -1,5 +1,5 @@
@charset "utf-8";
@import '~antd/dist/antd.css';
html {
font-size:625%;

View File

@ -101,7 +101,7 @@ gulp.task('initialBuild', ['removeDist'], () => {
});
excuteCmd('ykit', ['s', '-p', '4000'], {
cwd: path.resolve(__dirname, '../')
cwd: path.resolve(__dirname, './')
});
});
});

View File

@ -101,6 +101,7 @@
"ykit-config-react": "^0.4.4"
},
"devDependencies": {
"babel-plugin-import": "^1.3.1",
"ghooks": "^2.0.0",
"nodemon": "^1.11.0",
"redux-devtools": "^3.4.0",

View File

@ -115,6 +115,33 @@ class groupController extends baseController {
}
}
async changeMemberRole(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, '分组成员不存在');
}
if (await this.checkAuth(id, 'group', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
params.role = params.role === 'owner' ? 'owner' : 'dev';
try {
let result = await groupInst.changeMemberRole(params.id, params.member_uid, params.role);
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) {
@ -143,6 +170,9 @@ class groupController extends baseController {
if (check === 0) {
return ctx.body = yapi.commons.resReturn(null, 400, '分组成员不存在');
}
if (await this.checkAuth(id, 'group', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
try {
let result = await groupInst.delMember(params.id, params.member_uid);
@ -221,12 +251,10 @@ class groupController extends baseController {
* @example ./api/group/up.json
*/
async up(ctx) {
if (this.getRole() !== 'admin') {
return ctx.body = yapi.commons.resReturn(null, 401, '没有权限');
if (await this.checkAuth(id, 'group', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
try {
ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
id: 'number',
group_name: 'string',

View File

@ -0,0 +1,28 @@
import interfaceCaseModel from '../models/interfaceCase.js';
import baseController from './base.js';
import yapi from '../yapi.js';
class interfaceCaseController extends baseController{
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(interfaceCaseModel);
}
list(ctx){
}
get(ctx){
}
up(ctx){
}
del(ctx){
}
}

View File

@ -0,0 +1,31 @@
import interfaceColModel from '../models/interfaceCol.js';
import baseController from './base.js';
import yapi from '../yapi.js';
class interfaceColController extends baseController{
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(interfaceColModel);
}
async list(ctx){
try {
let id = ctx.query.project_id;
let inst = yapi.getInst(interfaceColModel);
let result = await inst.list(id);
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
async up(ctx){
}
async del(ctx){
}
}

View File

@ -58,6 +58,11 @@ class projectController extends baseController {
group_id: 'number',
desc: 'string'
});
if (await this.checkAuth(params.group_id, 'group', 'edit') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
if (!params.group_id) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
@ -93,6 +98,8 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
}
let data = {
name: params.name,
desc: params.desc,
@ -134,6 +141,10 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
}
if (await this.checkAuth(params.id, 'project', 'edit') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
var check = await this.Model.checkMemberRepeat(params.id, params.member_uid);
if (check > 0) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
@ -178,6 +189,10 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员不存在');
}
if (await this.checkAuth(params.id, 'project', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
try {
let result = await this.Model.delMember(params.id, params.member_uid);
ctx.body = yapi.commons.resReturn(result);
@ -271,8 +286,10 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
let auth = this.checkAuth(group_id, 'group', 'edit')
try {
let result = await this.Model.list(group_id);
let result = await this.Model.list(group_id, auth);
let uids = [];
result.forEach((item) => {
if (uids.indexOf(item.uid) === -1) {
@ -316,7 +333,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '请先删除该项目下所有接口');
}
if (await this.checkAuth(id, 'project', 'owner') !== true) {
if (await this.checkAuth(id, 'project', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
let result = await this.Model.del(id);
@ -326,6 +343,33 @@ class projectController extends baseController {
}
}
async changeMemberRole(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, '分组成员不存在');
}
if (await this.checkAuth(id, 'group', 'danger') !== true) {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
params.role = params.role === 'owner' ? 'owner' : 'dev';
try {
let result = await groupInst.changeMemberRole(params.id, params.member_uid, params.role);
ctx.body = yapi.commons.resReturn(result);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
/**
* 编辑项目
* @interface /project/up

View File

@ -61,6 +61,17 @@ class groupModel extends baseModel {
);
}
changeMemberRole(id, uid, role) {
return this.model.update(
{
_id: id,
"members.uid": uid
}, {
"$set": { "members.$.uid": role}
}
);
}
checkMemberRepeat(id, uid){
return this.model.count({
_id: id,

View File

@ -16,6 +16,9 @@ class interfaceModel extends baseModel {
desc: String,
add_time: Number,
up_time: Number,
req_query:[{
name: String, value: String, desc: String, required: Boolean
}],
req_headers: [{
name: String, value: String, desc: String, required: Boolean
}],

View File

@ -0,0 +1,68 @@
import yapi from '../yapi.js';
import baseModel from './base.js';
class interfaceCase extends baseModel {
getName() {
return 'interface_col';
}
getSchema() {
return {
casename: { type: String, required: true },
uid: { type: Number, required: true },
col_id: { type: Number, required: true },
project_id: { type: Number, required: true },
add_time: Number,
up_time: Number,
env: { type: String, required: true },
path: { type: String, required: true },
method: { type: String, required: true },
req_query: [{
name: String, value: String
}],
req_headers: [{
name: String, value: String
}],
req_body_type: {
type: String,
enum: ['form', 'json', 'text', 'xml']
},
res_body_form: [{
name: String, value: String
}],
res_body_other: String
};
}
save(data) {
let m = new this.model(data);
return m.save();
}
get(id) {
return this.model.findOne({
_id: id
}).exec();
}
list() {
return this.model.find().exec();
}
del(id) {
return this.model.deleteOne({
_id: id
});
}
up(id, data) {
data.up_time = yapi.commons.time()
return this.model.update(
{ _id: id },
data
);
}
}
module.exports = interfaceCase;

View File

@ -0,0 +1,60 @@
import yapi from '../yapi.js';
import baseModel from './base.js';
class interfaceCol extends baseModel {
getName() {
return 'interface_col';
}
getSchema() {
return {
name: { type: String, required: true },
uid: { type: Number, required: true },
project_id: { type: Number, required: true },
desc: String,
add_time: Number,
up_time: Number,
};
}
save(data) {
let m = new this.model(data);
return m.save();
}
get(id) {
return this.model.findOne({
_id: id
}).exec();
}
checkRepeat(name) {
return this.model.count({
name: name
});
}
list(project_id) {
return this.model.find({
project_id: project_id
}).exec();
}
del(id) {
return this.model.deleteOne({
_id: id
});
}
up(id, data) {
data.up_time = yapi.commons.time()
return this.model.update(
{
_id: id
},
data
);
}
}
module.exports = interfaceCol;

View File

@ -13,6 +13,7 @@ class projectModel extends baseModel {
basepath: {type: String },
desc: String,
group_id: { type: Number, required: true },
project_type: {type:String, required: true, enum: ['public', 'private']},
members: [
{uid: Number, role: {type: String, enum:['owner', 'dev'], username: String, email: String}}
],
@ -56,10 +57,10 @@ class projectModel extends baseModel {
});
}
list(group_id) {
return this.model.find({
group_id: group_id
}).sort({ _id: -1 }).exec();
list(group_id, auth) {
let params = {group_id: group_id}
if(auth) params.project_type = 'public';
return this.model.find(params).sort({ _id: -1 }).exec();
}
listWithPaging(group_id, page, limit) {
@ -122,6 +123,17 @@ class projectModel extends baseModel {
});
}
changeMemberRole(id, uid, role) {
return this.model.update(
{
_id: id,
"members.uid": uid
}, {
"$set": { "members.$.uid": role}
}
);
}
search(keyword) {
return this.model.find({
name: new RegExp(keyword, 'ig')

View File

@ -322,125 +322,229 @@ var groupController = function (_baseController) {
return addMember;
}()
}, {
key: 'getMemberList',
key: 'changeMemberRole',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var params, groupInst, group;
var params, groupInst, check, result;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
params = ctx.request.query;
params = ctx.request.body;
groupInst = _yapi2.default.getInst(_group2.default);
if (params.id) {
_context4.next = 3;
if (params.member_uid) {
_context4.next = 4;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
case 3:
_context4.prev = 3;
groupInst = _yapi2.default.getInst(_group2.default);
_context4.next = 7;
return groupInst.get(params.id);
case 4:
if (params.id) {
_context4.next = 6;
break;
}
case 7:
group = _context4.sent;
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
ctx.body = _yapi2.default.commons.resReturn(group.members);
_context4.next = 14;
break;
case 6:
_context4.next = 8;
return groupInst.checkMemberRepeat(params.id, params.member_uid);
case 8:
check = _context4.sent;
if (!(check === 0)) {
_context4.next = 11;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
case 11:
_context4.prev = 11;
_context4.t0 = _context4['catch'](3);
_context4.next = 13;
return this.checkAuth(id, 'group', 'danger');
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 13:
_context4.t0 = _context4.sent;
case 14:
if (!(_context4.t0 !== true)) {
_context4.next = 16;
break;
}
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 16:
params.role = params.role === 'owner' ? 'owner' : 'dev';
_context4.prev = 17;
_context4.next = 20;
return groupInst.changeMemberRole(params.id, params.member_uid, params.role);
case 20:
result = _context4.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 27;
break;
case 24:
_context4.prev = 24;
_context4.t1 = _context4['catch'](17);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t1.message);
case 27:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[3, 11]]);
}, _callee4, this, [[17, 24]]);
}));
function getMemberList(_x5) {
function changeMemberRole(_x5) {
return _ref4.apply(this, arguments);
}
return changeMemberRole;
}()
}, {
key: 'getMemberList',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var params, groupInst, group;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
params = ctx.request.query;
if (params.id) {
_context5.next = 3;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 3:
_context5.prev = 3;
groupInst = _yapi2.default.getInst(_group2.default);
_context5.next = 7;
return groupInst.get(params.id);
case 7:
group = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(group.members);
_context5.next = 14;
break;
case 11:
_context5.prev = 11;
_context5.t0 = _context5['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
case 14:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[3, 11]]);
}));
function getMemberList(_x6) {
return _ref5.apply(this, arguments);
}
return getMemberList;
}()
}, {
key: 'delMember',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var params, groupInst, check, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
params = ctx.request.body;
groupInst = _yapi2.default.getInst(_group2.default);
if (params.member_uid) {
_context5.next = 4;
_context6.next = 4;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
case 4:
if (params.id) {
_context5.next = 6;
_context6.next = 6;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
case 6:
_context5.next = 8;
_context6.next = 8;
return groupInst.checkMemberRepeat(params.id, params.member_uid);
case 8:
check = _context5.sent;
check = _context6.sent;
if (!(check === 0)) {
_context5.next = 11;
_context6.next = 11;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
case 11:
_context5.prev = 11;
_context5.next = 14;
_context6.next = 13;
return this.checkAuth(id, 'group', 'danger');
case 13:
_context6.t0 = _context6.sent;
if (!(_context6.t0 !== true)) {
_context6.next = 16;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 16:
_context6.prev = 16;
_context6.next = 19;
return groupInst.delMember(params.id, params.member_uid);
case 14:
result = _context5.sent;
case 19:
result = _context6.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 21;
_context6.next = 26;
break;
case 18:
_context5.prev = 18;
_context5.t0 = _context5['catch'](11);
case 23:
_context6.prev = 23;
_context6.t1 = _context6['catch'](16);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t1.message);
case 21:
case 26:
case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, this, [[11, 18]]);
}, _callee6, this, [[16, 23]]);
}));
function delMember(_x6) {
return _ref5.apply(this, arguments);
function delMember(_x7) {
return _ref6.apply(this, arguments);
}
return delMember;
@ -459,40 +563,40 @@ var groupController = function (_baseController) {
}, {
key: 'list',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var groupInst, result;
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:
_context6.prev = 0;
_context7.prev = 0;
groupInst = _yapi2.default.getInst(_group2.default);
_context6.next = 4;
_context7.next = 4;
return groupInst.list();
case 4:
result = _context6.sent;
result = _context7.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context6.next = 11;
_context7.next = 11;
break;
case 8:
_context6.prev = 8;
_context6.t0 = _context6['catch'](0);
_context7.prev = 8;
_context7.t0 = _context7['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context6.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
case 11:
case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, this, [[0, 8]]);
}, _callee7, this, [[0, 8]]);
}));
function list(_x7) {
return _ref6.apply(this, arguments);
function list(_x8) {
return _ref7.apply(this, arguments);
}
return list;
@ -512,73 +616,74 @@ var groupController = function (_baseController) {
}, {
key: 'del',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var groupInst, projectInst, id, count, result;
return _regenerator2.default.wrap(function _callee7$(_context7) {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var groupInst, projectInst, _id, count, result;
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
if (!(this.getRole() !== 'admin')) {
_context7.next = 2;
_context8.next = 2;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
case 2:
_context7.prev = 2;
_context8.prev = 2;
groupInst = _yapi2.default.getInst(_group2.default);
projectInst = _yapi2.default.getInst(_project2.default);
id = ctx.request.body.id;
_id = ctx.request.body.id;
if (id) {
_context7.next = 8;
if (_id) {
_context8.next = 8;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
case 8:
_context7.next = 10;
return projectInst.countByGroupId(id);
_context8.next = 10;
return projectInst.countByGroupId(_id);
case 10:
count = _context7.sent;
count = _context8.sent;
if (!(count > 0)) {
_context7.next = 13;
_context8.next = 13;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
case 13:
_context7.next = 15;
return groupInst.del(id);
_context8.next = 15;
return groupInst.del(_id);
case 15:
result = _context7.sent;
result = _context8.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context7.next = 22;
_context8.next = 22;
break;
case 19:
_context7.prev = 19;
_context7.t0 = _context7['catch'](2);
_context8.prev = 19;
_context8.t0 = _context8['catch'](2);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t0.message);
case 22:
case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, this, [[2, 19]]);
}, _callee8, this, [[2, 19]]);
}));
function del(_x8) {
return _ref7.apply(this, arguments);
function del(_x9) {
return _ref8.apply(this, arguments);
}
return del;
@ -600,22 +705,28 @@ var groupController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var groupInst, id, data, result;
return _regenerator2.default.wrap(function _callee8$(_context8) {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var groupInst, _id2, data, result;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:
if (!(this.getRole() !== 'admin')) {
_context8.next = 2;
_context9.next = 2;
return this.checkAuth(id, 'group', 'danger');
case 2:
_context9.t0 = _context9.sent;
if (!(_context9.t0 !== true)) {
_context9.next = 5;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
case 2:
_context8.prev = 2;
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 5:
_context9.prev = 5;
ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, {
id: 'number',
@ -623,7 +734,7 @@ var groupController = function (_baseController) {
group_desc: 'string'
});
groupInst = _yapi2.default.getInst(_group2.default);
id = ctx.request.body.id;
_id2 = ctx.request.body.id;
data = {};
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name);
@ -631,32 +742,32 @@ var groupController = function (_baseController) {
if ((0, _keys2.default)(data).length === 0) {
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
}
_context8.next = 12;
return groupInst.up(id, data);
_context9.next = 15;
return groupInst.up(_id2, data);
case 12:
result = _context8.sent;
case 15:
result = _context9.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context8.next = 19;
_context9.next = 22;
break;
case 16:
_context8.prev = 16;
_context8.t0 = _context8['catch'](2);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t0.message);
case 19:
_context9.prev = 19;
_context9.t1 = _context9['catch'](5);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t1.message);
case 22:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, this, [[2, 16]]);
}, _callee9, this, [[5, 19]]);
}));
function up(_x9) {
return _ref8.apply(this, arguments);
function up(_x10) {
return _ref9.apply(this, arguments);
}
return up;

View File

@ -0,0 +1,63 @@
'use strict';
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _interfaceCase = require('../models/interfaceCase.js');
var _interfaceCase2 = _interopRequireDefault(_interfaceCase);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var interfaceCaseController = function (_baseController) {
(0, _inherits3.default)(interfaceCaseController, _baseController);
function interfaceCaseController(ctx) {
(0, _classCallCheck3.default)(this, interfaceCaseController);
var _this = (0, _possibleConstructorReturn3.default)(this, (interfaceCaseController.__proto__ || (0, _getPrototypeOf2.default)(interfaceCaseController)).call(this, ctx));
_this.Model = _yapi2.default.getInst(_interfaceCase2.default);
return _this;
}
(0, _createClass3.default)(interfaceCaseController, [{
key: 'list',
value: function list(ctx) {}
}, {
key: 'get',
value: function get(ctx) {}
}, {
key: 'up',
value: function up(ctx) {}
}, {
key: 'del',
value: function del(ctx) {}
}]);
return interfaceCaseController;
}(_base2.default);

View File

@ -0,0 +1,143 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _interfaceCol = require('../models/interfaceCol.js');
var _interfaceCol2 = _interopRequireDefault(_interfaceCol);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var interfaceColController = function (_baseController) {
(0, _inherits3.default)(interfaceColController, _baseController);
function interfaceColController(ctx) {
(0, _classCallCheck3.default)(this, interfaceColController);
var _this = (0, _possibleConstructorReturn3.default)(this, (interfaceColController.__proto__ || (0, _getPrototypeOf2.default)(interfaceColController)).call(this, ctx));
_this.Model = _yapi2.default.getInst(_interfaceCol2.default);
return _this;
}
(0, _createClass3.default)(interfaceColController, [{
key: 'list',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var id, inst, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
id = ctx.query.project_id;
inst = _yapi2.default.getInst(_interfaceCol2.default);
_context.next = 5;
return inst.list(id);
case 5:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 12;
break;
case 9:
_context.prev = 9;
_context.t0 = _context['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
case 12:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[0, 9]]);
}));
function list(_x) {
return _ref.apply(this, arguments);
}
return list;
}()
}, {
key: 'up',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function up(_x2) {
return _ref2.apply(this, arguments);
}
return up;
}()
}, {
key: 'del',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function del(_x3) {
return _ref3.apply(this, arguments);
}
return del;
}()
}]);
return interfaceColController;
}(_base2.default);

View File

@ -129,77 +129,91 @@ var projectController = function (_baseController) {
desc: 'string'
});
_context.next = 4;
return this.checkAuth(params.group_id, 'group', 'edit');
case 4:
_context.t0 = _context.sent;
if (!(_context.t0 !== true)) {
_context.next = 7;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 7:
if (params.group_id) {
_context.next = 4;
_context.next = 9;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
case 4:
case 9:
if (params.name) {
_context.next = 6;
_context.next = 11;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
case 6:
_context.next = 8;
case 11:
_context.next = 13;
return this.Model.checkNameRepeat(params.name);
case 8:
case 13:
checkRepeat = _context.sent;
if (!(checkRepeat > 0)) {
_context.next = 11;
_context.next = 16;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 11:
case 16:
if (params.prd_host) {
_context.next = 13;
_context.next = 18;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
case 13:
case 18:
params.basepath = params.basepath || '';
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
_context.next = 16;
_context.next = 21;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
case 16:
case 21:
if (this.verifyDomain(params.prd_host)) {
_context.next = 18;
_context.next = 23;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
case 18:
_context.next = 20;
case 23:
_context.next = 25;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 20:
case 25:
checkRepeatDomain = _context.sent;
if (!(checkRepeatDomain > 0)) {
_context.next = 23;
_context.next = 28;
break;
}
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 23:
case 28:
data = {
name: params.name,
desc: params.desc,
@ -212,29 +226,29 @@ var projectController = function (_baseController) {
add_time: _yapi2.default.commons.time(),
up_time: _yapi2.default.commons.time()
};
_context.prev = 24;
_context.next = 27;
_context.prev = 29;
_context.next = 32;
return this.Model.save(data);
case 27:
case 32:
result = _context.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context.next = 34;
_context.next = 39;
break;
case 31:
_context.prev = 31;
_context.t0 = _context['catch'](24);
case 36:
_context.prev = 36;
_context.t1 = _context['catch'](29);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t1.message);
case 34:
case 39:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[24, 31]]);
}, _callee, this, [[29, 36]]);
}));
function add(_x) {
@ -283,56 +297,70 @@ var projectController = function (_baseController) {
case 5:
_context2.next = 7;
return this.Model.checkMemberRepeat(params.id, params.member_uid);
return this.checkAuth(params.id, 'project', 'edit');
case 7:
_context2.t0 = _context2.sent;
if (!(_context2.t0 !== true)) {
_context2.next = 10;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 10:
_context2.next = 12;
return this.Model.checkMemberRepeat(params.id, params.member_uid);
case 12:
check = _context2.sent;
if (!(check > 0)) {
_context2.next = 10;
_context2.next = 15;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员已存在'));
case 10:
_context2.next = 12;
case 15:
_context2.next = 17;
return this.getUserdata(params.member_uid);
case 12:
case 17:
userdata = _context2.sent;
if (!(userdata === null)) {
_context2.next = 15;
_context2.next = 20;
break;
}
return _context2.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '成员uid不存在'));
case 15:
_context2.prev = 15;
_context2.next = 18;
case 20:
_context2.prev = 20;
_context2.next = 23;
return this.Model.addMember(params.id, userdata);
case 18:
case 23:
result = _context2.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context2.next = 25;
_context2.next = 30;
break;
case 22:
_context2.prev = 22;
_context2.t0 = _context2['catch'](15);
case 27:
_context2.prev = 27;
_context2.t1 = _context2['catch'](20);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context2.t1.message);
case 25:
case 30:
case 'end':
return _context2.stop();
}
}
}, _callee2, this, [[15, 22]]);
}, _callee2, this, [[20, 27]]);
}));
function addMember(_x2) {
@ -394,29 +422,43 @@ var projectController = function (_baseController) {
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目成员不存在'));
case 10:
_context3.prev = 10;
_context3.next = 13;
_context3.next = 12;
return this.checkAuth(params.id, 'project', 'danger');
case 12:
_context3.t0 = _context3.sent;
if (!(_context3.t0 !== true)) {
_context3.next = 15;
break;
}
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 15:
_context3.prev = 15;
_context3.next = 18;
return this.Model.delMember(params.id, params.member_uid);
case 13:
case 18:
result = _context3.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context3.next = 20;
_context3.next = 25;
break;
case 17:
_context3.prev = 17;
_context3.t0 = _context3['catch'](10);
case 22:
_context3.prev = 22;
_context3.t1 = _context3['catch'](15);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t0.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context3.t1.message);
case 20:
case 25:
case 'end':
return _context3.stop();
}
}
}, _callee3, this, [[10, 17]]);
}, _callee3, this, [[15, 22]]);
}));
function delMember(_x3) {
@ -611,7 +653,7 @@ var projectController = function (_baseController) {
key: 'list',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var group_id, page, limit, result, uids, _users, users;
var group_id, page, limit, auth, result, uids, _users, users;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
@ -627,11 +669,12 @@ var projectController = function (_baseController) {
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
case 3:
_context7.prev = 3;
_context7.next = 6;
return this.Model.list(group_id);
auth = this.checkAuth(group_id, 'group', 'edit');
_context7.prev = 4;
_context7.next = 7;
return this.Model.list(group_id, auth);
case 6:
case 7:
result = _context7.sent;
uids = [];
@ -641,10 +684,10 @@ var projectController = function (_baseController) {
}
});
_users = {};
_context7.next = 12;
_context7.next = 13;
return _yapi2.default.getInst(_user2.default).findByUids(uids);
case 12:
case 13:
users = _context7.sent;
users.forEach(function (item) {
@ -654,21 +697,21 @@ var projectController = function (_baseController) {
list: result,
userinfo: _users
});
_context7.next = 20;
_context7.next = 21;
break;
case 17:
_context7.prev = 17;
_context7.t0 = _context7['catch'](3);
case 18:
_context7.prev = 18;
_context7.t0 = _context7['catch'](4);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t0.message);
case 20:
case 21:
case 'end':
return _context7.stop();
}
}
}, _callee7, this, [[3, 17]]);
}, _callee7, this, [[4, 18]]);
}));
function list(_x8) {
@ -693,15 +736,16 @@ var projectController = function (_baseController) {
key: 'del',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var id, interfaceInst, count, result;
var _id, interfaceInst, count, result;
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.prev = 0;
id = ctx.request.body.id;
_id = ctx.request.body.id;
if (id) {
if (_id) {
_context8.next = 4;
break;
}
@ -711,7 +755,7 @@ var projectController = function (_baseController) {
case 4:
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context8.next = 7;
return interfaceInst.countByProjectId(id);
return interfaceInst.countByProjectId(_id);
case 7:
count = _context8.sent;
@ -725,7 +769,7 @@ var projectController = function (_baseController) {
case 10:
_context8.next = 12;
return this.checkAuth(id, 'project', 'owner');
return this.checkAuth(_id, 'project', 'danger');
case 12:
_context8.t0 = _context8.sent;
@ -739,7 +783,7 @@ var projectController = function (_baseController) {
case 15:
_context8.next = 17;
return this.Model.del(id);
return this.Model.del(_id);
case 17:
result = _context8.sent;
@ -768,6 +812,96 @@ var projectController = function (_baseController) {
return del;
}()
}, {
key: 'changeMemberRole',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var params, groupInst, check, result;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
params = ctx.request.body;
groupInst = _yapi2.default.getInst(_group2.default);
if (params.member_uid) {
_context9.next = 4;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员uid不能为空'));
case 4:
if (params.id) {
_context9.next = 6;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组id不能为空'));
case 6:
_context9.next = 8;
return groupInst.checkMemberRepeat(params.id, params.member_uid);
case 8:
check = _context9.sent;
if (!(check === 0)) {
_context9.next = 11;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '分组成员不存在'));
case 11:
_context9.next = 13;
return this.checkAuth(id, 'group', 'danger');
case 13:
_context9.t0 = _context9.sent;
if (!(_context9.t0 !== true)) {
_context9.next = 16;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 16:
params.role = params.role === 'owner' ? 'owner' : 'dev';
_context9.prev = 17;
_context9.next = 20;
return groupInst.changeMemberRole(params.id, params.member_uid, params.role);
case 20:
result = _context9.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context9.next = 27;
break;
case 24:
_context9.prev = 24;
_context9.t1 = _context9['catch'](17);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t1.message);
case 27:
case 'end':
return _context9.stop();
}
}
}, _callee9, this, [[17, 24]]);
}));
function changeMemberRole(_x10) {
return _ref9.apply(this, arguments);
}
return changeMemberRole;
}()
/**
* 编辑项目
@ -790,14 +924,15 @@ var projectController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var id, params, projectData, checkRepeat, checkRepeatDomain, data, result;
return _regenerator2.default.wrap(function _callee9$(_context9) {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _id2, params, projectData, checkRepeat, checkRepeatDomain, data, result;
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
_context9.prev = 0;
id = ctx.request.body.id;
_context10.prev = 0;
_id2 = ctx.request.body.id;
params = ctx.request.body;
params.basepath = params.basepath || '';
@ -810,48 +945,48 @@ var projectController = function (_baseController) {
desc: 'string'
});
if (id) {
_context9.next = 7;
if (_id2) {
_context10.next = 7;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
case 7:
_context9.next = 9;
return this.checkAuth(id, 'project', 'edit');
_context10.next = 9;
return this.checkAuth(_id2, 'project', 'edit');
case 9:
_context9.t0 = _context9.sent;
_context10.t0 = _context10.sent;
if (!(_context9.t0 !== true)) {
_context9.next = 12;
if (!(_context10.t0 !== true)) {
_context10.next = 12;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 12:
_context9.next = 14;
return this.Model.get(id);
_context10.next = 14;
return this.Model.get(_id2);
case 14:
projectData = _context9.sent;
projectData = _context10.sent;
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
_context9.next = 17;
_context10.next = 17;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
case 17:
if (this.verifyDomain(params.prd_host)) {
_context9.next = 19;
_context10.next = 19;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
case 19:
@ -864,41 +999,41 @@ var projectController = function (_baseController) {
}
if (!params.name) {
_context9.next = 27;
_context10.next = 27;
break;
}
_context9.next = 24;
_context10.next = 24;
return this.Model.checkNameRepeat(params.name);
case 24:
checkRepeat = _context9.sent;
checkRepeat = _context10.sent;
if (!(checkRepeat > 0)) {
_context9.next = 27;
_context10.next = 27;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 27:
if (!(params.basepath && params.prd_host)) {
_context9.next = 33;
_context10.next = 33;
break;
}
_context9.next = 30;
_context10.next = 30;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 30:
checkRepeatDomain = _context9.sent;
checkRepeatDomain = _context10.sent;
if (!(checkRepeatDomain > 0)) {
_context9.next = 33;
_context10.next = 33;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 33:
data = {
@ -915,32 +1050,32 @@ var projectController = function (_baseController) {
if (params.protocol) data.protocol = params.protocol;
if (params.env) data.env = params.env;
_context9.next = 41;
return this.Model.up(id, data);
_context10.next = 41;
return this.Model.up(_id2, data);
case 41:
result = _context9.sent;
result = _context10.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context9.next = 48;
_context10.next = 48;
break;
case 45:
_context9.prev = 45;
_context9.t1 = _context9['catch'](0);
_context10.prev = 45;
_context10.t1 = _context10['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context9.t1.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context10.t1.message);
case 48:
case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee9, this, [[0, 45]]);
}, _callee10, this, [[0, 45]]);
}));
function up(_x10) {
return _ref9.apply(this, arguments);
function up(_x11) {
return _ref10.apply(this, arguments);
}
return up;
@ -960,40 +1095,40 @@ var projectController = function (_baseController) {
}, {
key: 'search',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
var q, projectList, groupList, projectRules, groupRules, queryList;
return _regenerator2.default.wrap(function _callee10$(_context10) {
return _regenerator2.default.wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:
q = ctx.request.query.q;
if (q) {
_context10.next = 3;
_context11.next = 3;
break;
}
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
case 3:
if (_yapi2.default.commons.validateSearchKeyword(q)) {
_context10.next = 5;
_context11.next = 5;
break;
}
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
case 5:
_context10.next = 7;
_context11.next = 7;
return this.Model.search(q);
case 7:
projectList = _context10.sent;
_context10.next = 10;
projectList = _context11.sent;
_context11.next = 10;
return this.groupModel.search(q);
case 10:
groupList = _context10.sent;
groupList = _context11.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' }];
@ -1005,18 +1140,18 @@ var projectController = function (_baseController) {
project: projectList,
group: groupList
};
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
return _context11.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
case 17:
case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee10, this);
}, _callee11, this);
}));
function search(_x11) {
return _ref10.apply(this, arguments);
function search(_x12) {
return _ref11.apply(this, arguments);
}
return search;

View File

@ -98,6 +98,16 @@ var groupModel = function (_baseModel) {
$pull: { members: { uid: uid } }
});
}
}, {
key: 'changeMemberRole',
value: function changeMemberRole(id, uid, role) {
return this.model.update({
_id: id,
"members.uid": uid
}, {
"$set": { "members.$.uid": role }
});
}
}, {
key: 'checkMemberRepeat',
value: function checkMemberRepeat(id, uid) {

View File

@ -55,6 +55,9 @@ var interfaceModel = function (_baseModel) {
desc: String,
add_time: Number,
up_time: Number,
req_query: [{
name: String, value: String, desc: String, required: Boolean
}],
req_headers: [{
name: String, value: String, desc: String, required: Boolean
}],

View File

@ -0,0 +1,111 @@
'use strict';
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var interfaceCase = function (_baseModel) {
(0, _inherits3.default)(interfaceCase, _baseModel);
function interfaceCase() {
(0, _classCallCheck3.default)(this, interfaceCase);
return (0, _possibleConstructorReturn3.default)(this, (interfaceCase.__proto__ || (0, _getPrototypeOf2.default)(interfaceCase)).apply(this, arguments));
}
(0, _createClass3.default)(interfaceCase, [{
key: 'getName',
value: function getName() {
return 'interface_col';
}
}, {
key: 'getSchema',
value: function getSchema() {
return {
casename: { type: String, required: true },
uid: { type: Number, required: true },
col_id: { type: Number, required: true },
project_id: { type: Number, required: true },
add_time: Number,
up_time: Number,
env: { type: String, required: true },
path: { type: String, required: true },
method: { type: String, required: true },
req_query: [{
name: String, value: String
}],
req_headers: [{
name: String, value: String
}],
req_body_type: {
type: String,
enum: ['form', 'json', 'text', 'xml']
},
res_body_form: [{
name: String, value: String
}],
res_body_other: String
};
}
}, {
key: 'save',
value: function save(data) {
var m = new this.model(data);
return m.save();
}
}, {
key: 'get',
value: function get(id) {
return this.model.findOne({
_id: id
}).exec();
}
}, {
key: 'list',
value: function list() {
return this.model.find().exec();
}
}, {
key: 'del',
value: function del(id) {
return this.model.deleteOne({
_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {
data.up_time = _yapi2.default.commons.time();
return this.model.update({ _id: id }, data);
}
}]);
return interfaceCase;
}(_base2.default);
module.exports = interfaceCase;

View File

@ -0,0 +1,104 @@
'use strict';
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
var _base = require('./base.js');
var _base2 = _interopRequireDefault(_base);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var interfaceCol = function (_baseModel) {
(0, _inherits3.default)(interfaceCol, _baseModel);
function interfaceCol() {
(0, _classCallCheck3.default)(this, interfaceCol);
return (0, _possibleConstructorReturn3.default)(this, (interfaceCol.__proto__ || (0, _getPrototypeOf2.default)(interfaceCol)).apply(this, arguments));
}
(0, _createClass3.default)(interfaceCol, [{
key: 'getName',
value: function getName() {
return 'interface_col';
}
}, {
key: 'getSchema',
value: function getSchema() {
return {
name: { type: String, required: true },
uid: { type: Number, required: true },
project_id: { type: Number, required: true },
desc: String,
add_time: Number,
up_time: Number
};
}
}, {
key: 'save',
value: function save(data) {
var m = new this.model(data);
return m.save();
}
}, {
key: 'get',
value: function get(id) {
return this.model.findOne({
_id: id
}).exec();
}
}, {
key: 'checkRepeat',
value: function checkRepeat(name) {
return this.model.count({
name: name
});
}
}, {
key: 'list',
value: function list(project_id) {
return this.model.find({
project_id: project_id
}).exec();
}
}, {
key: 'del',
value: function del(id) {
return this.model.deleteOne({
_id: id
});
}
}, {
key: 'up',
value: function up(id, data) {
data.up_time = _yapi2.default.commons.time();
return this.model.update({
_id: id
}, data);
}
}]);
return interfaceCol;
}(_base2.default);
module.exports = interfaceCol;

View File

@ -52,6 +52,7 @@ var projectModel = function (_baseModel) {
basepath: { type: String },
desc: String,
group_id: { type: Number, required: true },
project_type: { type: String, required: true, enum: ['public', 'private'] },
members: [{ uid: Number, role: { type: String, enum: ['owner', 'dev'], username: String, email: String } }],
protocol: { type: String, required: true },
prd_host: { type: String, required: true },
@ -97,10 +98,10 @@ var projectModel = function (_baseModel) {
}
}, {
key: 'list',
value: function list(group_id) {
return this.model.find({
group_id: group_id
}).sort({ _id: -1 }).exec();
value: function list(group_id, auth) {
var params = { group_id: group_id };
if (auth) params.project_type = 'public';
return this.model.find(params).sort({ _id: -1 }).exec();
}
}, {
key: 'listWithPaging',
@ -166,6 +167,16 @@ var projectModel = function (_baseModel) {
"members.uid": uid
});
}
}, {
key: 'changeMemberRole',
value: function changeMemberRole(id, uid, role) {
return this.model.update({
_id: id,
"members.uid": uid
}, {
"$set": { "members.$.uid": role }
});
}
}, {
key: 'search',
value: function search(keyword) {

View File

@ -11,10 +11,10 @@
<script src="http://127.0.0.1:4000/yapi/prd/manifest@dev.js"></script>
<script src="http://127.0.0.1:4000/yapi/prd/lib2@dev.js"></script>
<script src="http://127.0.0.1:4000/yapi/prd/lib@dev.js"></script>
<script src="http://127.0.0.1:4000/yapi/prd/index@dev.js"></script>
<script src="http://127.0.0.1:4000/prd/manifest@dev.js"></script>
<script src="http://127.0.0.1:4000/prd/lib2@dev.js"></script>
<script src="http://127.0.0.1:4000/prd/lib@dev.js"></script>
<script src="http://127.0.0.1:4000/prd/index@dev.js"></script>
<script src="/lib/ace-1.2.8.js"></script>
<script src="/lib/snippets-json.js"></script>

View File

@ -13,6 +13,7 @@ module.exports = {
modifyQuery: function (defaultQuery) { // 可查看和编辑 defaultQuery
defaultQuery.plugins = [];
defaultQuery.plugins.push('transform-decorators-legacy');
defaultQuery.plugins.push(["import", { libraryName: "antd", style: "css" }])
return defaultQuery;
}
}
@ -31,12 +32,12 @@ module.exports = {
'react-dom',
'redux-promise',
'react-router-dom',
'prop-types',
'prop-types'
],
lib2:[
'axios',
'moment'
],
lib2: [
'antd'
]
}
},