feat: 增加项目访客权限

This commit is contained in:
zwjamnsss 2017-09-21 16:46:14 +08:00
parent 765889462d
commit 92dc670240
7 changed files with 60 additions and 45 deletions

View File

@ -100,6 +100,7 @@ class ProjectList extends Component {
render() {
const projectData = this.state.projectData;
console.log(this.props.currGroup.role)
return (
<div style={{ paddingTop: '24px' }} className="m-panel card-panel card-panel-s project-list" >
<Row className="project-list-header">
@ -109,7 +110,7 @@ class ProjectList extends Component {
<Col>
<Tooltip title="您没有权限,请联系该分组组长或管理员">
{this.props.currGroup.role!== 'member' ?
{ /(admin)|(owner)|(dev)/.test(this.props.currGroup.role) ?
<Button type="primary" ><Link to="/add-project">添加项目</Link></Button> :
<Button type="primary" disabled >添加项目</Button>}
</Tooltip>

View File

@ -186,6 +186,7 @@ class ProjectMember extends Component {
<Select value={record.role+'-'+record.uid} className="select" onChange={this.changeUserRole}>
<Option value={'owner-'+record.uid}>组长</Option>
<Option value={'dev-'+record.uid}>开发者</Option>
<Option value={'guest-'+record.uid}>访客</Option>
</Select>
<Popconfirm placement="topRight" title="你确定要删除吗? " onConfirm={this.deleteConfirm(record.uid)} okText="确定" cancelText="">
<Button type="danger" icon="minus" className="btn-danger" />
@ -198,6 +199,8 @@ class ProjectMember extends Component {
return '组长';
} else if (record.role === 'dev') {
return '开发者';
} else if (record.role === 'guest') {
return '访客';
} else {
return '';
}
@ -225,6 +228,7 @@ class ProjectMember extends Component {
<Select size="large" defaultValue="dev" className="select" onChange={this.changeNewMemberRole}>
<Option value="owner">组长</Option>
<Option value="dev">开发者</Option>
<Option value="guest">访客</Option>
</Select>
</Col>
</Row>

64
npm-shrinkwrap.json generated
View File

@ -5312,14 +5312,6 @@
}
}
},
"string_decoder": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.1.tgz",
"integrity": "sha1-YuIA8DmVWmgQ2N8KM//A8BNmLZg=",
"requires": {
"safe-buffer": "5.0.1"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
@ -5330,6 +5322,14 @@
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.1.tgz",
"integrity": "sha1-YuIA8DmVWmgQ2N8KM//A8BNmLZg=",
"requires": {
"safe-buffer": "5.0.1"
}
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
@ -12638,22 +12638,6 @@
}
}
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha1-TPNaQkf2TKPfjC7yCMxJSxyo/C4=",
"requires": {
"resolve-from": "2.0.0",
"semver": "5.4.1"
},
"dependencies": {
"resolve-from": {
"version": "2.0.0",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
}
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/require-directory/-/require-directory-2.1.1.tgz",
@ -12678,6 +12662,22 @@
"resolve-from": "1.0.1"
}
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha1-TPNaQkf2TKPfjC7yCMxJSxyo/C4=",
"requires": {
"resolve-from": "2.0.0",
"semver": "5.4.1"
},
"dependencies": {
"resolve-from": {
"version": "2.0.0",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
}
}
},
"requires-port": {
"version": "1.0.0",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/requires-port/-/requires-port-1.0.0.tgz",
@ -13351,14 +13351,6 @@
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM="
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=",
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-convert": {
"version": "0.2.1",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/string-convert/-/string-convert-0.2.1.tgz",
@ -13445,6 +13437,14 @@
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=",
"requires": {
"safe-buffer": "5.1.1"
}
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/stringstream/-/stringstream-0.0.5.tgz",

View File

@ -93,6 +93,7 @@ class baseController {
let interfaceInst = yapi.getInst(interfaceModel);
let interfaceData = await interfaceInst.get(id)
result.interfaceData = interfaceData;
// 项目创建者相当于 owner
if (interfaceData.uid === this.getUid()) {
return 'owner';
}
@ -115,8 +116,10 @@ class baseController {
if (memberData && memberData.role) {
if (memberData.role === 'owner') {
return 'owner';
} else {
} else if (memberData.role === 'dev') {
return 'dev';
} else {
return 'guest';
}
}
type = 'group';
@ -134,8 +137,10 @@ class baseController {
if (groupMemberData && groupMemberData.role) {
if (groupMemberData.role === 'owner') {
return 'owner';
} else {
} else if (groupMemberData.role === 'dev') {
return 'dev'
} else {
return 'guest'
}
}
}
@ -151,7 +156,7 @@ class baseController {
*
* @param {*} id type对应的id
* @param {*} type enum[interface, project, group]
* @param {*} action enum[ danger , edit ] danger只有owner或管理员才能操作,edit只要是dev或以上就能执行
* @param {*} action enum[ danger, edit, view ] danger只有owner或管理员才能操作,edit只要是dev或以上就能执行
*/
async checkAuth(id, type, action) {
let role = await this.getProjectRole(id, type);
@ -163,6 +168,10 @@ class baseController {
if (role === 'admin' || role === 'owner' || role === 'dev') {
return true;
}
} else if (action === 'view') {
if (role === 'admin' || role === 'owner' || role === 'dev' || role === 'guest') {
return true;
}
}
return false;
}

View File

@ -232,7 +232,7 @@ class interfaceController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 407, '不存在的项目');
}
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
if (await this.checkAuth(project._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
@ -257,7 +257,7 @@ class interfaceController extends baseController {
let catdata = await this.catModel.get(catid);
let project = await this.projectModel.getBaseInfo(catdata.project_id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
if (await this.checkAuth(project._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
@ -278,7 +278,7 @@ class interfaceController extends baseController {
let project = await this.projectModel.getBaseInfo(project_id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
if (await this.checkAuth(project._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}

View File

@ -29,7 +29,7 @@ class interfaceColController extends baseController{
let id = ctx.query.project_id;
let project = await this.projectModel.getBaseInfo(id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
if (await this.checkAuth(project._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
@ -124,7 +124,7 @@ class interfaceColController extends baseController{
let project = await this.projectModel.getBaseInfo(colData.project_id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
if (await this.checkAuth(project._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}

View File

@ -175,7 +175,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目成员已存在');
}
params.role = params.role === 'owner' ? 'owner' : 'dev';
params.role = ['owner', 'dev', 'guest'].find(v => v === params.role) || 'dev';
let userdata = await this.getUserdata(params.member_uid, params.role);
if (userdata === null) {
@ -309,7 +309,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
}
if (result.project_type === 'private') {
if (await this.checkAuth(result._id, 'project', 'edit') !== true) {
if (await this.checkAuth(result._id, 'project', 'view') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
@ -342,7 +342,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
let auth = await this.checkAuth(group_id, 'group', 'edit')
let auth = await this.checkAuth(group_id, 'group', 'view')
try {
let result = await this.Model.list(group_id);
let follow = await this.followModel.list(this.getUid());
@ -358,6 +358,7 @@ class projectController extends baseController {
let f = _.find(follow, (fol) => {
return fol.projectid === item._id
})
// 排序:收藏的项目放前面
if (f) {
item.follow = true;
project_list.unshift(item);
@ -440,7 +441,7 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
params.role = params.role === 'owner' ? 'owner' : 'dev';
params.role = ['owner', 'dev', 'guest'].find(v => v === params.role) || 'dev';
try {
let result = await projectInst.changeMemberRole(params.id, params.member_uid, params.role);