成员管理后端接口 加上角色验证

This commit is contained in:
W23123 2020-02-18 11:34:33 +08:00
parent a086e80574
commit f668fd6891
5 changed files with 15 additions and 15 deletions

View File

@ -1,14 +1,9 @@
package io.metersphere.commons.constants;
public enum RoleConstants {
ADMIN("admin"), ORGADMIN("org_admin"), TESTUSER("test_user"), TESTVIEWER("test_viewer"), TESTMANAGER("test_manager");
private String value;
RoleConstants(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public class RoleConstants {
public final static String ADMIN = "admin";
public final static String ORG_ADMIN = "org_admin";
public final static String TEST_VIEWER = "test_viewer";
public final static String TEST_MANAGER = "test_manager";
public final static String TEST_USER = "test_user";
}

View File

@ -4,6 +4,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.Role;
import io.metersphere.base.domain.User;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.member.AddMemberRequest;
@ -12,6 +13,7 @@ import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.service.UserService;
import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -69,6 +71,7 @@ public class UserController {
* 获取成员用户
*/
@PostMapping("/member/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.TEST_MANAGER)
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getMemberList(request));
@ -78,6 +81,7 @@ public class UserController {
* 添加成员
*/
@PostMapping("/member/add")
@RequiresRoles(RoleConstants.TEST_MANAGER)
public void addMember(@RequestBody AddMemberRequest request) {
userService.addMember(request);
}
@ -86,6 +90,7 @@ public class UserController {
* 删除成员
*/
@GetMapping("/member/delete/{workspaceId}/{userId}")
@RequiresRoles(RoleConstants.TEST_MANAGER)
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
userService.deleteMember(workspaceId, userId);
}

View File

@ -4,7 +4,7 @@ import io.metersphere.commons.constants.RoleConstants;
public class QueryMemberRequest {
private String workspaceId;
private String roleId = RoleConstants.TESTMANAGER.getValue();
private String roleId = RoleConstants.TEST_MANAGER;
public String getWorkspaceId() {
return workspaceId;

View File

@ -235,7 +235,7 @@ public class UserService {
if (!CollectionUtils.isEmpty(request.getUserIds())) {
for (String userId : request.getUserIds()) {
UserRole userRole = new UserRole();
userRole.setRoleId(RoleConstants.TESTMANAGER.getValue());
userRole.setRoleId(RoleConstants.TEST_MANAGER);
userRole.setSourceId(request.getWorkspaceId());
userRole.setUserId(userId);
userRole.setId(UUID.randomUUID().toString());
@ -248,7 +248,7 @@ public class UserService {
public void deleteMember(String workspaceId, String userId) {
UserRoleExample example = new UserRoleExample();
example.createCriteria().andRoleIdEqualTo(RoleConstants.TESTMANAGER.getValue())
example.createCriteria().andRoleIdEqualTo(RoleConstants.TEST_MANAGER)
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
userRoleMapper.deleteByExample(example);
}

View File

@ -3,7 +3,7 @@
<el-card>
<div slot="header">
<el-row type="flex" justify="space-between" align="middle">
<span class="title">工作空间</span>
<span class="title">成员</span>
<span class="search">
<el-input type="text" size="small" placeholder="根据名称搜索" prefix-icon="el-icon-search"
maxlength="60" v-model="condition" clearable/>