feat: openapi 用户角色改为项目开发

This commit is contained in:
suwenxiong 2019-01-28 09:41:58 +08:00
parent 23adaaa4e5
commit 48b3024a14
8 changed files with 56 additions and 17 deletions

View File

@ -34,8 +34,8 @@ export default class LoginWrap extends Component {
<TabPane tab="登录" key="1">
<LoginForm />
</TabPane>
<TabPane tab="注册" key="2" disabled={!canRegister}>
<RegForm />
<TabPane tab={"注册"} key="2">
{canRegister ? <RegForm /> : <div style={{minHeight: 200}}>管理员已禁止注册请联系管理员</div>}
</TabPane>
</Tabs>
);

View File

@ -56,7 +56,7 @@ class ProjectToken extends Component {
<div className="project-token">
<h2 className="token-title">工具标识</h2>
<div className="message">
每个项目都有唯一的标识token用户可以使用这个token值来请求项目的所有资源数据
每个项目都有唯一的标识token用户可以使用这个token值来请求项目 openapi.
</div>
<div className="token">
<span>
@ -74,6 +74,22 @@ class ProjectToken extends Component {
<div className="blockquote">
为确保项目内数据的安全性和私密性请勿轻易将该token暴露给项目组外用户
</div>
<br />
{/* <h2 className="token-title">open接口</h2> */}
{/* <div>
<ul className="open-api">
<li>/api/open/run_auto_test []</li>
<li>/api/open/import_data []</li>
<li>/api/interface/add []</li>
<li>/api/interface/save []</li>
<li>/api/interface/up []</li>
<li>/api/interface/get []</li>
<li>/api/interface/list []</li>
<li>/api/interface/list_menu []</li>
<li>/api/interface/add_cat []</li>
<li>/api/interface/getCatMenu []</li>
</ul>
</div> */}
</div>
);
}

View File

@ -17,6 +17,14 @@
}
.open-api{
margin-top: 10px;
margin-left: 20px;
li{
margin-bottom: 10px;
}
}
.message{
padding: 16px 0 0 16px;
font-size: 14px;

View File

@ -131,11 +131,11 @@ class WikiPage extends Component {
};
this.handleWebsocketAccidentClose(sendEditor, status => {
// 如果websocket 启动不成功用户依旧可以对wiki 进行编辑
// if (!status) {
if (!status) {
this.setState({
isEditor: !this.state.isEditor
});
// }
}
});
};

View File

@ -1,6 +1,6 @@
{
"name": "yapi-vendor",
"version": "1.4.4",
"version": "1.5.0",
"description": "YAPI",
"main": "server/app.js",
"scripts": {

View File

@ -6,6 +6,7 @@ const groupModel = require('../models/group.js');
const tokenModel = require('../models/token.js');
const _ = require('underscore');
const jwt = require('jsonwebtoken');
const OPENAPI_USER = 99999999;
class baseController {
constructor(ctx) {
@ -38,11 +39,15 @@ class baseController {
let openApiRouter = [
'/api/open/run_auto_test',
'/api/open/import_data',
'/api/interface/add',
'/api/interface/save',
'/api/interface/up',
'/api/interface/add_cat'
'/api/open/import_data',
'/api/interface/add',
'/api/interface/save',
'/api/interface/up',
'/api/interface/get',
'/api/interface/list',
'/api/interface/list_menu',
'/api/interface/add_cat',
'/api/interface/getCatMenu'
];
let params = Object.assign({}, ctx.query, ctx.request.body);
@ -63,7 +68,7 @@ class baseController {
if (projectData) {
ctx.params.project_id = checkId;
this.$tokenAuth = true;
this.$uid = '999999';
this.$uid = OPENAPI_USER;
this.$user = {
_id: this.$uid,
role: 'member',
@ -258,6 +263,9 @@ class baseController {
*/
async checkAuth(id, type, action) {
let role = await this.getProjectRole(id, type);
if(this.getUid() === OPENAPI_USER){
role = 'dev'
}
if (action === 'danger') {
if (role === 'admin' || role === 'owner') {

View File

@ -398,13 +398,19 @@ class interfaceController extends baseController {
* @example ./api/interface/get.json
*/
async get(ctx) {
let params = ctx.request.query;
let params = ctx.params;
if (!params.id) {
return (ctx.body = yapi.commons.resReturn(null, 400, '接口id不能为空'));
}
try {
let result = await this.Model.get(params.id);
if(this.$tokenAuth){
if(params.project_id !== result.project_id){
ctx.body = yapi.commons.resReturn(null, 400, 'token有误')
return;
}
}
// console.log('result', result);
if (!result) {
return (ctx.body = yapi.commons.resReturn(null, 490, '不存在的'));
@ -440,7 +446,7 @@ class interfaceController extends baseController {
* @example ./api/interface/list.json
*/
async list(ctx) {
let project_id = ctx.request.query.project_id;
let project_id = ctx.params.project_id;
let page = ctx.request.query.page || 1,
limit = ctx.request.query.limit || 10;
let project = await this.projectModel.getBaseInfo(project_id);
@ -520,7 +526,7 @@ class interfaceController extends baseController {
}
async listByMenu(ctx) {
let project_id = ctx.request.query.project_id;
let project_id = ctx.params.project_id;
if (!project_id) {
return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));
}
@ -980,7 +986,7 @@ class interfaceController extends baseController {
*/
async getCatMenu(ctx) {
let project_id = ctx.request.query.project_id;
let project_id = ctx.params.project_id;
if (!project_id || isNaN(project_id)) {
return (ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'));

View File

@ -417,8 +417,9 @@ exports.createAction = (router, baseurl, routerController, action, path, method,
let inst = new routerController(ctx);
try {
await inst.init(ctx);
ctx.params = Object.assign({}, ctx.request.query, ctx.request.body, ctx.params);
if (inst.schemaMap && typeof inst.schemaMap === 'object' && inst.schemaMap[action]) {
ctx.params = Object.assign({}, ctx.request.query, ctx.request.body, ctx.params);
let validResult = yapi.commons.validateParams(inst.schemaMap[action], ctx.params);
if (!validResult.valid) {