成员管理后端接口 加上角色验证
This commit is contained in:
parent
a086e80574
commit
f668fd6891
|
@ -1,14 +1,9 @@
|
||||||
package io.metersphere.commons.constants;
|
package io.metersphere.commons.constants;
|
||||||
|
|
||||||
public enum RoleConstants {
|
public class RoleConstants {
|
||||||
ADMIN("admin"), ORGADMIN("org_admin"), TESTUSER("test_user"), TESTVIEWER("test_viewer"), TESTMANAGER("test_manager");
|
public final static String ADMIN = "admin";
|
||||||
private String value;
|
public final static String ORG_ADMIN = "org_admin";
|
||||||
|
public final static String TEST_VIEWER = "test_viewer";
|
||||||
RoleConstants(String value) {
|
public final static String TEST_MANAGER = "test_manager";
|
||||||
this.value = value;
|
public final static String TEST_USER = "test_user";
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.base.domain.Role;
|
import io.metersphere.base.domain.Role;
|
||||||
import io.metersphere.base.domain.User;
|
import io.metersphere.base.domain.User;
|
||||||
|
import io.metersphere.commons.constants.RoleConstants;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.controller.request.member.AddMemberRequest;
|
import io.metersphere.controller.request.member.AddMemberRequest;
|
||||||
|
@ -12,6 +13,7 @@ import io.metersphere.dto.UserDTO;
|
||||||
import io.metersphere.dto.UserRoleDTO;
|
import io.metersphere.dto.UserRoleDTO;
|
||||||
import io.metersphere.service.UserService;
|
import io.metersphere.service.UserService;
|
||||||
import io.metersphere.user.SessionUtils;
|
import io.metersphere.user.SessionUtils;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -69,6 +71,7 @@ public class UserController {
|
||||||
* 获取成员用户
|
* 获取成员用户
|
||||||
*/
|
*/
|
||||||
@PostMapping("/member/list/{goPage}/{pageSize}")
|
@PostMapping("/member/list/{goPage}/{pageSize}")
|
||||||
|
@RequiresRoles(RoleConstants.TEST_MANAGER)
|
||||||
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
||||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
||||||
|
@ -78,6 +81,7 @@ public class UserController {
|
||||||
* 添加成员
|
* 添加成员
|
||||||
*/
|
*/
|
||||||
@PostMapping("/member/add")
|
@PostMapping("/member/add")
|
||||||
|
@RequiresRoles(RoleConstants.TEST_MANAGER)
|
||||||
public void addMember(@RequestBody AddMemberRequest request) {
|
public void addMember(@RequestBody AddMemberRequest request) {
|
||||||
userService.addMember(request);
|
userService.addMember(request);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +90,7 @@ public class UserController {
|
||||||
* 删除成员
|
* 删除成员
|
||||||
*/
|
*/
|
||||||
@GetMapping("/member/delete/{workspaceId}/{userId}")
|
@GetMapping("/member/delete/{workspaceId}/{userId}")
|
||||||
|
@RequiresRoles(RoleConstants.TEST_MANAGER)
|
||||||
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
|
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||||
userService.deleteMember(workspaceId, userId);
|
userService.deleteMember(workspaceId, userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import io.metersphere.commons.constants.RoleConstants;
|
||||||
|
|
||||||
public class QueryMemberRequest {
|
public class QueryMemberRequest {
|
||||||
private String workspaceId;
|
private String workspaceId;
|
||||||
private String roleId = RoleConstants.TESTMANAGER.getValue();
|
private String roleId = RoleConstants.TEST_MANAGER;
|
||||||
|
|
||||||
public String getWorkspaceId() {
|
public String getWorkspaceId() {
|
||||||
return workspaceId;
|
return workspaceId;
|
||||||
|
|
|
@ -235,7 +235,7 @@ public class UserService {
|
||||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||||
for (String userId : request.getUserIds()) {
|
for (String userId : request.getUserIds()) {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleId(RoleConstants.TESTMANAGER.getValue());
|
userRole.setRoleId(RoleConstants.TEST_MANAGER);
|
||||||
userRole.setSourceId(request.getWorkspaceId());
|
userRole.setSourceId(request.getWorkspaceId());
|
||||||
userRole.setUserId(userId);
|
userRole.setUserId(userId);
|
||||||
userRole.setId(UUID.randomUUID().toString());
|
userRole.setId(UUID.randomUUID().toString());
|
||||||
|
@ -248,7 +248,7 @@ public class UserService {
|
||||||
|
|
||||||
public void deleteMember(String workspaceId, String userId) {
|
public void deleteMember(String workspaceId, String userId) {
|
||||||
UserRoleExample example = new UserRoleExample();
|
UserRoleExample example = new UserRoleExample();
|
||||||
example.createCriteria().andRoleIdEqualTo(RoleConstants.TESTMANAGER.getValue())
|
example.createCriteria().andRoleIdEqualTo(RoleConstants.TEST_MANAGER)
|
||||||
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
|
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
|
||||||
userRoleMapper.deleteByExample(example);
|
userRoleMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<el-card>
|
<el-card>
|
||||||
<div slot="header">
|
<div slot="header">
|
||||||
<el-row type="flex" justify="space-between" align="middle">
|
<el-row type="flex" justify="space-between" align="middle">
|
||||||
<span class="title">工作空间</span>
|
<span class="title">成员</span>
|
||||||
<span class="search">
|
<span class="search">
|
||||||
<el-input type="text" size="small" placeholder="根据名称搜索" prefix-icon="el-icon-search"
|
<el-input type="text" size="small" placeholder="根据名称搜索" prefix-icon="el-icon-search"
|
||||||
maxlength="60" v-model="condition" clearable/>
|
maxlength="60" v-model="condition" clearable/>
|
||||||
|
|
Loading…
Reference in New Issue