修改用户相关api

This commit is contained in:
shiziyuan9527 2020-03-06 17:10:23 +08:00
parent 4274e8d81c
commit 1bd8bcd562
9 changed files with 133 additions and 84 deletions

View File

@ -2,7 +2,6 @@ package io.metersphere.controller;
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;
@ -12,9 +11,7 @@ import io.metersphere.controller.request.member.AddMemberRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.controller.request.organization.AddOrgMemberRequest;
import io.metersphere.controller.request.organization.QueryOrgMemberRequest;
import io.metersphere.dto.OrganizationMemberDTO;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.service.UserService;
import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils;
@ -32,39 +29,89 @@ public class UserController {
@Resource
private UserService userService;
@PostMapping("/add")
// admin api
@PostMapping("/special/add")
@RequiresRoles(RoleConstants.ADMIN)
public UserDTO insertUser(@RequestBody User user) {
return userService.insert(user);
}
@GetMapping("/list")
public List<User> getUserList() {
return userService.getUserList();
}
@PostMapping("/list/{goPage}/{pageSize}")
@PostMapping("/special/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.ADMIN)
public Pager<List<User>> getUserList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody UserRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request));
}
@GetMapping("/delete/{userId}")
@GetMapping("/special/delete/{userId}")
@RequiresRoles(RoleConstants.ADMIN)
public void deleteUser(@PathVariable(value = "userId") String userId) {
userService.deleteUser(userId);
}
@PostMapping("/update")
@PostMapping("/special/update")
@RequiresRoles(RoleConstants.ADMIN)
public void updateUser(@RequestBody User user) {
userService.updateUser(user);
}
/**
* 修改登录用户信息
*/
@PostMapping("/special/ws/member/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.ADMIN)
public Pager<List<User>> getMemberListByAdmin(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getMemberList(request));
}
@PostMapping("/special/ws/member/list/all")
@RequiresRoles(RoleConstants.ADMIN)
public List<User> getMemberListByAdmin(@RequestBody QueryMemberRequest request) {
return userService.getMemberList(request);
}
@PostMapping("/special/ws/member/add")
@RequiresRoles(RoleConstants.ADMIN)
public void addMemberByAdmin(@RequestBody AddMemberRequest request) {
userService.addMember(request);
}
@GetMapping("/special/ws/member/delete/{workspaceId}/{userId}")
@RequiresRoles(RoleConstants.ADMIN)
public void deleteMemberByAdmin(@PathVariable String workspaceId, @PathVariable String userId) {
userService.deleteMember(workspaceId, userId);
}
@PostMapping("/special/org/member/add")
@RequiresRoles(RoleConstants.ADMIN)
public void addOrganizationMemberByAdmin(@RequestBody AddOrgMemberRequest request) {
userService.addOrganizationMember(request);
}
@GetMapping("/special/org/member/delete/{organizationId}/{userId}")
@RequiresRoles(RoleConstants.ADMIN)
public void delOrganizationMemberByAdmin(@PathVariable String organizationId, @PathVariable String userId) {
userService.delOrganizationMember(organizationId, userId);
}
@PostMapping("/special/org/member/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.ADMIN)
public Pager<List<User>> getOrgMemberListByAdmin(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getOrgMemberList(request));
}
@PostMapping("/special/org/member/list/all")
@RequiresRoles(RoleConstants.ADMIN)
public List<User> getOrgMemberListByAdmin(@RequestBody QueryOrgMemberRequest request) {
return userService.getOrgMemberList(request);
}
// admin api
@GetMapping("/list")
@RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
public List<User> getUserList() {
return userService.getUserList();
}
@PostMapping("/update/currentuser")
public UserDTO updateCurrentUser(@RequestBody User user) {
SessionUser sessionUser = SessionUtils.getUser();
@ -73,20 +120,21 @@ public class UserController {
return SessionUtils.getUser();
}
@GetMapping("/role/list/{userId}")
public List<Role> getUserRolesList(@PathVariable(value = "userId") String userId) {
return userService.getUserRolesList(userId);
}
@GetMapping("/rolelist/{userId}")
public List<UserRoleDTO> convertUserRoleDTO(@PathVariable(value = "userId") String userId) {
return userService.getUserRoleList(userId);
}
@PostMapping("/switch/source/{sign}/{sourceId}")
public UserDTO switchUserRole(@PathVariable String sign, @PathVariable(value = "sourceId") String sourceId) {
@PostMapping("/switch/source/org/{sourceId}")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
// todo checkOrganizationOwner()
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, sign, sourceId);
userService.switchUserRole(user,"organization",sourceId);
return SessionUtils.getUser();
}
@PostMapping("/switch/source/ws/{sourceId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.TEST_VIEWER,RoleConstants.TEST_USER}, logical = Logical.OR)
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
// todo checkWorkspaceOwner()
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, "workspace", sourceId);
return SessionUtils.getUser();
}
@ -98,9 +146,11 @@ public class UserController {
/**
* 获取工作空间成员用户
*/
@PostMapping("/member/list/{goPage}/{pageSize}")
//@RequiresRoles(RoleConstants.TEST_MANAGER)
@PostMapping("/ws/member/list/{goPage}/{pageSize}")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
// todo 检查是否是该工作空间的所有者 或者是 该工作空间的父级组织的所有者
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getMemberList(request));
}
@ -108,52 +158,62 @@ public class UserController {
/**
* 获取工作空间成员用户 不分页
*/
@PostMapping("/member/list/all")
@PostMapping("/ws/member/list/all")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<User> getMemberList(@RequestBody QueryMemberRequest request) {
// todo 检查是否是该工作空间的所有者 或者是 该工作空间的父级组织的所有者
return userService.getMemberList(request);
}
/**
* 添加成员
* 添加工作空间成员
*/
@PostMapping("/member/add")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN,RoleConstants.ADMIN}, logical = Logical.OR)
@PostMapping("/ws/member/add")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
public void addMember(@RequestBody AddMemberRequest request) {
// todo check
userService.addMember(request);
}
/**
* 删除成员
* 删除工作空间成员
*/
@GetMapping("/member/delete/{workspaceId}/{userId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
@GetMapping("/ws/member/delete/{workspaceId}/{userId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
// todo check
userService.deleteMember(workspaceId, userId);
}
/**
* 添加组织成员
*/
@PostMapping("/orgmember/add")
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
@PostMapping("/org/member/add")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void addOrganizationMember(@RequestBody AddOrgMemberRequest request) {
// todo check
userService.addOrganizationMember(request);
}
/**
* 删除组织成员
*/
@GetMapping("/orgmember/delete/{organizationId}/{userId}")
@RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
@GetMapping("/org/member/delete/{organizationId}/{userId}")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void delOrganizationMember(@PathVariable String organizationId, @PathVariable String userId) {
// todo check
userService.delOrganizationMember(organizationId, userId);
}
/**
* 查询组织成员列表
*/
@PostMapping("/orgmember/list/{goPage}/{pageSize}")
@PostMapping("/org/member/list/{goPage}/{pageSize}")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public Pager<List<User>> getOrgMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
// todo check
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getOrgMemberList(request));
}
@ -161,23 +221,14 @@ public class UserController {
/**
* 组织成员列表不分页
*/
@PostMapping("/orgmember/list/all")
@PostMapping("/org/member/list/all")
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<User> getOrgMemberList(@RequestBody QueryOrgMemberRequest request) {
// todo check
return userService.getOrgMemberList(request);
}
/**
* 查询组织成员列表 带角色信息
*/
@PostMapping("/orgmemberdto/list/{goPage}/{pageSize}")
public Pager<List<OrganizationMemberDTO>> getOrganizationMemberDTO(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getOrganizationMemberDTO(request));
}
/**
*
*/
@GetMapping("/besideorg/list/{orgId}")
public List<User> getBesideOrgMemberList(@PathVariable String orgId) {
return userService.getBesideOrgMemberList(orgId);

View File

@ -128,7 +128,7 @@ public class UserService {
userMapper.updateByPrimaryKeySelective(user);
}
public List<Role> getUserRolesList(String userId) {
/*public List<Role> getUserRolesList(String userId) {
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRolesList = userRoleMapper.selectByExample(userRoleExample);
@ -143,7 +143,7 @@ public class UserService {
return new ArrayList<>();
}
return convertUserRoleDTO(extUserRoleMapper.getUserRoleHelpList(userId));
}
}*/
private List<UserRoleDTO> convertUserRoleDTO(List<UserRoleHelpDTO> helpDTOList) {
StringBuilder buffer = new StringBuilder();

View File

@ -126,19 +126,17 @@
},
changeOrg(data) {
let orgId = data.id;
let sign = "organization";
this.$post("/user/switch/source/" + sign + "/" + orgId, {}, response => {
this.$post("/user/switch/source/org/" + orgId, {}, response => {
localStorage.setItem(TokenKey, JSON.stringify(response.data));
window.location.reload();
})
},
changeWs(data) {
let sign = "workspace";
let workspaceId = data.id;
if (!workspaceId) {
return false;
}
this.$post("/user/switch/source/" + sign + "/" + workspaceId, {}, response => {
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
localStorage.setItem(TokenKey, JSON.stringify(response.data));
window.location.reload();
})

View File

@ -129,7 +129,7 @@
createVisible: false,
updateVisible: false,
form: {},
queryPath: "/user/orgmember/list",
queryPath: "/user/org/member/list",
condition: "",
tableData: [],
rules: {
@ -221,7 +221,7 @@
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/orgmember/delete/' + this.currentUser().lastOrganizationId + '/' + row.id, () => {
this.result = this.$get('/user/org/member/delete/' + this.currentUser().lastOrganizationId + '/' + row.id, () => {
this.$message({
type: 'success',
message: this.$t('commons.delete_success')
@ -262,7 +262,7 @@
roleIds: this.form.roleIds,
organizationId: orgId
};
this.result = this.$post("user/orgmember/add", param,() => {
this.result = this.$post("user/org/member/add", param,() => {
this.initTableData();
this.createVisible = false;
})

View File

@ -256,7 +256,7 @@
name: '',
workspaceId: this.items[i].id
}
let path = "user/member/list/all";
let path = "user/ws/member/list/all";
this.$post(path, param, res => {
let member = res.data;
this.$set(this.items[i], "memberSize", member.length);
@ -297,7 +297,7 @@
name: '',
workspaceId: row.id
};
let path = "/user/member/list";
let path = "/user/ws/member/list";
this.result = this.$post(this.buildPagePath(path), param, res => {
let data = res.data;
this.memberLineData = data.listObject;
@ -335,7 +335,7 @@
roleIds: this.memberForm.roleIds,
workspaceId: this.currentWorkspaceRow.id
};
this.result = this.$post("user/member/add", param,() => {
this.result = this.$post("user/ws/member/add", param,() => {
this.cellClick(this.currentWorkspaceRow);
this.addMemberVisible = false;
})
@ -360,7 +360,7 @@
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
this.result = this.$get('/user/ws/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
this.$message({
type: 'success',
message: this.$t('commons.delete_success')

View File

@ -290,7 +290,7 @@
name: '',
organizationId: row.id
};
let path = "/user/orgmember/list";
let path = "/user/special/org/member/list";
this.result = this.$post(this.buildPagePath(path), param, res => {
let data = res.data;
this.memberLineData = data.listObject;
@ -330,7 +330,7 @@
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/orgmember/delete/' + this.currentRow.id + '/' + row.id, () => {
this.result = this.$get('/user/special/org/member/delete/' + this.currentRow.id + '/' + row.id, () => {
this.$message({
type: 'success',
message: this.$t('commons.delete_success')
@ -385,7 +385,7 @@
name: '',
organizationId: this.tableData[i].id
}
let path = "user/orgmember/list/all";
let path = "user/special/org/member/list/all";
this.$post(path, param, res => {
let member = res.data;
this.$set(this.tableData[i], "memberSize", member.length);
@ -431,7 +431,7 @@
roleIds: this.memberForm.roleIds,
organizationId: this.currentRow.id
};
this.result = this.$post("user/orgmember/add", param,() => {
this.result = this.$post("user/special/org/member/add", param,() => {
this.cellClick(this.currentRow);
this.addMemberVisible = false;
})

View File

@ -270,7 +270,7 @@
name: '',
workspaceId: row.id
};
let path = "/user/member/list";
let path = "/user/special/ws/member/list";
this.result = this.$post(this.buildPagePath(path), param, res => {
let data = res.data;
this.memberLineData = data.listObject;
@ -340,7 +340,7 @@
name: '',
workspaceId: this.items[i].id
}
let path = "user/member/list/all";
let path = "user/special/ws/member/list/all";
this.$post(path, param, res => {
let member = res.data;
this.$set(this.items[i], "memberSize", member.length);
@ -376,7 +376,7 @@
roleIds: this.memberForm.roleIds,
workspaceId: this.currentWorkspaceRow.id
};
this.result = this.$post("user/member/add", param,() => {
this.result = this.$post("user/special/ws/member/add", param,() => {
this.cellClick(this.currentWorkspaceRow);
this.addMemberVisible = false;
})
@ -401,7 +401,7 @@
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
this.result = this.$get('/user/special/ws/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
this.$message({
type: 'success',
message: this.$t('commons.delete_success')

View File

@ -113,10 +113,10 @@
export default {
data() {
return {
queryPath: '/user/list',
deletePath: '/user/delete/',
createPath: '/user/add',
updatePath: '/user/update',
queryPath: '/user/special/list',
deletePath: '/user/special/delete/',
createPath: '/user/special/add',
updatePath: '/user/special/update',
result: {},
createVisible: false,
updateVisible: false,

View File

@ -126,7 +126,7 @@
btnTips: "添加工作空间成员",
createVisible: false,
updateVisible: false,
queryPath: "/user/member/list",
queryPath: "/user/ws/member/list",
condition: "",
tableData: [],
rules: {
@ -198,7 +198,7 @@
type: 'warning'
}).then(() => {
this.loading = true;
this.$get('/user/member/delete/' + this.currentUser().lastWorkspaceId + '/' + row.id).then(() => {
this.$get('/user/ws/member/delete/' + this.currentUser().lastWorkspaceId + '/' + row.id).then(() => {
this.initTableData();
this.loading = false;
});
@ -256,7 +256,7 @@
});
return false;
}
this.$post('/user/orgmember/list/all', param,response => {
this.$post('/user/org/member/list/all', param,response => {
this.createVisible = true;
this.$set(this.form, "userList", response.data);
})
@ -272,7 +272,7 @@
roleIds: this.form.roleIds,
workspaceId: this.currentUser().lastWorkspaceId
};
this.result = this.$post("user/member/add", param, () => {
this.result = this.$post("user/ws/member/add", param, () => {
this.initTableData();
this.createVisible = false;
})