feat(系统设置): 用户管理批量操作增加添加到组织和项目的功能
This commit is contained in:
parent
50f3be9e52
commit
5d5c5bf84f
|
@ -11,7 +11,7 @@ import io.metersphere.sdk.util.PageUtils;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.sdk.util.SessionUtils;
|
import io.metersphere.sdk.util.SessionUtils;
|
||||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
||||||
import io.metersphere.system.service.GlobalUserRoleRelationLogService;
|
import io.metersphere.system.service.GlobalUserRoleRelationLogService;
|
||||||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
|
|
|
@ -3,30 +3,27 @@ package io.metersphere.system.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import io.metersphere.project.domain.Project;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.sdk.constants.UserSourceEnum;
|
import io.metersphere.sdk.constants.UserSourceEnum;
|
||||||
import io.metersphere.sdk.dto.BasePageRequest;
|
import io.metersphere.sdk.dto.BasePageRequest;
|
||||||
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
import io.metersphere.sdk.dto.UserDTO;
|
import io.metersphere.sdk.dto.UserDTO;
|
||||||
import io.metersphere.sdk.log.annotation.Log;
|
import io.metersphere.sdk.log.annotation.Log;
|
||||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
import io.metersphere.sdk.util.PageUtils;
|
import io.metersphere.sdk.util.PageUtils;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.sdk.util.SessionUtils;
|
import io.metersphere.sdk.util.SessionUtils;
|
||||||
|
import io.metersphere.system.domain.Organization;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
import io.metersphere.system.dto.UserBatchCreateDTO;
|
import io.metersphere.system.dto.UserBatchCreateDTO;
|
||||||
import io.metersphere.system.dto.UserExtend;
|
import io.metersphere.system.dto.UserExtend;
|
||||||
import io.metersphere.system.dto.UserRoleOption;
|
import io.metersphere.system.request.OrganizationMemberBatchRequest;
|
||||||
import io.metersphere.system.dto.request.UserBaseBatchRequest;
|
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
|
||||||
import io.metersphere.system.dto.request.UserChangeEnableRequest;
|
import io.metersphere.system.request.user.*;
|
||||||
import io.metersphere.system.dto.request.UserEditRequest;
|
import io.metersphere.system.response.user.*;
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
import io.metersphere.system.service.*;
|
||||||
import io.metersphere.system.dto.response.UserBatchProcessResponse;
|
import io.metersphere.system.utils.TreeNodeParseUtils;
|
||||||
import io.metersphere.system.dto.response.UserImportResponse;
|
|
||||||
import io.metersphere.system.dto.response.UserTableResponse;
|
|
||||||
import io.metersphere.system.service.GlobalUserRoleRelationLogService;
|
|
||||||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
|
||||||
import io.metersphere.system.service.GlobalUserRoleService;
|
|
||||||
import io.metersphere.system.service.UserService;
|
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
@ -41,6 +38,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/user")
|
@RequestMapping("/system/user")
|
||||||
|
@ -51,6 +49,10 @@ public class UserController {
|
||||||
private GlobalUserRoleService globalUserRoleService;
|
private GlobalUserRoleService globalUserRoleService;
|
||||||
@Resource
|
@Resource
|
||||||
private GlobalUserRoleRelationService globalUserRoleRelationService;
|
private GlobalUserRoleRelationService globalUserRoleRelationService;
|
||||||
|
@Resource
|
||||||
|
private OrganizationService organizationService;
|
||||||
|
@Resource
|
||||||
|
private SystemProjectService systemProjectService;
|
||||||
|
|
||||||
@GetMapping("/get/{email}")
|
@GetMapping("/get/{email}")
|
||||||
@Operation(summary = "通过email查找用户")
|
@Operation(summary = "通过email查找用户")
|
||||||
|
@ -59,13 +61,6 @@ public class UserController {
|
||||||
return userService.getUserDTOByEmail(email);
|
return userService.getUserDTOByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/global/system/role")
|
|
||||||
@Operation(summary = "查找系统级用户权限")
|
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
|
||||||
public List<UserRoleOption> getGlobalSystemRole() {
|
|
||||||
return globalUserRoleService.getGlobalSystemRoleList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@Operation(summary = "添加用户")
|
@Operation(summary = "添加用户")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_ADD)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_ADD)
|
||||||
|
@ -94,7 +89,7 @@ public class UserController {
|
||||||
@Operation(summary = "启用/禁用用户")
|
@Operation(summary = "启用/禁用用户")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateLog(#request)", msClass = UserService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateLog(#request)", msClass = UserService.class)
|
||||||
public UserBatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) {
|
public BatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) {
|
||||||
return userService.updateUserEnable(request, SessionUtils.getSessionId());
|
return userService.updateUserEnable(request, SessionUtils.getSessionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +104,7 @@ public class UserController {
|
||||||
@Operation(summary = "删除用户")
|
@Operation(summary = "删除用户")
|
||||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#request)", msClass = UserService.class)
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#request)", msClass = UserService.class)
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_DELETE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_DELETE)
|
||||||
public UserBatchProcessResponse deleteUser(@Validated @RequestBody UserBaseBatchRequest request) {
|
public BatchProcessResponse deleteUser(@Validated @RequestBody UserBaseBatchRequest request) {
|
||||||
return userService.deleteUser(request, SessionUtils.getUserId());
|
return userService.deleteUser(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +119,7 @@ public class UserController {
|
||||||
@Operation(summary = "重置用户密码")
|
@Operation(summary = "重置用户密码")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.resetPasswordLog(#request)", msClass = UserService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.resetPasswordLog(#request)", msClass = UserService.class)
|
||||||
public UserBatchProcessResponse resetPassword(@Validated @RequestBody UserBaseBatchRequest request) {
|
public BatchProcessResponse resetPassword(@Validated @RequestBody UserBaseBatchRequest request) {
|
||||||
return userService.resetPassword(request, SessionUtils.getUserId());
|
return userService.resetPassword(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +135,52 @@ public class UserController {
|
||||||
@Operation(summary = "批量添加用户到多个用户组中")
|
@Operation(summary = "批量添加用户到多个用户组中")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
@Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
||||||
public UserBatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) {
|
public BatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) {
|
||||||
return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId());
|
return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/global/system/role")
|
||||||
|
@Operation(summary = "查找系统级用户权限")
|
||||||
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
||||||
|
public List<UserSelectOption> getGlobalSystemRole() {
|
||||||
|
return globalUserRoleService.getGlobalSystemRoleList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/organization")
|
||||||
|
@Operation(summary = "用户批量操作-查找组织")
|
||||||
|
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_ROLE_READ, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ}, logical = Logical.AND)
|
||||||
|
public List<OptionDTO> getOrganization() {
|
||||||
|
return organizationService.listAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/project")
|
||||||
|
@Operation(summary = "用户批量操作-查找项目")
|
||||||
|
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_ROLE_READ, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ}, logical = Logical.AND)
|
||||||
|
public List<UserTreeSelectOption> getProject() {
|
||||||
|
Map<Organization, List<Project>> orgProjectMap = organizationService.getOrgProjectMap();
|
||||||
|
return TreeNodeParseUtils.parseOrgProjectMap(orgProjectMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/add-project-member")
|
||||||
|
//todo 这里权限有更改 权限待定
|
||||||
|
@Operation(summary = "添加用户到项目")
|
||||||
|
// @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||||
|
public void addProjectMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
||||||
|
ProjectAddMemberBatchRequest request = new ProjectAddMemberBatchRequest();
|
||||||
|
request.setProjectIds(userRoleBatchRelationRequest.getRoleIds());
|
||||||
|
request.setUserIds(userRoleBatchRelationRequest.getUserIds());
|
||||||
|
systemProjectService.addProjectMember(request, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add-org-member")
|
||||||
|
@Operation(summary = "添加用户到组织")
|
||||||
|
//todo 这里权限有更改 权限待定
|
||||||
|
// @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||||
|
public void addMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
||||||
|
OrganizationMemberBatchRequest request = new OrganizationMemberBatchRequest();
|
||||||
|
request.setOrganizationIds(userRoleBatchRelationRequest.getRoleIds());
|
||||||
|
request.setMemberIds(userRoleBatchRelationRequest.getUserIds());
|
||||||
|
organizationService.addMemberBySystem(request, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package io.metersphere.system.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UserRoleOption {
|
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
private boolean selected = false;
|
|
||||||
private boolean closeable = true;
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package io.metersphere.system.dto.response;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UserBatchProcessResponse {
|
|
||||||
private long totalCount;
|
|
||||||
private long successCount;
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.metersphere.system.mapper;
|
package io.metersphere.system.mapper;
|
||||||
|
|
||||||
import io.metersphere.system.domain.UserRoleRelation;
|
|
||||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||||
|
import io.metersphere.system.domain.UserRoleRelation;
|
||||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -12,5 +12,5 @@ public interface ExtUserRoleRelationMapper {
|
||||||
|
|
||||||
List<UserRoleRelation> selectGlobalRoleByUserId(String userId);
|
List<UserRoleRelation> selectGlobalRoleByUserId(String userId);
|
||||||
|
|
||||||
List<UserRoleRelationUserDTO> listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request);
|
List<UserRoleRelationUserDTO> listGlobal(@Param("request") GlobalUserRoleRelationQueryRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package io.metersphere.system.request;
|
package io.metersphere.system.request;
|
||||||
|
|
||||||
|
import io.metersphere.validation.groups.Created;
|
||||||
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ -9,7 +12,8 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class ProjectAddMemberBatchRequest extends ProjectAddMemberRequest{
|
public class ProjectAddMemberBatchRequest extends ProjectAddMemberRequest{
|
||||||
@Schema(description = "项目ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "项目ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotBlank(message = "{project.id.not_blank}")
|
@Valid
|
||||||
private List<String> projectIds;
|
private List<
|
||||||
|
@NotBlank(message = "{project.id.not_blank}", groups = {Created.class, Updated.class})
|
||||||
|
String> projectIds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package io.metersphere.system.request;
|
package io.metersphere.system.request;
|
||||||
|
|
||||||
|
import io.metersphere.validation.groups.Created;
|
||||||
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -15,6 +18,8 @@ public class ProjectAddMemberRequest {
|
||||||
|
|
||||||
@Schema(description = "用户ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "用户ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotEmpty(message = "{user.ids.not_blank}")
|
@NotEmpty(message = "{user.ids.not_blank}")
|
||||||
private List<String> userIds;
|
@Valid
|
||||||
|
private List<
|
||||||
|
@NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class})
|
||||||
|
String> userIds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.dto.request.user;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -1,6 +1,5 @@
|
||||||
package io.metersphere.system.dto.request.user;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
import io.metersphere.system.dto.request.UserBaseBatchRequest;
|
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
@ -9,10 +8,12 @@ import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class UserAndRoleBatchRequest extends UserBaseBatchRequest {
|
public class UserAndRoleBatchRequest extends UserBaseBatchRequest {
|
||||||
|
|
||||||
@Schema(description = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
@ -1,6 +1,5 @@
|
||||||
package io.metersphere.system.dto.request;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
import io.metersphere.system.dto.request.user.BaseCondition;
|
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.dto.request;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.dto.request;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
import io.metersphere.system.dto.UserCreateInfo;
|
import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
|
@ -0,0 +1,24 @@
|
||||||
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserRoleBatchRelationRequest {
|
||||||
|
/**
|
||||||
|
* 权限ID集合
|
||||||
|
*/
|
||||||
|
@Schema(description = "权限ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{organization.id.not_blank}")
|
||||||
|
private List<String> roleIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成员ID集合
|
||||||
|
*/
|
||||||
|
@Schema(description = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{user.id.not_blank}")
|
||||||
|
private List<String> userIds;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package io.metersphere.system.response.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchProcessResponse {
|
||||||
|
@Schema(description = "全部数量")
|
||||||
|
private long totalCount;
|
||||||
|
@Schema(description = "成功数量")
|
||||||
|
private long successCount;
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.dto.response;
|
package io.metersphere.system.response.user;
|
||||||
|
|
||||||
import io.metersphere.sdk.dto.ExcelParseDTO;
|
import io.metersphere.sdk.dto.ExcelParseDTO;
|
||||||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
|
@ -0,0 +1,16 @@
|
||||||
|
package io.metersphere.system.response.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserSelectOption {
|
||||||
|
@Schema(description = "节点唯一ID")
|
||||||
|
private String id;
|
||||||
|
@Schema(description = "节点名称")
|
||||||
|
private String name;
|
||||||
|
@Schema(description = "是否选中")
|
||||||
|
private boolean selected = false;
|
||||||
|
@Schema(description = "是否允许关闭")
|
||||||
|
private boolean closeable = true;
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.dto.response;
|
package io.metersphere.system.response.user;
|
||||||
|
|
||||||
import io.metersphere.system.domain.Organization;
|
import io.metersphere.system.domain.Organization;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
|
@ -0,0 +1,18 @@
|
||||||
|
package io.metersphere.system.response.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserTreeSelectOption extends UserSelectOption {
|
||||||
|
@Schema(description = "父节点ID")
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
public UserTreeSelectOption(String id, String name, String parentId) {
|
||||||
|
this.setId(id);
|
||||||
|
this.setName(name);
|
||||||
|
this.setParentId(parentId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,9 +12,9 @@ import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.domain.UserRole;
|
import io.metersphere.system.domain.UserRole;
|
||||||
import io.metersphere.system.domain.UserRoleExample;
|
import io.metersphere.system.domain.UserRoleExample;
|
||||||
import io.metersphere.system.domain.UserRoleRelation;
|
import io.metersphere.system.domain.UserRoleRelation;
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
|
||||||
import io.metersphere.system.mapper.UserRoleMapper;
|
import io.metersphere.system.mapper.UserRoleMapper;
|
||||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||||
|
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ import io.metersphere.system.domain.UserRole;
|
||||||
import io.metersphere.system.domain.UserRoleRelation;
|
import io.metersphere.system.domain.UserRoleRelation;
|
||||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
|
||||||
import io.metersphere.system.dto.response.UserBatchProcessResponse;
|
|
||||||
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||||
|
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
||||||
|
import io.metersphere.system.response.user.BatchProcessResponse;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -85,7 +85,7 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
||||||
return userRoleRelationMapper.selectByExample(example);
|
return userRoleRelationMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserBatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserAndRoleBatchRequest request, String operator) {
|
public BatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserAndRoleBatchRequest request, String operator) {
|
||||||
//检查角色的合法性
|
//检查角色的合法性
|
||||||
this.checkGlobalSystemUserRoleLegality(request.getRoleIds());
|
this.checkGlobalSystemUserRoleLegality(request.getRoleIds());
|
||||||
//获取本次处理的用户
|
//获取本次处理的用户
|
||||||
|
@ -116,7 +116,7 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
||||||
if (CollectionUtils.isNotEmpty(saveList)) {
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
||||||
userRoleRelationMapper.batchInsert(saveList);
|
userRoleRelationMapper.batchInsert(saveList);
|
||||||
}
|
}
|
||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
BatchProcessResponse response = new BatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getUserIds().size());
|
||||||
response.setSuccessCount(saveList.size());
|
response.setSuccessCount(saveList.size());
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -7,9 +7,9 @@ import io.metersphere.sdk.service.BaseUserRoleService;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.UserRole;
|
import io.metersphere.system.domain.UserRole;
|
||||||
import io.metersphere.system.domain.UserRoleExample;
|
import io.metersphere.system.domain.UserRoleExample;
|
||||||
import io.metersphere.system.dto.UserRoleOption;
|
|
||||||
import io.metersphere.system.mapper.ExtUserRoleMapper;
|
import io.metersphere.system.mapper.ExtUserRoleMapper;
|
||||||
import io.metersphere.system.mapper.UserRoleMapper;
|
import io.metersphere.system.mapper.UserRoleMapper;
|
||||||
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
@ -109,12 +109,12 @@ public class GlobalUserRoleService extends BaseUserRoleService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserRoleOption> getGlobalSystemRoleList() {
|
public List<UserSelectOption> getGlobalSystemRoleList() {
|
||||||
UserRoleExample example = new UserRoleExample();
|
UserRoleExample example = new UserRoleExample();
|
||||||
example.createCriteria().andScopeIdEqualTo(GLOBAL_SCOPE).andTypeEqualTo(SYSTEM_TYPE);
|
example.createCriteria().andScopeIdEqualTo(GLOBAL_SCOPE).andTypeEqualTo(SYSTEM_TYPE);
|
||||||
List<UserRoleOption> returnList = new ArrayList<>();
|
List<UserSelectOption> returnList = new ArrayList<>();
|
||||||
userRoleMapper.selectByExample(example).forEach(userRole -> {
|
userRoleMapper.selectByExample(example).forEach(userRole -> {
|
||||||
UserRoleOption userRoleOption = new UserRoleOption();
|
UserSelectOption userRoleOption = new UserSelectOption();
|
||||||
userRoleOption.setId(userRole.getId());
|
userRoleOption.setId(userRole.getId());
|
||||||
userRoleOption.setName(userRole.getName());
|
userRoleOption.setName(userRole.getName());
|
||||||
userRoleOption.setSelected(StringUtils.equals(userRole.getId(), MEMBER.getValue()));
|
userRoleOption.setSelected(StringUtils.equals(userRole.getId(), MEMBER.getValue()));
|
||||||
|
|
|
@ -815,6 +815,29 @@ public class OrganizationService {
|
||||||
return extOrganizationMapper.getOptionsByIds(orgIds);
|
return extOrganizationMapper.getOptionsByIds(orgIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkedHashMap<Organization, List<Project>> getOrgProjectMap() {
|
||||||
|
ProjectExample projectExample = new ProjectExample();
|
||||||
|
projectExample.setOrderByClause("name asc");
|
||||||
|
List<Project> allProject = projectMapper.selectByExample(projectExample);
|
||||||
|
|
||||||
|
OrganizationExample orgExample = new OrganizationExample();
|
||||||
|
orgExample.createCriteria().andIdIn(allProject.stream().map(Project::getOrganizationId).distinct().collect(Collectors.toList()));
|
||||||
|
orgExample.setOrderByClause("name asc");
|
||||||
|
List<Organization> orgList = organizationMapper.selectByExample(orgExample);
|
||||||
|
|
||||||
|
LinkedHashMap<Organization, List<Project>> returnMap = new LinkedHashMap<>();
|
||||||
|
for (Organization org : orgList) {
|
||||||
|
List<Project> projectsInOrg = new ArrayList<>();
|
||||||
|
for (Project project : allProject) {
|
||||||
|
if (StringUtils.equals(project.getOrganizationId(), org.getId())) {
|
||||||
|
projectsInOrg.add(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allProject.remove(projectsInOrg);
|
||||||
|
returnMap.put(org, projectsInOrg);
|
||||||
|
}
|
||||||
|
return returnMap;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Long> getTotal(String organizationId) {
|
public Map<String, Long> getTotal(String organizationId) {
|
||||||
Map<String, Long> total = new HashMap<>();
|
Map<String, Long> total = new HashMap<>();
|
||||||
|
|
|
@ -94,7 +94,6 @@ public class SystemProjectService {
|
||||||
commonProjectService.deleteProject(projects);
|
commonProjectService.deleteProject(projects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
|
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
|
||||||
return extSystemProjectMapper.selectProjectOptions();
|
return extSystemProjectMapper.selectProjectOptions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
import io.metersphere.sdk.log.service.OperationLogService;
|
import io.metersphere.sdk.log.service.OperationLogService;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.domain.*;
|
import io.metersphere.system.domain.*;
|
||||||
import io.metersphere.system.dto.response.UserTableResponse;
|
|
||||||
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||||
import io.metersphere.system.mapper.OrganizationMapper;
|
import io.metersphere.system.mapper.OrganizationMapper;
|
||||||
import io.metersphere.system.mapper.UserRoleMapper;
|
import io.metersphere.system.mapper.UserRoleMapper;
|
||||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||||
|
import io.metersphere.system.response.user.UserTableResponse;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -162,7 +162,7 @@ public class UserRoleRelationService {
|
||||||
List<String> deleteRoleList = new ArrayList<>();
|
List<String> deleteRoleList = new ArrayList<>();
|
||||||
List<UserRoleRelation> saveList = new ArrayList<>();
|
List<UserRoleRelation> saveList = new ArrayList<>();
|
||||||
List<UserRoleRelation> userRoleRelationList = this.selectGlobalRoleByUserId(user.getId());
|
List<UserRoleRelation> userRoleRelationList = this.selectGlobalRoleByUserId(user.getId());
|
||||||
List<String> userSavedRoleIdList = userRoleRelationList.stream().map(UserRoleRelation::getRoleId).collect(Collectors.toList());
|
List<String> userSavedRoleIdList = userRoleRelationList.stream().map(UserRoleRelation::getRoleId).toList();
|
||||||
//获取要移除的权限
|
//获取要移除的权限
|
||||||
for (String userSavedRoleId : userSavedRoleIdList) {
|
for (String userSavedRoleId : userSavedRoleIdList) {
|
||||||
if (!roleList.contains(userSavedRoleId)) {
|
if (!roleList.contains(userSavedRoleId)) {
|
||||||
|
|
|
@ -20,14 +20,14 @@ import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.dto.UserExtend;
|
import io.metersphere.system.dto.UserExtend;
|
||||||
import io.metersphere.system.dto.excel.UserExcel;
|
import io.metersphere.system.dto.excel.UserExcel;
|
||||||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
||||||
import io.metersphere.system.dto.request.UserBaseBatchRequest;
|
|
||||||
import io.metersphere.system.dto.request.UserChangeEnableRequest;
|
|
||||||
import io.metersphere.system.dto.request.UserEditRequest;
|
|
||||||
import io.metersphere.system.dto.response.UserBatchProcessResponse;
|
|
||||||
import io.metersphere.system.dto.response.UserImportResponse;
|
|
||||||
import io.metersphere.system.dto.response.UserTableResponse;
|
|
||||||
import io.metersphere.system.mapper.ExtUserMapper;
|
import io.metersphere.system.mapper.ExtUserMapper;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
|
import io.metersphere.system.request.user.UserBaseBatchRequest;
|
||||||
|
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
||||||
|
import io.metersphere.system.request.user.UserEditRequest;
|
||||||
|
import io.metersphere.system.response.user.BatchProcessResponse;
|
||||||
|
import io.metersphere.system.response.user.UserImportResponse;
|
||||||
|
import io.metersphere.system.response.user.UserTableResponse;
|
||||||
import io.metersphere.system.utils.UserImportEventListener;
|
import io.metersphere.system.utils.UserImportEventListener;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
@ -197,10 +197,10 @@ public class UserService {
|
||||||
return userEditRequest;
|
return userEditRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserBatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) {
|
public BatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) {
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setUserIds(this.getBatchUserIds(request));
|
||||||
this.checkUserInDb(request.getUserIds());
|
this.checkUserInDb(request.getUserIds());
|
||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
BatchProcessResponse response = new BatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getUserIds().size());
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdIn(
|
userExample.createCriteria().andIdIn(
|
||||||
|
@ -282,7 +282,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UserBatchProcessResponse deleteUser(@Valid UserBaseBatchRequest request, String operator) {
|
public BatchProcessResponse deleteUser(@Valid UserBaseBatchRequest request, String operator) {
|
||||||
List<String> userIdList = this.getBatchUserIds(request);
|
List<String> userIdList = this.getBatchUserIds(request);
|
||||||
this.checkUserInDb(userIdList);
|
this.checkUserInDb(userIdList);
|
||||||
//检查是否含有Admin
|
//检查是否含有Admin
|
||||||
|
@ -290,7 +290,7 @@ public class UserService {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdIn(userIdList);
|
userExample.createCriteria().andIdIn(userIdList);
|
||||||
//更新删除标志位
|
//更新删除标志位
|
||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
BatchProcessResponse response = new BatchProcessResponse();
|
||||||
response.setTotalCount(userIdList.size());
|
response.setTotalCount(userIdList.size());
|
||||||
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
||||||
//删除用户角色关系
|
//删除用户角色关系
|
||||||
|
@ -422,7 +422,7 @@ public class UserService {
|
||||||
return extUserMapper.getMemberOption(sourceId);
|
return extUserMapper.getMemberOption(sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserBatchProcessResponse resetPassword(UserBaseBatchRequest request, String operator) {
|
public BatchProcessResponse resetPassword(UserBaseBatchRequest request, String operator) {
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setUserIds(this.getBatchUserIds(request));
|
||||||
this.checkUserInDb(request.getUserIds());
|
this.checkUserInDb(request.getUserIds());
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ public class UserService {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
|
||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
BatchProcessResponse response = new BatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getUserIds().size());
|
||||||
response.setSuccessCount(request.getUserIds().size());
|
response.setSuccessCount(request.getUserIds().size());
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package io.metersphere.system.utils;
|
||||||
|
|
||||||
|
import io.metersphere.project.domain.Project;
|
||||||
|
import io.metersphere.system.domain.Organization;
|
||||||
|
import io.metersphere.system.response.user.UserTreeSelectOption;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TreeNodeParseUtils {
|
||||||
|
public static List<UserTreeSelectOption> parseOrgProjectMap(Map<Organization, List<Project>> orgProjectMap) {
|
||||||
|
List<UserTreeSelectOption> userTreeSelectOptions = new ArrayList<>();
|
||||||
|
for (Map.Entry<Organization, List<Project>> entry : orgProjectMap.entrySet()) {
|
||||||
|
Organization organization = entry.getKey();
|
||||||
|
List<Project> projects = entry.getValue();
|
||||||
|
|
||||||
|
UserTreeSelectOption orgNode = new UserTreeSelectOption(organization.getId(), organization.getName(), null);
|
||||||
|
userTreeSelectOptions.add(orgNode);
|
||||||
|
|
||||||
|
for (Project project : projects) {
|
||||||
|
UserTreeSelectOption projectNode = new UserTreeSelectOption(project.getId(), project.getName(), organization.getId());
|
||||||
|
userTreeSelectOptions.add(projectNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return userTreeSelectOptions;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,10 @@ package io.metersphere.system.controller.user;
|
||||||
|
|
||||||
import com.jayway.jsonpath.JsonPath;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
import io.metersphere.system.dto.UserCreateInfo;
|
import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.dto.UserRoleOption;
|
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
||||||
import io.metersphere.system.dto.request.UserBaseBatchRequest;
|
import io.metersphere.system.request.user.UserBaseBatchRequest;
|
||||||
import io.metersphere.system.dto.request.UserChangeEnableRequest;
|
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
import io.metersphere.system.utils.user.UserParamUtils;
|
import io.metersphere.system.utils.user.UserParamUtils;
|
||||||
import io.metersphere.system.utils.user.UserRequestUtils;
|
import io.metersphere.system.utils.user.UserRequestUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -58,9 +58,9 @@ public class UserControllerNonePermissionTests {
|
||||||
setName("tianyang.no.permission.email");
|
setName("tianyang.no.permission.email");
|
||||||
setEmail("tianyang.no.permission.email@126.com");
|
setEmail("tianyang.no.permission.email@126.com");
|
||||||
}};
|
}};
|
||||||
List<UserRoleOption> paramRoleList = new ArrayList<>() {{
|
List<UserSelectOption> paramRoleList = new ArrayList<>() {{
|
||||||
this.add(
|
this.add(
|
||||||
new UserRoleOption() {{
|
new UserSelectOption() {{
|
||||||
this.setId("member");
|
this.setId("member");
|
||||||
this.setName("member");
|
this.setName("member");
|
||||||
}});
|
}});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package io.metersphere.system.controller.user;
|
package io.metersphere.system.controller.user;
|
||||||
|
|
||||||
|
import io.metersphere.project.domain.Project;
|
||||||
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
import io.metersphere.sdk.base.BaseTest;
|
import io.metersphere.sdk.base.BaseTest;
|
||||||
import io.metersphere.sdk.controller.handler.ResultHolder;
|
import io.metersphere.sdk.controller.handler.ResultHolder;
|
||||||
import io.metersphere.sdk.dto.BasePageRequest;
|
import io.metersphere.sdk.dto.BasePageRequest;
|
||||||
|
@ -12,18 +14,14 @@ import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Pager;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
import io.metersphere.system.domain.UserExample;
|
import io.metersphere.system.domain.UserExample;
|
||||||
|
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||||
import io.metersphere.system.dto.UserBatchCreateDTO;
|
import io.metersphere.system.dto.UserBatchCreateDTO;
|
||||||
import io.metersphere.system.dto.UserCreateInfo;
|
import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.dto.UserRoleOption;
|
|
||||||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
||||||
import io.metersphere.system.dto.request.UserBaseBatchRequest;
|
|
||||||
import io.metersphere.system.dto.request.UserChangeEnableRequest;
|
|
||||||
import io.metersphere.system.dto.request.UserEditRequest;
|
|
||||||
import io.metersphere.system.dto.request.user.UserAndRoleBatchRequest;
|
|
||||||
import io.metersphere.system.dto.response.UserBatchProcessResponse;
|
|
||||||
import io.metersphere.system.dto.response.UserImportResponse;
|
|
||||||
import io.metersphere.system.dto.response.UserTableResponse;
|
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
|
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||||
|
import io.metersphere.system.request.user.*;
|
||||||
|
import io.metersphere.system.response.user.*;
|
||||||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
||||||
import io.metersphere.system.service.UserService;
|
import io.metersphere.system.service.UserService;
|
||||||
import io.metersphere.system.utils.user.UserParamUtils;
|
import io.metersphere.system.utils.user.UserParamUtils;
|
||||||
|
@ -66,7 +64,9 @@ public class UserControllerTests extends BaseTest {
|
||||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||||
//测试过程中需要用到的数据
|
//测试过程中需要用到的数据
|
||||||
private static final List<UserCreateInfo> USER_LIST = new ArrayList<>();
|
private static final List<UserCreateInfo> USER_LIST = new ArrayList<>();
|
||||||
private static final List<UserRoleOption> USER_ROLE_LIST = new ArrayList<>();
|
private static final List<UserSelectOption> USER_ROLE_LIST = new ArrayList<>();
|
||||||
|
private static final List<UserSelectOption> ORG_LIST = new ArrayList<>();
|
||||||
|
private static final List<UserTreeSelectOption> PROJECT_LIST = new ArrayList<>();
|
||||||
//默认数据
|
//默认数据
|
||||||
public static final String USER_DEFAULT_NAME = "tianyang.no.1";
|
public static final String USER_DEFAULT_NAME = "tianyang.no.1";
|
||||||
public static final String USER_DEFAULT_EMAIL = "tianyang.no.1@126.com";
|
public static final String USER_DEFAULT_EMAIL = "tianyang.no.1@126.com";
|
||||||
|
@ -151,116 +151,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
this.addUser2List(mvcResult);
|
this.addUser2List(mvcResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public final String URL_GET_ORGANIZATION = "/system/user/get/organization";
|
||||||
@Order(1)
|
|
||||||
public void testAddError() throws Exception {
|
|
||||||
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
|
|
||||||
this.testGetGlobalSystemUserRoleSuccess();
|
|
||||||
}
|
|
||||||
UserBatchCreateDTO userMaintainRequest;
|
|
||||||
List<UserCreateInfo> errorUserList = new ArrayList<>() {{
|
|
||||||
add(new UserCreateInfo() {{
|
|
||||||
setName("tianyang.error.1");
|
|
||||||
setEmail("tianyang.error.name.1@126.com");
|
|
||||||
}});
|
|
||||||
add(new UserCreateInfo() {{
|
|
||||||
setName("tianyang.error.2");
|
|
||||||
setEmail("tianyang.error.name.2@126.com");
|
|
||||||
}});
|
|
||||||
}};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 校验参数不合法的反例
|
|
||||||
* 每一次校验,使用getErrorUserCreateDTO方法重新获取参数,避免上一步的参数干扰
|
|
||||||
*/
|
|
||||||
//所有参数都为空
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(null, null);
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//用户组ID为空
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
null,
|
|
||||||
errorUserList);
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//没有用户
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
null);
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//用户组含有null
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
errorUserList);
|
|
||||||
userMaintainRequest.getUserRoleIdList().add(null);
|
|
||||||
userMaintainRequest.getUserRoleIdList().add("");
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//含有用户名称为空的数据
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
new ArrayList<>()
|
|
||||||
);
|
|
||||||
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
||||||
setEmail("tianyang.name.empty@126.com");
|
|
||||||
}});
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//含有用户邮箱为空的数据
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
new ArrayList<>()
|
|
||||||
);
|
|
||||||
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
||||||
setName("tianyang.email.empty");
|
|
||||||
}});
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
//用户邮箱不符合标准
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
new ArrayList<>()
|
|
||||||
);
|
|
||||||
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
||||||
setName("用户邮箱放飞自我");
|
|
||||||
setEmail("用户邮箱放飞自我");
|
|
||||||
}});
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
||||||
/*
|
|
||||||
* 校验业务判断出错的反例 (500 error)
|
|
||||||
* 需要保证数据库有正常数据
|
|
||||||
*/
|
|
||||||
this.checkUserList();
|
|
||||||
//含有非法用户组
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
new ArrayList<>() {{
|
|
||||||
this.add(new UserRoleOption() {{
|
|
||||||
this.setId("not system global user role id");
|
|
||||||
}});
|
|
||||||
}},
|
|
||||||
errorUserList);
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
||||||
//含有重复的用户邮箱
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
errorUserList
|
|
||||||
);
|
|
||||||
String firstUserEmail = userMaintainRequest.getUserInfoList().get(0).getEmail();
|
|
||||||
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
||||||
setName("tianyang.no.error4");
|
|
||||||
setEmail(firstUserEmail);
|
|
||||||
}});
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
||||||
//测试请求参数中含有数据库中已存在的邮箱情况
|
|
||||||
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
||||||
USER_ROLE_LIST,
|
|
||||||
errorUserList
|
|
||||||
);
|
|
||||||
userMaintainRequest.setUserInfoList(
|
|
||||||
new ArrayList<>() {{
|
|
||||||
add(new UserCreateInfo() {{
|
|
||||||
setName("tianyang.repeat.email.db");
|
|
||||||
setEmail(USER_DEFAULT_EMAIL);
|
|
||||||
}});
|
|
||||||
}}
|
|
||||||
);
|
|
||||||
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
|
@ -579,6 +470,135 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String URL_GET_PROJECT = "/system/user/get/project";
|
||||||
|
public final String URL_ADD_PROJECT_MEMBER = "/system/user/add-project-member";
|
||||||
|
public final String URL_ADD_ORGANIZATION_MEMBER = "/system/user/add-org-member";
|
||||||
|
@Resource
|
||||||
|
ProjectMapper projectMapper;
|
||||||
|
@Resource
|
||||||
|
private UserRoleRelationMapper userRoleRelationMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(8)
|
||||||
|
public void testUserResetPasswordError() throws Exception {
|
||||||
|
//用户不存在
|
||||||
|
{
|
||||||
|
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
||||||
|
request.setUserIds(Collections.singletonList("none user"));
|
||||||
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void testAddError() throws Exception {
|
||||||
|
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
|
||||||
|
this.testGetGlobalSystemUserRoleSuccess();
|
||||||
|
}
|
||||||
|
UserBatchCreateDTO userMaintainRequest;
|
||||||
|
List<UserCreateInfo> errorUserList = new ArrayList<>() {{
|
||||||
|
add(new UserCreateInfo() {{
|
||||||
|
setName("tianyang.error.1");
|
||||||
|
setEmail("tianyang.error.name.1@126.com");
|
||||||
|
}});
|
||||||
|
add(new UserCreateInfo() {{
|
||||||
|
setName("tianyang.error.2");
|
||||||
|
setEmail("tianyang.error.name.2@126.com");
|
||||||
|
}});
|
||||||
|
}};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 校验参数不合法的反例
|
||||||
|
* 每一次校验,使用getErrorUserCreateDTO方法重新获取参数,避免上一步的参数干扰
|
||||||
|
*/
|
||||||
|
//所有参数都为空
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(null, null);
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//用户组ID为空
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
null,
|
||||||
|
errorUserList);
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//没有用户
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
null);
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//用户组含有null
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
errorUserList);
|
||||||
|
userMaintainRequest.getUserRoleIdList().add(null);
|
||||||
|
userMaintainRequest.getUserRoleIdList().add("");
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//含有用户名称为空的数据
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
new ArrayList<>()
|
||||||
|
);
|
||||||
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
||||||
|
setEmail("tianyang.name.empty@126.com");
|
||||||
|
}});
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//含有用户邮箱为空的数据
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
new ArrayList<>()
|
||||||
|
);
|
||||||
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
||||||
|
setName("tianyang.email.empty");
|
||||||
|
}});
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
//用户邮箱不符合标准
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
new ArrayList<>()
|
||||||
|
);
|
||||||
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
||||||
|
setName("用户邮箱放飞自我");
|
||||||
|
setEmail("用户邮箱放飞自我");
|
||||||
|
}});
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
||||||
|
/*
|
||||||
|
* 校验业务判断出错的反例 (500 error)
|
||||||
|
* 需要保证数据库有正常数据
|
||||||
|
*/
|
||||||
|
this.checkUserList();
|
||||||
|
//含有非法用户组
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
new ArrayList<>() {{
|
||||||
|
this.add(new UserSelectOption() {{
|
||||||
|
this.setId("not system global user role id");
|
||||||
|
}});
|
||||||
|
}},
|
||||||
|
errorUserList);
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
//含有重复的用户邮箱
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
errorUserList
|
||||||
|
);
|
||||||
|
String firstUserEmail = userMaintainRequest.getUserInfoList().get(0).getEmail();
|
||||||
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
||||||
|
setName("tianyang.no.error4");
|
||||||
|
setEmail(firstUserEmail);
|
||||||
|
}});
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
//测试请求参数中含有数据库中已存在的邮箱情况
|
||||||
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
||||||
|
USER_ROLE_LIST,
|
||||||
|
errorUserList
|
||||||
|
);
|
||||||
|
userMaintainRequest.setUserInfoList(
|
||||||
|
new ArrayList<>() {{
|
||||||
|
add(new UserCreateInfo() {{
|
||||||
|
setName("tianyang.repeat.email.db");
|
||||||
|
setEmail(USER_DEFAULT_EMAIL);
|
||||||
|
}});
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(8)
|
@Order(8)
|
||||||
|
@ -590,7 +610,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
request.setUserIds(Collections.singletonList("admin"));
|
request.setUserIds(Collections.singletonList("admin"));
|
||||||
userRequestUtils.parseObjectFromMvcResult(
|
userRequestUtils.parseObjectFromMvcResult(
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
UserBatchProcessResponse.class
|
BatchProcessResponse.class
|
||||||
);
|
);
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
|
@ -607,9 +627,9 @@ public class UserControllerTests extends BaseTest {
|
||||||
Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser));
|
Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser));
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
||||||
request.setUserIds(Collections.singletonList(userId));
|
request.setUserIds(Collections.singletonList(userId));
|
||||||
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
UserBatchProcessResponse.class
|
BatchProcessResponse.class
|
||||||
);
|
);
|
||||||
Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1);
|
Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1);
|
||||||
List<User> userList = userService.selectByIdList(Collections.singletonList(userId));
|
List<User> userList = userService.selectByIdList(Collections.singletonList(userId));
|
||||||
|
@ -625,9 +645,9 @@ public class UserControllerTests extends BaseTest {
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
||||||
request.setSkipIds(Collections.singletonList("admin"));
|
request.setSkipIds(Collections.singletonList("admin"));
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
UserBatchProcessResponse.class
|
BatchProcessResponse.class
|
||||||
);
|
);
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdNotEqualTo("admin");
|
example.createCriteria().andIdNotEqualTo("admin");
|
||||||
|
@ -646,17 +666,6 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(8)
|
|
||||||
public void testUserResetPasswordError() throws Exception {
|
|
||||||
//用户不存在
|
|
||||||
{
|
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
|
||||||
request.setUserIds(Collections.singletonList("none user"));
|
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(9)
|
@Order(9)
|
||||||
public void testUserRoleRelationSuccess() throws Exception {
|
public void testUserRoleRelationSuccess() throws Exception {
|
||||||
|
@ -668,7 +677,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
//测试添加角色权限。 预期数据:每个用户都会增加对应的权限
|
//测试添加角色权限。 预期数据:每个用户都会增加对应的权限
|
||||||
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
||||||
//检查有权限的数据量是否一致
|
//检查有权限的数据量是否一致
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
|
@ -676,7 +685,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
request.getUserIds().size() * request.getRoleIds().size()
|
request.getUserIds().size() * request.getRoleIds().size()
|
||||||
);
|
);
|
||||||
//检查日志
|
//检查日志
|
||||||
for (UserRoleOption option : USER_ROLE_LIST) {
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
this.checkLog(option.getId(), OperationLogType.ADD);
|
this.checkLog(option.getId(), OperationLogType.ADD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,7 +697,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
request.getUserIds().size() * request.getRoleIds().size()
|
request.getUserIds().size() * request.getRoleIds().size()
|
||||||
);
|
);
|
||||||
//检查日志
|
//检查日志
|
||||||
for (UserRoleOption option : USER_ROLE_LIST) {
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
this.checkLog(option.getId(), OperationLogType.ADD);
|
this.checkLog(option.getId(), OperationLogType.ADD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,7 +713,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
// 用户ID为空
|
// 用户ID为空
|
||||||
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
||||||
request.setUserIds(new ArrayList<>());
|
request.setUserIds(new ArrayList<>());
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, BAD_REQUEST_MATCHER);
|
||||||
// 角色id为空
|
// 角色id为空
|
||||||
request = new UserAndRoleBatchRequest();
|
request = new UserAndRoleBatchRequest();
|
||||||
|
@ -714,17 +723,171 @@ public class UserControllerTests extends BaseTest {
|
||||||
// 用户ID含有不存在的
|
// 用户ID含有不存在的
|
||||||
request = new UserAndRoleBatchRequest();
|
request = new UserAndRoleBatchRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
request.getUserIds().add("none user");
|
request.getUserIds().add("none user");
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
||||||
// 角色ID含有不存在的
|
// 角色ID含有不存在的
|
||||||
request = new UserAndRoleBatchRequest();
|
request = new UserAndRoleBatchRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
request.getRoleIds().add("none role");
|
request.getRoleIds().add("none role");
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(10)
|
||||||
|
@Sql(scripts = {"/dml/init_user_org_project.sql"},
|
||||||
|
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
||||||
|
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
||||||
|
public void testGetProjectAndOrganization() throws Exception {
|
||||||
|
String str = userRequestUtils.responseGet(userRequestUtils.URL_GET_PROJECT).getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
ResultHolder rh = JSON.parseObject(str, ResultHolder.class);
|
||||||
|
List<UserTreeSelectOption> userTreeSelectOptions = JSON.parseArray(
|
||||||
|
JSON.toJSONString(rh.getData()),
|
||||||
|
UserTreeSelectOption.class);
|
||||||
|
//返回值不为空
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(userTreeSelectOptions));
|
||||||
|
PROJECT_LIST.addAll(userTreeSelectOptions);
|
||||||
|
|
||||||
|
|
||||||
|
List<UserSelectOption> userSelectOptions = JSON.parseArray(
|
||||||
|
JSON.toJSONString(
|
||||||
|
JSON.parseObject(
|
||||||
|
userRequestUtils.responseGet(userRequestUtils.URL_GET_ORGANIZATION).getResponse().getContentAsString(StandardCharsets.UTF_8),
|
||||||
|
ResultHolder.class).getData()),
|
||||||
|
UserSelectOption.class);
|
||||||
|
ORG_LIST.addAll(userSelectOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(11)
|
||||||
|
public void testAddProjectMember() throws Exception {
|
||||||
|
//UserList中的部分角色是没有添加到某权限中的
|
||||||
|
if (CollectionUtils.isEmpty(USER_LIST)) {
|
||||||
|
this.testAddSuccess();
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(PROJECT_LIST) || CollectionUtils.isEmpty(ORG_LIST)) {
|
||||||
|
this.testGetProjectAndOrganization();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
|
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
request.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
//排除树结构中的组织ID
|
||||||
|
request.getRoleIds().removeAll(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
this.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, request);
|
||||||
|
//检查有权限的数据量是否一致
|
||||||
|
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
||||||
|
|
||||||
|
for (String projectId : request.getRoleIds()) {
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
|
String orgId = project.getOrganizationId();
|
||||||
|
for (String userId : request.getUserIds()) {
|
||||||
|
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(projectId);
|
||||||
|
//检查是否在对应的项目下
|
||||||
|
Assertions.assertEquals(
|
||||||
|
userRoleRelationMapper.countByExample(checkExample), 1
|
||||||
|
);
|
||||||
|
checkExample.clear();
|
||||||
|
//检查是否在对应的组织下
|
||||||
|
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(orgId);
|
||||||
|
Assertions.assertEquals(
|
||||||
|
userRoleRelationMapper.countByExample(checkExample), 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//检查日志
|
||||||
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
|
this.checkLog(option.getId(), OperationLogType.ADD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(13)
|
||||||
|
public void testAddOrganization() throws Exception {
|
||||||
|
//UserList中的部分角色是没有添加到某权限中的
|
||||||
|
if (CollectionUtils.isEmpty(USER_LIST)) {
|
||||||
|
this.testAddSuccess();
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(PROJECT_LIST) || CollectionUtils.isEmpty(ORG_LIST)) {
|
||||||
|
this.testGetProjectAndOrganization();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
|
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
this.requestPost(userRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request);
|
||||||
|
//检查有权限的数据量是否一致
|
||||||
|
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
||||||
|
for (String orgId : request.getRoleIds()) {
|
||||||
|
for (String userId : request.getUserIds()) {
|
||||||
|
checkExample.clear();
|
||||||
|
//检查是否在对应的组织下
|
||||||
|
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(orgId);
|
||||||
|
Assertions.assertEquals(
|
||||||
|
userRoleRelationMapper.countByExample(checkExample), 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//检查日志
|
||||||
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
|
this.checkLog(option.getId(), OperationLogType.ADD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(11)
|
||||||
|
public void testAddToOrgOrProjectError() throws Exception {
|
||||||
|
if (CollectionUtils.isEmpty(PROJECT_LIST) || CollectionUtils.isEmpty(ORG_LIST)) {
|
||||||
|
this.testGetProjectAndOrganization();
|
||||||
|
}
|
||||||
|
// 用户ID为空
|
||||||
|
UserRoleBatchRelationRequest addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
|
addToProjectRequest.setUserIds(new ArrayList<>());
|
||||||
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
||||||
|
// 项目为空
|
||||||
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
|
addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
addToProjectRequest.setRoleIds(new ArrayList<>());
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
||||||
|
// 用户ID含有不存在的
|
||||||
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
|
addToProjectRequest.setUserIds(Collections.singletonList("none user"));
|
||||||
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
// 项目ID含有不存在的
|
||||||
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
|
addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
addToProjectRequest.setRoleIds(Collections.singletonList("none role"));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
|
||||||
|
|
||||||
|
// 用户ID为空
|
||||||
|
UserRoleBatchRelationRequest orgRequest = new UserRoleBatchRelationRequest();
|
||||||
|
orgRequest.setUserIds(new ArrayList<>());
|
||||||
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
||||||
|
// 项目为空
|
||||||
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
|
orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
orgRequest.setRoleIds(new ArrayList<>());
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
||||||
|
// 用户ID含有不存在的
|
||||||
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
|
orgRequest.setUserIds(Collections.singletonList("none user"));
|
||||||
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
// 项目ID含有不存在的
|
||||||
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
|
orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
|
orgRequest.setRoleIds(Collections.singletonList("none role"));
|
||||||
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
//本测试类中会用到很多次用户数据。所以测试删除的方法放于最后
|
//本测试类中会用到很多次用户数据。所以测试删除的方法放于最后
|
||||||
@Test
|
@Test
|
||||||
@Order(99)
|
@Order(99)
|
||||||
|
@ -735,7 +898,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
UserCreateInfo deleteUser = USER_LIST.get(0);
|
UserCreateInfo deleteUser = USER_LIST.get(0);
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
||||||
request.setUserIds(Collections.singletonList(deleteUser.getId()));
|
request.setUserIds(Collections.singletonList(deleteUser.getId()));
|
||||||
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), UserBatchProcessResponse.class);
|
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), BatchProcessResponse.class);
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
||||||
//检查数据库
|
//检查数据库
|
||||||
|
@ -749,7 +912,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
||||||
request.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setSkipIds(Collections.singletonList("admin"));
|
request.setSkipIds(Collections.singletonList("admin"));
|
||||||
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), UserBatchProcessResponse.class);
|
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), BatchProcessResponse.class);
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount(), response.getSuccessCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount(), response.getSuccessCount());
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
|
@ -798,7 +961,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||||
//返回请求正常
|
//返回请求正常
|
||||||
Assertions.assertNotNull(resultHolder);
|
Assertions.assertNotNull(resultHolder);
|
||||||
List<UserRoleOption> userRoleList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), UserRoleOption.class);
|
List<UserSelectOption> userRoleList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), UserSelectOption.class);
|
||||||
//返回值不为空
|
//返回值不为空
|
||||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleList));
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleList));
|
||||||
USER_ROLE_LIST.addAll(userRoleList);
|
USER_ROLE_LIST.addAll(userRoleList);
|
||||||
|
|
|
@ -1,44 +1,40 @@
|
||||||
package io.metersphere.system.utils.user;
|
package io.metersphere.system.utils.user;
|
||||||
|
|
||||||
import io.metersphere.sdk.controller.handler.ResultHolder;
|
|
||||||
import io.metersphere.sdk.dto.BasePageRequest;
|
import io.metersphere.sdk.dto.BasePageRequest;
|
||||||
import io.metersphere.sdk.dto.UserDTO;
|
import io.metersphere.sdk.dto.UserDTO;
|
||||||
import io.metersphere.sdk.service.BaseUserRoleService;
|
import io.metersphere.sdk.service.BaseUserRoleService;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
|
||||||
import io.metersphere.system.domain.UserRole;
|
import io.metersphere.system.domain.UserRole;
|
||||||
import io.metersphere.system.dto.UserBatchCreateDTO;
|
import io.metersphere.system.dto.UserBatchCreateDTO;
|
||||||
import io.metersphere.system.dto.UserCreateInfo;
|
import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.dto.UserRoleOption;
|
import io.metersphere.system.request.user.UserEditRequest;
|
||||||
import io.metersphere.system.dto.request.UserEditRequest;
|
import io.metersphere.system.response.user.UserImportResponse;
|
||||||
import io.metersphere.system.dto.response.UserImportResponse;
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
import io.metersphere.system.service.GlobalUserRoleService;
|
import io.metersphere.system.service.GlobalUserRoleService;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UserParamUtils {
|
public class UserParamUtils {
|
||||||
|
|
||||||
public static UserBatchCreateDTO getUserCreateDTO(
|
public static UserBatchCreateDTO getUserCreateDTO(
|
||||||
List<UserRoleOption> userRoleList,
|
List<UserSelectOption> userRoleList,
|
||||||
List<UserCreateInfo> userInfoList) {
|
List<UserCreateInfo> userInfoList) {
|
||||||
UserBatchCreateDTO userMaintainRequest = new UserBatchCreateDTO();
|
UserBatchCreateDTO userMaintainRequest = new UserBatchCreateDTO();
|
||||||
if (CollectionUtils.isNotEmpty(userRoleList)) {
|
if (CollectionUtils.isNotEmpty(userRoleList)) {
|
||||||
userMaintainRequest.setUserRoleIdList(
|
userMaintainRequest.setUserRoleIdList(
|
||||||
userRoleList.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
userRoleList.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
userMaintainRequest.setUserInfoList(userInfoList);
|
userMaintainRequest.setUserInfoList(userInfoList);
|
||||||
return userMaintainRequest;
|
return userMaintainRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserEditRequest getUserUpdateDTO(UserCreateInfo user, List<UserRoleOption> userRoleList) {
|
public static UserEditRequest getUserUpdateDTO(UserCreateInfo user, List<UserSelectOption> userRoleList) {
|
||||||
UserEditRequest returnDTO = new UserEditRequest();
|
UserEditRequest returnDTO = new UserEditRequest();
|
||||||
if (user.getPhone() == null) {
|
if (user.getPhone() == null) {
|
||||||
user.setPhone("");
|
user.setPhone("");
|
||||||
|
@ -46,7 +42,7 @@ public class UserParamUtils {
|
||||||
BeanUtils.copyBean(returnDTO, user);
|
BeanUtils.copyBean(returnDTO, user);
|
||||||
if (CollectionUtils.isNotEmpty(userRoleList)) {
|
if (CollectionUtils.isNotEmpty(userRoleList)) {
|
||||||
returnDTO.setUserRoleIdList(
|
returnDTO.setUserRoleIdList(
|
||||||
userRoleList.stream().map(UserRoleOption::getId).collect(Collectors.toList()));
|
userRoleList.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
@ -61,23 +57,15 @@ public class UserParamUtils {
|
||||||
public static byte[] getFileBytes(String filePath) {
|
public static byte[] getFileBytes(String filePath) {
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
byte[] buffer = new byte[0];
|
byte[] buffer = new byte[0];
|
||||||
FileInputStream fi = null;
|
try (FileInputStream fi = new FileInputStream(file)) {
|
||||||
try {
|
|
||||||
fi = new FileInputStream(file);
|
|
||||||
buffer = new byte[(int) file.length()];
|
buffer = new byte[(int) file.length()];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int numRead = 0;
|
int numRead;
|
||||||
while (offset < buffer.length
|
while (offset < buffer.length
|
||||||
&& (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
|
&& (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
|
||||||
offset += numRead;
|
offset += numRead;
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fi.close();
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +88,7 @@ public class UserParamUtils {
|
||||||
= selectUserDTO.getUserRoles().stream()
|
= selectUserDTO.getUserRoles().stream()
|
||||||
.filter(item -> (StringUtils.equals(item.getType(), BaseUserRoleService.SYSTEM_TYPE)
|
.filter(item -> (StringUtils.equals(item.getType(), BaseUserRoleService.SYSTEM_TYPE)
|
||||||
&& StringUtils.equals(item.getScopeId(), GlobalUserRoleService.GLOBAL_SCOPE)))
|
&& StringUtils.equals(item.getScopeId(), GlobalUserRoleService.GLOBAL_SCOPE)))
|
||||||
.map(UserRole::getId).collect(Collectors.toList());
|
.map(UserRole::getId).toList();
|
||||||
Assertions.assertTrue(
|
Assertions.assertTrue(
|
||||||
editRequest.getUserRoleIdList().containsAll(selectUserSystemRoleId)
|
editRequest.getUserRoleIdList().containsAll(selectUserSystemRoleId)
|
||||||
&& selectUserSystemRoleId.containsAll(editRequest.getUserRoleIdList()));
|
&& selectUserSystemRoleId.containsAll(editRequest.getUserRoleIdList()));
|
||||||
|
|
|
@ -31,6 +31,12 @@ public class UserRequestUtils {
|
||||||
public final String URL_USER_RESET_PASSWORD = "/system/user/reset/password";
|
public final String URL_USER_RESET_PASSWORD = "/system/user/reset/password";
|
||||||
public final String URL_USER_ROLE_RELATION = "/system/user/add/batch/user-role";
|
public final String URL_USER_ROLE_RELATION = "/system/user/add/batch/user-role";
|
||||||
|
|
||||||
|
//查找组织、项目
|
||||||
|
public final String URL_GET_ORGANIZATION = "/system/user/get/organization";
|
||||||
|
public final String URL_GET_PROJECT = "/system/user/get/project";
|
||||||
|
public final String URL_ADD_PROJECT_MEMBER = "/system/user/add-project-member";
|
||||||
|
public final String URL_ADD_ORGANIZATION_MEMBER = "/system/user/add-org-member";
|
||||||
|
|
||||||
private final MockMvc mockMvc;
|
private final MockMvc mockMvc;
|
||||||
private final String sessionId;
|
private final String sessionId;
|
||||||
private final String csrfToken;
|
private final String csrfToken;
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
# 组织列表数据准备
|
||||||
|
INSERT INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-1',12138, 'tianyang-organization-1', 'XXX-1', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-2',12139, 'tianyang-organization-2', 'XXX-2', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-3',12140, 'tianyang-organization-3', 'XXX-3', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-4',12141, 'tianyang-organization-4', 'XXX-4', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
INSERT INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-5',12142, 'tianyang-organization-5', 'XXX-5', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
|
('tianyang-organization-6',12143, 'tianyang-organization-6', 'XXX-6', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-1', 12138, 'tianyang-organization-1', 'tianyang-projectId-1', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-2', 12139, 'tianyang-organization-1', 'tianyang-projectId-2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-3', 12140, 'tianyang-organization-1', 'tianyang-projectId-3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-4', 12141, 'tianyang-organization-1', 'tianyang-projectId-4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-5', 12142, 'tianyang-organization-1', 'tianyang-projectId-5', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-6', 12143, 'tianyang-organization-1', 'tianyang-projectId-6', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-7', 12144, 'tianyang-organization-1', 'tianyang-projectId-7', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-8', 12145, 'tianyang-organization-1', 'tianyang-projectId-8', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-9', 12146, 'tianyang-organization-1', 'tianyang-projectId-9', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-10', 12147, 'tianyang-organization-1', 'tianyang-projectId-10', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-20', 12148, 'tianyang-organization-2', 'tianyang-projectId-20', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-30', 12149, 'tianyang-organization-3', 'tianyang-projectId-30', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-40', 12150, 'tianyang-organization-4', 'tianyang-projectId-40', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-50', 12151, 'tianyang-organization-5', 'tianyang-projectId-50', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||||
|
('tianyang-projectId-60', 12152, 'tianyang-organization-6', 'tianyang-projectId-60', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
|
||||||
|
|
Loading…
Reference in New Issue