From bc85db953966e91eae28693270d03b10e21f87b7 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Fri, 22 Sep 2017 12:08:23 +0800 Subject: [PATCH] =?UTF-8?q?opti:=20=E5=AE=8C=E5=96=84=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=92=8C=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/project.js | 59 +++++++++++++++++++++++++++++++---- server/router.js | 6 ++-- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/server/controllers/project.js b/server/controllers/project.js index c138f077..6494ce70 100755 --- a/server/controllers/project.js +++ b/server/controllers/project.js @@ -517,9 +517,6 @@ class projectController extends baseController { * @param {String} name 项目名称,不能为空 * @param {String} basepath 项目基本路径,不能为空 * @param {String} [desc] 项目描述 - * @param {Array} [env] 项目环境配置 - * @param {String} [env[].name] 环境名称 - * @param {String} [env[].domain] 环境域名 * @returns {Object} * @example ./api/project/up.json */ @@ -540,7 +537,7 @@ class projectController extends baseController { return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空'); } - if (await this.checkAuth(id, 'project', 'edit') !== true) { + if (await this.checkAuth(id, 'project', 'danger') !== true) { return ctx.body = yapi.commons.resReturn(null, 405, '没有权限'); } @@ -572,7 +569,6 @@ class projectController extends baseController { if (!_.isUndefined(params.name)) data.name = params.name; if (!_.isUndefined(params.desc)) data.desc = params.desc; data.basepath = params.basepath; - if (!_.isUndefined(params.env)) data.env = params.env; if (!_.isUndefined(params.color)) data.color = params.color; if (!_.isUndefined(params.icon)) data.icon = params.icon; let result = await this.Model.up(id, data); @@ -588,7 +584,58 @@ class projectController extends baseController { } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); } - } + } + + + /** + * 编辑项目 + * @interface /project/up_env + * @method POST + * @category project + * @foldnumber 10 + * @param {Number} id 项目id,不能为空 + * @param {Array} [env] 项目环境配置 + * @param {String} [env[].name] 环境名称 + * @param {String} [env[].domain] 环境域名 + * @returns {Object} + * @example + */ + async upEnv(ctx) { + try { + let id = ctx.request.body.id; + let params = ctx.request.body; + if (!id) { + return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空'); + } + + if (await this.checkAuth(id, 'project', 'edit') !== true) { + return ctx.body = yapi.commons.resReturn(null, 405, '没有权限'); + } + + if(!params.env || !Array.isArray(params.env)){ + return ctx.body = yapi.commons.resReturn(null, 405, 'env参数格式有误'); + } + + let projectData = await this.Model.get(id); + let data = { + up_time: yapi.commons.time() + }; + + data.env = params.env; + let result = await this.Model.up(id, data); + let username = this.getUsername(); + yapi.commons.saveLog({ + content: `用户 "${username}" 更新了项目 "${projectData.name}" 环境`, + type: 'project', + uid: this.getUid(), + username: username, + typeid: id + }); + ctx.body = yapi.commons.resReturn(result); + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); + } + } /** * 模糊搜索项目名称或者组名称 diff --git a/server/router.js b/server/router.js index 0050e8c3..d074aaf0 100755 --- a/server/router.js +++ b/server/router.js @@ -228,9 +228,9 @@ let routerConfig = { "method": "get" }, { - "action": "download", - "path": "download", - "method": "get" + "action": "upEnv", + "path": "up_env", + "method": "post" } ], "interface": [