refactor(系统设置): 表格批量参数提取
This commit is contained in:
parent
49a6e24f5d
commit
0221a76d45
|
@ -1,4 +1,4 @@
|
||||||
package io.metersphere.system.request.user;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -10,14 +10,10 @@ import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class BasePageRequest {
|
public class BasePageRequest extends BaseCondition {
|
||||||
@Schema(description = "关键字")
|
|
||||||
private String keyword;
|
|
||||||
|
|
||||||
@Min(value = 1, message = "当前页码必须大于0")
|
@Min(value = 1, message = "当前页码必须大于0")
|
||||||
@Schema(description = "当前页码")
|
@Schema(description = "当前页码")
|
||||||
private int current;
|
private int current;
|
||||||
|
@ -30,11 +26,6 @@ public class BasePageRequest {
|
||||||
@Schema(description = "排序字段(model中的字段 : asc/desc)")
|
@Schema(description = "排序字段(model中的字段 : asc/desc)")
|
||||||
private Map<@Valid @Pattern(regexp = "^[A-Za-z]+$") String, @Valid @NotBlank String> sort;
|
private Map<@Valid @Pattern(regexp = "^[A-Za-z]+$") String, @Valid @NotBlank String> sort;
|
||||||
|
|
||||||
@Schema(description = "过滤字段")
|
|
||||||
private Map<String, List<String>> filter;
|
|
||||||
|
|
||||||
@Schema(description = "高级搜索")
|
|
||||||
private Map<String, Object> combine;
|
|
||||||
|
|
||||||
public String getSortString() {
|
public String getSortString() {
|
||||||
if (sort == null || sort.isEmpty()) {
|
if (sort == null || sort.isEmpty()) {
|
||||||
|
|
|
@ -1,24 +1,22 @@
|
||||||
package io.metersphere.system.request.user;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
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;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserBaseBatchRequest {
|
public class TableBatchProcessDTO {
|
||||||
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@Valid
|
@Valid
|
||||||
private List<
|
private List<
|
||||||
@NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class})
|
@NotBlank(message = "{id must not be blank}", groups = {Created.class, Updated.class})
|
||||||
@Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class})
|
|
||||||
String
|
String
|
||||||
> userIds;
|
> selectIds;
|
||||||
|
|
||||||
@Schema(description = "不处理的用户ID")
|
@Schema(description = "不处理的用户ID")
|
||||||
List<String> excludeIds;
|
List<String> excludeIds;
|
|
@ -1,10 +1,14 @@
|
||||||
package io.metersphere.system.response.user;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class BatchProcessResponse {
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TableBatchProcessResponse {
|
||||||
@Schema(description = "全部数量")
|
@Schema(description = "全部数量")
|
||||||
private long totalCount;
|
private long totalCount;
|
||||||
@Schema(description = "成功数量")
|
@Schema(description = "成功数量")
|
|
@ -1,4 +1,5 @@
|
||||||
excel.parse.error=Excel parse error
|
excel.parse.error=Excel parse error
|
||||||
|
id.not_blank=Id must not be blank
|
||||||
role.not.global.system=Role is not global system role
|
role.not.global.system=Role is not global system role
|
||||||
role.not.contains.member=Role not contains member
|
role.not.contains.member=Role not contains member
|
||||||
user.not.login=User not login
|
user.not.login=User not login
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
excel.parse.error=Excel解析失败
|
excel.parse.error=Excel解析失败
|
||||||
|
id.not_blank=ID不能为空
|
||||||
role.not.global.system=角色不是全局系统角色
|
role.not.global.system=角色不是全局系统角色
|
||||||
role.not.contains.member=角色不包含系统成员角色
|
role.not.contains.member=角色不包含系统成员角色
|
||||||
user.not.login=未获取到登录用户
|
user.not.login=未获取到登录用户
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
excel.parse.error=Excel解析失敗
|
excel.parse.error=Excel解析失敗
|
||||||
|
id.not_blank=ID不能為空
|
||||||
role.not.global.system=角色不是為全局系統角色
|
role.not.global.system=角色不是為全局系統角色
|
||||||
role.not.contains.member=角色不包含系統成員角色
|
role.not.contains.member=角色不包含系統成員角色
|
||||||
user.not.login=未獲取到登錄用戶
|
user.not.login=未獲取到登錄用戶
|
||||||
|
|
|
@ -12,7 +12,6 @@ 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.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;
|
||||||
|
@ -56,15 +55,6 @@ public class GlobalUserRoleRelationController {
|
||||||
globalUserRoleRelationService.add(request);
|
globalUserRoleRelationService.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户管理页面,批量添加用户到多个用户组。 权限所属是用户管理的编辑页面权限
|
|
||||||
@PostMapping("/add/batch/user-role")
|
|
||||||
@Operation(summary = "批量添加用户到多个用户组中")
|
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
|
||||||
@Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
|
||||||
public void batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) {
|
|
||||||
globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/delete/{id}")
|
@GetMapping("/delete/{id}")
|
||||||
@Operation(summary = "删除全局用户组和用户的关联关系")
|
@Operation(summary = "删除全局用户组和用户的关联关系")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE)
|
||||||
|
|
|
@ -6,9 +6,7 @@ import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.project.domain.Project;
|
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.*;
|
||||||
import io.metersphere.sdk.dto.OptionDTO;
|
|
||||||
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;
|
||||||
|
@ -19,8 +17,13 @@ import io.metersphere.system.dto.UserBatchCreateDTO;
|
||||||
import io.metersphere.system.dto.UserExtend;
|
import io.metersphere.system.dto.UserExtend;
|
||||||
import io.metersphere.system.request.OrganizationMemberBatchRequest;
|
import io.metersphere.system.request.OrganizationMemberBatchRequest;
|
||||||
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
|
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
|
||||||
import io.metersphere.system.request.user.*;
|
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
||||||
import io.metersphere.system.response.user.*;
|
import io.metersphere.system.request.user.UserEditRequest;
|
||||||
|
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
||||||
|
import io.metersphere.system.response.user.UserImportResponse;
|
||||||
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
|
import io.metersphere.system.response.user.UserTableResponse;
|
||||||
|
import io.metersphere.system.response.user.UserTreeSelectOption;
|
||||||
import io.metersphere.system.service.*;
|
import io.metersphere.system.service.*;
|
||||||
import io.metersphere.system.utils.TreeNodeParseUtils;
|
import io.metersphere.system.utils.TreeNodeParseUtils;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
|
@ -88,7 +91,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 BatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) {
|
public TableBatchProcessResponse updateUserEnable(@Validated @RequestBody UserChangeEnableRequest request) {
|
||||||
return userService.updateUserEnable(request, SessionUtils.getSessionId());
|
return userService.updateUserEnable(request, SessionUtils.getSessionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +106,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 BatchProcessResponse deleteUser(@Validated @RequestBody UserBaseBatchRequest request) {
|
public TableBatchProcessResponse deleteUser(@Validated @RequestBody TableBatchProcessDTO request) {
|
||||||
return userService.deleteUser(request, SessionUtils.getUserId());
|
return userService.deleteUser(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +114,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 BatchProcessResponse resetPassword(@Validated @RequestBody UserBaseBatchRequest request) {
|
public TableBatchProcessResponse resetPassword(@Validated @RequestBody TableBatchProcessDTO request) {
|
||||||
return userService.resetPassword(request, SessionUtils.getUserId());
|
return userService.resetPassword(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +126,6 @@ public class UserController {
|
||||||
return userService.getMemberOption(sourceId);
|
return userService.getMemberOption(sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/add/batch/user-role")
|
|
||||||
@Operation(summary = "批量添加用户到多个用户组中")
|
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
|
||||||
@Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
|
||||||
public BatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserAndRoleBatchRequest request) {
|
|
||||||
return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get/global/system/role")
|
@GetMapping("/get/global/system/role")
|
||||||
@Operation(summary = "查找系统级用户权限")
|
@Operation(summary = "查找系统级用户权限")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
||||||
|
@ -153,24 +148,35 @@ public class UserController {
|
||||||
return TreeNodeParseUtils.parseOrgProjectMap(orgProjectMap);
|
return TreeNodeParseUtils.parseOrgProjectMap(orgProjectMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add/batch/user-role")
|
||||||
|
@Operation(summary = "批量添加用户到多个用户组中")
|
||||||
|
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_UPDATE)
|
||||||
|
@Log(type = OperationLogType.ADD, expression = "#msClass.batchAddLog(#request)", msClass = GlobalUserRoleRelationLogService.class)
|
||||||
|
public TableBatchProcessResponse batchAdd(@Validated({Created.class}) @RequestBody UserRoleBatchRelationRequest request) {
|
||||||
|
return globalUserRoleRelationService.batchAdd(request, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/add-project-member")
|
@PostMapping("/add-project-member")
|
||||||
@Operation(summary = "批量添加用户到项目")
|
@Operation(summary = "批量添加用户到项目")
|
||||||
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND)
|
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND)
|
||||||
public void addProjectMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
public TableBatchProcessResponse addProjectMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
||||||
ProjectAddMemberBatchRequest request = new ProjectAddMemberBatchRequest();
|
ProjectAddMemberBatchRequest request = new ProjectAddMemberBatchRequest();
|
||||||
request.setProjectIds(userRoleBatchRelationRequest.getRoleIds());
|
request.setProjectIds(userRoleBatchRelationRequest.getRoleIds());
|
||||||
request.setUserIds(userRoleBatchRelationRequest.getUserIds());
|
request.setUserIds(userRoleBatchRelationRequest.getSelectIds());
|
||||||
systemProjectService.addProjectMember(request, SessionUtils.getUserId());
|
systemProjectService.addProjectMember(request, SessionUtils.getUserId());
|
||||||
|
return new TableBatchProcessResponse(userRoleBatchRelationRequest.getSelectIds().size(), userRoleBatchRelationRequest.getSelectIds().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/add-org-member")
|
@PostMapping("/add-org-member")
|
||||||
@Operation(summary = "批量添加用户到组织")
|
@Operation(summary = "批量添加用户到组织")
|
||||||
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND)
|
@RequiresPermissions(value = {PermissionConstants.SYSTEM_USER_READ_UPDATE, PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_MEMBER_ADD}, logical = Logical.AND)
|
||||||
public void addMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
public TableBatchProcessResponse addMember(@Validated @RequestBody UserRoleBatchRelationRequest userRoleBatchRelationRequest) {
|
||||||
|
//获取本次处理的用户
|
||||||
|
userRoleBatchRelationRequest.setSelectIds(userService.getBatchUserIds(userRoleBatchRelationRequest));
|
||||||
OrganizationMemberBatchRequest request = new OrganizationMemberBatchRequest();
|
OrganizationMemberBatchRequest request = new OrganizationMemberBatchRequest();
|
||||||
request.setOrganizationIds(userRoleBatchRelationRequest.getRoleIds());
|
request.setOrganizationIds(userRoleBatchRelationRequest.getRoleIds());
|
||||||
request.setMemberIds(userRoleBatchRelationRequest.getUserIds());
|
request.setMemberIds(userRoleBatchRelationRequest.getSelectIds());
|
||||||
organizationService.addMemberBySystem(request, SessionUtils.getUserId());
|
organizationService.addMemberBySystem(request, SessionUtils.getUserId());
|
||||||
|
return new TableBatchProcessResponse(userRoleBatchRelationRequest.getSelectIds().size(), userRoleBatchRelationRequest.getSelectIds().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package io.metersphere.system.request.user;
|
|
||||||
|
|
||||||
import io.metersphere.validation.groups.Created;
|
|
||||||
import io.metersphere.validation.groups.Updated;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
public class UserAndRoleBatchRequest extends UserBaseBatchRequest {
|
|
||||||
|
|
||||||
@Schema(description = "组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
||||||
@NotEmpty(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class})
|
|
||||||
@Valid
|
|
||||||
private List<
|
|
||||||
@NotBlank(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class, Updated.class})
|
|
||||||
@Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class})
|
|
||||||
String
|
|
||||||
> roleIds;
|
|
||||||
|
|
||||||
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
||||||
@NotEmpty(message = "{user_role_relation.role_id.not_blank}", groups = {Created.class})
|
|
||||||
@Valid
|
|
||||||
private List<
|
|
||||||
@NotBlank(message = "{user_role_relation.user_id.not_blank}", groups = {Created.class, Updated.class})
|
|
||||||
@Size(min = 1, max = 50, message = "{user_role_relation.user_id.length_range}", groups = {Created.class, Updated.class})
|
|
||||||
String
|
|
||||||
> userIds;
|
|
||||||
}
|
|
|
@ -1,12 +1,13 @@
|
||||||
package io.metersphere.system.request.user;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
|
import io.metersphere.sdk.dto.TableBatchProcessDTO;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class UserChangeEnableRequest extends UserBaseBatchRequest {
|
public class UserChangeEnableRequest extends TableBatchProcessDTO {
|
||||||
@Schema(description = "禁用/启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "禁用/启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
boolean enable;
|
boolean enable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.system.request.user;
|
package io.metersphere.system.request.user;
|
||||||
|
|
||||||
|
import io.metersphere.sdk.dto.TableBatchProcessDTO;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -7,18 +8,11 @@ import lombok.Data;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserRoleBatchRelationRequest {
|
public class UserRoleBatchRelationRequest extends TableBatchProcessDTO {
|
||||||
/**
|
/**
|
||||||
* 权限ID集合
|
* 权限ID集合
|
||||||
*/
|
*/
|
||||||
@Schema(description = "权限ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "权限ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotEmpty(message = "{organization.id.not_blank}")
|
@NotEmpty(message = "{organization.id.not_blank}")
|
||||||
private List<String> roleIds;
|
private List<String> roleIds;
|
||||||
|
|
||||||
/**
|
|
||||||
* 成员ID集合
|
|
||||||
*/
|
|
||||||
@Schema(description = "成员ID集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
||||||
@NotEmpty(message = "{user.id.not_blank}")
|
|
||||||
private List<String> userIds;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import io.metersphere.system.domain.UserRoleExample;
|
||||||
import io.metersphere.system.domain.UserRoleRelation;
|
import io.metersphere.system.domain.UserRoleRelation;
|
||||||
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 io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ public class GlobalUserRoleRelationLogService {
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LogDTO> batchAddLog(UserAndRoleBatchRequest request) {
|
public List<LogDTO> batchAddLog(UserRoleBatchRelationRequest request) {
|
||||||
UserRoleExample example = new UserRoleExample();
|
UserRoleExample example = new UserRoleExample();
|
||||||
example.createCriteria().andIdIn(request.getRoleIds());
|
example.createCriteria().andIdIn(request.getRoleIds());
|
||||||
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
List<UserRole> userRoles = userRoleMapper.selectByExample(example);
|
||||||
List<String> userIds = request.getUserIds();
|
List<String> userIds = request.getSelectIds();
|
||||||
List<OptionDTO> users = baseUserMapper.selectUserOptionByIds(userIds);
|
List<OptionDTO> users = baseUserMapper.selectUserOptionByIds(userIds);
|
||||||
|
|
||||||
List<LogDTO> returnList = new ArrayList<>();
|
List<LogDTO> returnList = new ArrayList<>();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.system.service;
|
package io.metersphere.system.service;
|
||||||
|
|
||||||
|
import io.metersphere.sdk.dto.TableBatchProcessResponse;
|
||||||
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
import io.metersphere.sdk.dto.UserRoleRelationUserDTO;
|
||||||
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
import io.metersphere.sdk.dto.request.GlobalUserRoleRelationUpdateRequest;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
|
@ -12,8 +13,7 @@ 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.mapper.ExtUserRoleRelationMapper;
|
import io.metersphere.system.mapper.ExtUserRoleRelationMapper;
|
||||||
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
||||||
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,20 +85,20 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
||||||
return userRoleRelationMapper.selectByExample(example);
|
return userRoleRelationMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserAndRoleBatchRequest request, String operator) {
|
public TableBatchProcessResponse batchAdd(@Validated({Created.class, Updated.class}) UserRoleBatchRelationRequest request, String operator) {
|
||||||
//检查角色的合法性
|
//检查角色的合法性
|
||||||
this.checkGlobalSystemUserRoleLegality(request.getRoleIds());
|
this.checkGlobalSystemUserRoleLegality(request.getRoleIds());
|
||||||
//获取本次处理的用户
|
//获取本次处理的用户
|
||||||
request.setUserIds(userService.getBatchUserIds(request));
|
request.setSelectIds(userService.getBatchUserIds(request));
|
||||||
//检查用户的合法性
|
//检查用户的合法性
|
||||||
userService.checkUserLegality(request.getUserIds());
|
userService.checkUserLegality(request.getSelectIds());
|
||||||
List<UserRoleRelation> savedUserRoleRelation = this.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds());
|
List<UserRoleRelation> savedUserRoleRelation = this.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds());
|
||||||
//过滤已经存储过的用户关系
|
//过滤已经存储过的用户关系
|
||||||
Map<String, List<String>> userRoleIdMap = savedUserRoleRelation.stream()
|
Map<String, List<String>> userRoleIdMap = savedUserRoleRelation.stream()
|
||||||
.collect(Collectors.groupingBy(UserRoleRelation::getUserId, Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
.collect(Collectors.groupingBy(UserRoleRelation::getUserId, Collectors.mapping(UserRoleRelation::getRoleId, Collectors.toList())));
|
||||||
long createTime = System.currentTimeMillis();
|
long createTime = System.currentTimeMillis();
|
||||||
List<UserRoleRelation> saveList = new ArrayList<>();
|
List<UserRoleRelation> saveList = new ArrayList<>();
|
||||||
for (String userId : request.getUserIds()) {
|
for (String userId : request.getSelectIds()) {
|
||||||
for (String roleId : request.getRoleIds()) {
|
for (String roleId : request.getRoleIds()) {
|
||||||
if (userRoleIdMap.containsKey(userId) && userRoleIdMap.get(userId).contains(roleId)) {
|
if (userRoleIdMap.containsKey(userId) && userRoleIdMap.get(userId).contains(roleId)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -116,8 +116,8 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
||||||
if (CollectionUtils.isNotEmpty(saveList)) {
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
||||||
userRoleRelationMapper.batchInsert(saveList);
|
userRoleRelationMapper.batchInsert(saveList);
|
||||||
}
|
}
|
||||||
BatchProcessResponse response = new BatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getSelectIds().size());
|
||||||
response.setSuccessCount(saveList.size());
|
response.setSuccessCount(saveList.size());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@ package io.metersphere.system.service;
|
||||||
import com.alibaba.excel.EasyExcelFactory;
|
import com.alibaba.excel.EasyExcelFactory;
|
||||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||||
import io.metersphere.sdk.dto.BasePageRequest;
|
import io.metersphere.sdk.dto.*;
|
||||||
import io.metersphere.sdk.dto.ExcelParseDTO;
|
|
||||||
import io.metersphere.sdk.dto.LogDTO;
|
|
||||||
import io.metersphere.sdk.dto.UserDTO;
|
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.log.constants.OperationLogModule;
|
import io.metersphere.sdk.log.constants.OperationLogModule;
|
||||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
|
@ -22,10 +19,8 @@ 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.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.UserChangeEnableRequest;
|
||||||
import io.metersphere.system.request.user.UserEditRequest;
|
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.UserImportResponse;
|
||||||
import io.metersphere.system.response.user.UserTableResponse;
|
import io.metersphere.system.response.user.UserTableResponse;
|
||||||
import io.metersphere.system.utils.UserImportEventListener;
|
import io.metersphere.system.utils.UserImportEventListener;
|
||||||
|
@ -197,14 +192,14 @@ public class UserService {
|
||||||
return userEditRequest;
|
return userEditRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) {
|
public TableBatchProcessResponse updateUserEnable(UserChangeEnableRequest request, String operator) {
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setSelectIds(this.getBatchUserIds(request));
|
||||||
this.checkUserInDb(request.getUserIds());
|
this.checkUserInDb(request.getSelectIds());
|
||||||
BatchProcessResponse response = new BatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getSelectIds().size());
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdIn(
|
userExample.createCriteria().andIdIn(
|
||||||
request.getUserIds()
|
request.getSelectIds()
|
||||||
);
|
);
|
||||||
User updateUser = new User();
|
User updateUser = new User();
|
||||||
updateUser.setEnable(request.isEnable());
|
updateUser.setEnable(request.isEnable());
|
||||||
|
@ -282,7 +277,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public BatchProcessResponse deleteUser(@Valid UserBaseBatchRequest request, String operator) {
|
public TableBatchProcessResponse deleteUser(@Valid TableBatchProcessDTO 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 +285,7 @@ public class UserService {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdIn(userIdList);
|
userExample.createCriteria().andIdIn(userIdList);
|
||||||
//更新删除标志位
|
//更新删除标志位
|
||||||
BatchProcessResponse response = new BatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
response.setTotalCount(userIdList.size());
|
response.setTotalCount(userIdList.size());
|
||||||
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
||||||
//删除用户角色关系
|
//删除用户角色关系
|
||||||
|
@ -342,10 +337,10 @@ public class UserService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LogDTO> batchUpdateLog(UserBaseBatchRequest request) {
|
public List<LogDTO> batchUpdateLog(TableBatchProcessDTO request) {
|
||||||
List<LogDTO> logDTOList = new ArrayList<>();
|
List<LogDTO> logDTOList = new ArrayList<>();
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setSelectIds(this.getBatchUserIds(request));
|
||||||
List<User> userList = this.selectByIdList(request.getUserIds());
|
List<User> userList = this.selectByIdList(request.getSelectIds());
|
||||||
for (User user : userList) {
|
for (User user : userList) {
|
||||||
LogDTO dto = new LogDTO(
|
LogDTO dto = new LogDTO(
|
||||||
OperationLogConstants.SYSTEM,
|
OperationLogConstants.SYSTEM,
|
||||||
|
@ -365,11 +360,11 @@ public class UserService {
|
||||||
/**
|
/**
|
||||||
* @param request 批量重置密码 用于记录Log使用
|
* @param request 批量重置密码 用于记录Log使用
|
||||||
*/
|
*/
|
||||||
public List<LogDTO> resetPasswordLog(UserBaseBatchRequest request) {
|
public List<LogDTO> resetPasswordLog(TableBatchProcessDTO request) {
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setSelectIds(this.getBatchUserIds(request));
|
||||||
List<LogDTO> returnList = new ArrayList<>();
|
List<LogDTO> returnList = new ArrayList<>();
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdIn(request.getUserIds());
|
example.createCriteria().andIdIn(request.getSelectIds());
|
||||||
List<User> userList = userMapper.selectByExample(example);
|
List<User> userList = userMapper.selectByExample(example);
|
||||||
for (User user : userList) {
|
for (User user : userList) {
|
||||||
LogDTO dto = new LogDTO(
|
LogDTO dto = new LogDTO(
|
||||||
|
@ -388,9 +383,9 @@ public class UserService {
|
||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LogDTO> deleteLog(UserBaseBatchRequest request) {
|
public List<LogDTO> deleteLog(TableBatchProcessDTO request) {
|
||||||
List<LogDTO> logDTOList = new ArrayList<>();
|
List<LogDTO> logDTOList = new ArrayList<>();
|
||||||
request.getUserIds().forEach(item -> {
|
request.getSelectIds().forEach(item -> {
|
||||||
User user = userMapper.selectByPrimaryKey(item);
|
User user = userMapper.selectByPrimaryKey(item);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
|
||||||
|
@ -422,15 +417,15 @@ public class UserService {
|
||||||
return extUserMapper.getMemberOption(sourceId);
|
return extUserMapper.getMemberOption(sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchProcessResponse resetPassword(UserBaseBatchRequest request, String operator) {
|
public TableBatchProcessResponse resetPassword(TableBatchProcessDTO request, String operator) {
|
||||||
request.setUserIds(this.getBatchUserIds(request));
|
request.setSelectIds(this.getBatchUserIds(request));
|
||||||
this.checkUserInDb(request.getUserIds());
|
this.checkUserInDb(request.getSelectIds());
|
||||||
|
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
UserMapper batchUpdateMapper = sqlSession.getMapper(UserMapper.class);
|
UserMapper batchUpdateMapper = sqlSession.getMapper(UserMapper.class);
|
||||||
int insertIndex = 0;
|
int insertIndex = 0;
|
||||||
long updateTime = System.currentTimeMillis();
|
long updateTime = System.currentTimeMillis();
|
||||||
List<User> userList = this.selectByIdList(request.getUserIds());
|
List<User> userList = this.selectByIdList(request.getSelectIds());
|
||||||
for (User user : userList) {
|
for (User user : userList) {
|
||||||
User updateModel = new User();
|
User updateModel = new User();
|
||||||
updateModel.setId(user.getId());
|
updateModel.setId(user.getId());
|
||||||
|
@ -450,13 +445,16 @@ public class UserService {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
|
||||||
BatchProcessResponse response = new BatchProcessResponse();
|
TableBatchProcessResponse response = new TableBatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getSelectIds().size());
|
||||||
response.setSuccessCount(request.getUserIds().size());
|
response.setSuccessCount(request.getSelectIds().size());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkUserLegality(List<String> userIds) {
|
public void checkUserLegality(List<String> userIds) {
|
||||||
|
if (CollectionUtils.isEmpty(userIds)) {
|
||||||
|
throw new MSException(Translator.get("user.not.exist"));
|
||||||
|
}
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdIn(userIds);
|
example.createCriteria().andIdIn(userIds);
|
||||||
if (userMapper.countByExample(example) != userIds.size()) {
|
if (userMapper.countByExample(example) != userIds.size()) {
|
||||||
|
@ -464,7 +462,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getBatchUserIds(UserBaseBatchRequest request) {
|
public List<String> getBatchUserIds(TableBatchProcessDTO request) {
|
||||||
if (request.isSelectAll()) {
|
if (request.isSelectAll()) {
|
||||||
List<User> userList = baseUserMapper.selectByKeyword(request.getCondition().getKeyword(), true);
|
List<User> userList = baseUserMapper.selectByKeyword(request.getCondition().getKeyword(), true);
|
||||||
List<String> userIdList = userList.stream().map(User::getId).collect(Collectors.toList());
|
List<String> userIdList = userList.stream().map(User::getId).collect(Collectors.toList());
|
||||||
|
@ -473,7 +471,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
return userIdList;
|
return userIdList;
|
||||||
} else {
|
} else {
|
||||||
return request.getUserIds();
|
return request.getSelectIds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,8 @@ package io.metersphere.system.controller.user;
|
||||||
|
|
||||||
import io.metersphere.sdk.base.BaseTest;
|
import io.metersphere.sdk.base.BaseTest;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
|
import io.metersphere.sdk.dto.TableBatchProcessDTO;
|
||||||
import io.metersphere.system.dto.UserCreateInfo;
|
import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.request.user.UserAndRoleBatchRequest;
|
|
||||||
import io.metersphere.system.request.user.UserBaseBatchRequest;
|
|
||||||
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
||||||
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
||||||
import io.metersphere.system.response.user.UserSelectOption;
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
|
@ -63,7 +62,7 @@ public class UserControllerPermissionTests extends BaseTest {
|
||||||
//校验权限:启用/禁用用户
|
//校验权限:启用/禁用用户
|
||||||
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
|
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
|
||||||
userChangeEnableRequest.setEnable(false);
|
userChangeEnableRequest.setEnable(false);
|
||||||
userChangeEnableRequest.setUserIds(new ArrayList<>() {{
|
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
|
||||||
this.add("admin");
|
this.add("admin");
|
||||||
}});
|
}});
|
||||||
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest);
|
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest);
|
||||||
|
@ -77,20 +76,20 @@ public class UserControllerPermissionTests extends BaseTest {
|
||||||
this.requestMultipartPermissionTest(PermissionConstants.SYSTEM_USER_READ_IMPORT, UserRequestUtils.URL_USER_IMPORT, paramMap);
|
this.requestMultipartPermissionTest(PermissionConstants.SYSTEM_USER_READ_IMPORT, UserRequestUtils.URL_USER_IMPORT, paramMap);
|
||||||
|
|
||||||
//用户删除
|
//用户删除
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(new ArrayList<>() {{
|
request.setSelectIds(new ArrayList<>() {{
|
||||||
this.add("testId");
|
this.add("testId");
|
||||||
}});
|
}});
|
||||||
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_DELETE, UserRequestUtils.URL_USER_DELETE, request);
|
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_DELETE, UserRequestUtils.URL_USER_DELETE, request);
|
||||||
|
|
||||||
//重置密码
|
//重置密码
|
||||||
request = new UserBaseBatchRequest();
|
request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(Collections.singletonList("admin"));
|
request.setSelectIds(Collections.singletonList("admin"));
|
||||||
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD, request);
|
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD, request);
|
||||||
|
|
||||||
//批量添加用户到用户组
|
//批量添加用户到用户组
|
||||||
UserAndRoleBatchRequest userAndRoleBatchRequest = new UserAndRoleBatchRequest();
|
UserRoleBatchRelationRequest userAndRoleBatchRequest = new UserRoleBatchRelationRequest();
|
||||||
userAndRoleBatchRequest.setUserIds(Collections.singletonList("admin"));
|
userAndRoleBatchRequest.setSelectIds(Collections.singletonList("admin"));
|
||||||
userAndRoleBatchRequest.setRoleIds(Collections.singletonList("member"));
|
userAndRoleBatchRequest.setRoleIds(Collections.singletonList("member"));
|
||||||
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_ROLE_RELATION, userAndRoleBatchRequest);
|
this.requestPostPermissionTest(PermissionConstants.SYSTEM_USER_READ_UPDATE, UserRequestUtils.URL_USER_ROLE_RELATION, userAndRoleBatchRequest);
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ public class UserControllerPermissionTests extends BaseTest {
|
||||||
|
|
||||||
// 批量添加用户到项目
|
// 批量添加用户到项目
|
||||||
UserRoleBatchRelationRequest roleBatchRelationRequest = new UserRoleBatchRelationRequest();
|
UserRoleBatchRelationRequest roleBatchRelationRequest = new UserRoleBatchRelationRequest();
|
||||||
roleBatchRelationRequest.setUserIds(Collections.singletonList("admin"));
|
roleBatchRelationRequest.setSelectIds(Collections.singletonList("admin"));
|
||||||
roleBatchRelationRequest.setRoleIds(Collections.singletonList("member"));
|
roleBatchRelationRequest.setRoleIds(Collections.singletonList("member"));
|
||||||
List<String> addMemberPermissionList = new ArrayList<>();
|
List<String> addMemberPermissionList = new ArrayList<>();
|
||||||
addMemberPermissionList.add(PermissionConstants.SYSTEM_USER_READ_UPDATE);
|
addMemberPermissionList.add(PermissionConstants.SYSTEM_USER_READ_UPDATE);
|
||||||
|
|
|
@ -4,9 +4,7 @@ import io.metersphere.project.domain.Project;
|
||||||
import io.metersphere.project.mapper.ProjectMapper;
|
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.*;
|
||||||
import io.metersphere.sdk.dto.ExcelParseDTO;
|
|
||||||
import io.metersphere.sdk.dto.UserDTO;
|
|
||||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.CodingUtil;
|
import io.metersphere.sdk.util.CodingUtil;
|
||||||
|
@ -20,8 +18,13 @@ import io.metersphere.system.dto.UserCreateInfo;
|
||||||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||||
import io.metersphere.system.request.user.*;
|
import io.metersphere.system.request.user.UserChangeEnableRequest;
|
||||||
import io.metersphere.system.response.user.*;
|
import io.metersphere.system.request.user.UserEditRequest;
|
||||||
|
import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
||||||
|
import io.metersphere.system.response.user.UserImportResponse;
|
||||||
|
import io.metersphere.system.response.user.UserSelectOption;
|
||||||
|
import io.metersphere.system.response.user.UserTableResponse;
|
||||||
|
import io.metersphere.system.response.user.UserTreeSelectOption;
|
||||||
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;
|
||||||
|
@ -364,12 +367,12 @@ public class UserControllerTests extends BaseTest {
|
||||||
//单独修改状态
|
//单独修改状态
|
||||||
UserCreateInfo userInfo = USER_LIST.get(0);
|
UserCreateInfo userInfo = USER_LIST.get(0);
|
||||||
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
|
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
|
||||||
userChangeEnableRequest.setUserIds(new ArrayList<>() {{
|
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
|
||||||
this.add(userInfo.getId());
|
this.add(userInfo.getId());
|
||||||
}});
|
}});
|
||||||
userChangeEnableRequest.setEnable(false);
|
userChangeEnableRequest.setEnable(false);
|
||||||
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk());
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk());
|
||||||
for (String item : userChangeEnableRequest.getUserIds()) {
|
for (String item : userChangeEnableRequest.getSelectIds()) {
|
||||||
checkLog(item, OperationLogType.UPDATE);
|
checkLog(item, OperationLogType.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +389,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
userChangeEnableRequest.setEnable(false);
|
userChangeEnableRequest.setEnable(false);
|
||||||
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER);
|
||||||
//含有非法用户
|
//含有非法用户
|
||||||
userChangeEnableRequest.setUserIds(new ArrayList<>() {{
|
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
|
||||||
this.add("BCDEDIT");
|
this.add("BCDEDIT");
|
||||||
}});
|
}});
|
||||||
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
@ -479,8 +482,8 @@ public class UserControllerTests extends BaseTest {
|
||||||
public void testUserResetPasswordError() throws Exception {
|
public void testUserResetPasswordError() throws Exception {
|
||||||
//用户不存在
|
//用户不存在
|
||||||
{
|
{
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(Collections.singletonList("none user"));
|
request.setSelectIds(Collections.singletonList("none user"));
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,12 +605,9 @@ public class UserControllerTests extends BaseTest {
|
||||||
this.checkUserList();
|
this.checkUserList();
|
||||||
//重置admin的密码
|
//重置admin的密码
|
||||||
{
|
{
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(Collections.singletonList("admin"));
|
request.setSelectIds(Collections.singletonList("admin"));
|
||||||
userRequestUtils.parseObjectFromMvcResult(
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request);
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
|
||||||
BatchProcessResponse.class
|
|
||||||
);
|
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtil.md5("metersphere"));
|
userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtil.md5("metersphere"));
|
||||||
|
@ -621,11 +621,11 @@ public class UserControllerTests extends BaseTest {
|
||||||
paramUser.setId(userId);
|
paramUser.setId(userId);
|
||||||
paramUser.setPassword("I can't say any dirty words");
|
paramUser.setPassword("I can't say any dirty words");
|
||||||
Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser));
|
Assertions.assertEquals(1, userMapper.updateByPrimaryKeySelective(paramUser));
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(Collections.singletonList(userId));
|
request.setSelectIds(Collections.singletonList(userId));
|
||||||
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
BatchProcessResponse.class
|
TableBatchProcessResponse.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));
|
||||||
|
@ -638,12 +638,12 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
//重置非Admin用户的密码
|
//重置非Admin用户的密码
|
||||||
{
|
{
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setExcludeIds(Collections.singletonList("admin"));
|
request.setExcludeIds(Collections.singletonList("admin"));
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
BatchProcessResponse.class
|
TableBatchProcessResponse.class
|
||||||
);
|
);
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdNotEqualTo("admin");
|
example.createCriteria().andIdNotEqualTo("admin");
|
||||||
|
@ -671,14 +671,14 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
//测试添加角色权限。 预期数据:每个用户都会增加对应的权限
|
//测试添加角色权限。 预期数据:每个用户都会增加对应的权限
|
||||||
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::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(
|
||||||
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds()).size(),
|
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(),
|
||||||
request.getUserIds().size() * request.getRoleIds().size()
|
request.getSelectIds().size() * request.getRoleIds().size()
|
||||||
);
|
);
|
||||||
//检查日志
|
//检查日志
|
||||||
for (UserSelectOption option : USER_ROLE_LIST) {
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
|
@ -689,8 +689,8 @@ public class UserControllerTests extends BaseTest {
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
||||||
//检查有权限的数据量是否一致
|
//检查有权限的数据量是否一致
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getUserIds(), request.getRoleIds()).size(),
|
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(),
|
||||||
request.getUserIds().size() * request.getRoleIds().size()
|
request.getSelectIds().size() * request.getRoleIds().size()
|
||||||
);
|
);
|
||||||
//检查日志
|
//检查日志
|
||||||
for (UserSelectOption option : USER_ROLE_LIST) {
|
for (UserSelectOption option : USER_ROLE_LIST) {
|
||||||
|
@ -707,24 +707,24 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
// 用户ID为空
|
// 用户ID为空
|
||||||
UserAndRoleBatchRequest request = new UserAndRoleBatchRequest();
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(new ArrayList<>());
|
request.setSelectIds(new ArrayList<>());
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::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, ERROR_REQUEST_MATCHER);
|
||||||
// 角色id为空
|
// 角色id为空
|
||||||
request = new UserAndRoleBatchRequest();
|
request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(new ArrayList<>());
|
request.setRoleIds(new ArrayList<>());
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
||||||
// 用户ID含有不存在的
|
// 用户ID含有不存在的
|
||||||
request = new UserAndRoleBatchRequest();
|
request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
request.getUserIds().add("none user");
|
request.getSelectIds().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 UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::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);
|
||||||
|
@ -768,7 +768,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
|
|
||||||
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
//排除树结构中的组织ID
|
//排除树结构中的组织ID
|
||||||
request.getRoleIds().removeAll(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
request.getRoleIds().removeAll(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
|
@ -779,7 +779,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
for (String projectId : request.getRoleIds()) {
|
for (String projectId : request.getRoleIds()) {
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
String orgId = project.getOrganizationId();
|
String orgId = project.getOrganizationId();
|
||||||
for (String userId : request.getUserIds()) {
|
for (String userId : request.getSelectIds()) {
|
||||||
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(projectId);
|
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(projectId);
|
||||||
//检查是否在对应的项目下
|
//检查是否在对应的项目下
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
|
@ -813,13 +813,13 @@ public class UserControllerTests extends BaseTest {
|
||||||
|
|
||||||
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
||||||
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
||||||
request.setUserIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
this.requestPost(userRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request);
|
this.requestPost(userRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request);
|
||||||
//检查有权限的数据量是否一致
|
//检查有权限的数据量是否一致
|
||||||
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
||||||
for (String orgId : request.getRoleIds()) {
|
for (String orgId : request.getRoleIds()) {
|
||||||
for (String userId : request.getUserIds()) {
|
for (String userId : request.getSelectIds()) {
|
||||||
checkExample.clear();
|
checkExample.clear();
|
||||||
//检查是否在对应的组织下
|
//检查是否在对应的组织下
|
||||||
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(orgId);
|
checkExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(orgId);
|
||||||
|
@ -842,44 +842,44 @@ public class UserControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
// 用户ID为空
|
// 用户ID为空
|
||||||
UserRoleBatchRelationRequest addToProjectRequest = new UserRoleBatchRelationRequest();
|
UserRoleBatchRelationRequest addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
addToProjectRequest.setUserIds(new ArrayList<>());
|
addToProjectRequest.setSelectIds(new ArrayList<>());
|
||||||
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
||||||
// 项目为空
|
// 项目为空
|
||||||
addToProjectRequest = new UserRoleBatchRelationRequest();
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
addToProjectRequest.setRoleIds(new ArrayList<>());
|
addToProjectRequest.setRoleIds(new ArrayList<>());
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
||||||
// 用户ID含有不存在的
|
// 用户ID含有不存在的
|
||||||
addToProjectRequest = new UserRoleBatchRelationRequest();
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
addToProjectRequest.setUserIds(Collections.singletonList("none user"));
|
addToProjectRequest.setSelectIds(Collections.singletonList("none user"));
|
||||||
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
||||||
// 项目ID含有不存在的
|
// 项目ID含有不存在的
|
||||||
addToProjectRequest = new UserRoleBatchRelationRequest();
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
||||||
addToProjectRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
addToProjectRequest.setRoleIds(Collections.singletonList("none role"));
|
addToProjectRequest.setRoleIds(Collections.singletonList("none role"));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
||||||
|
|
||||||
|
|
||||||
// 用户ID为空
|
// 用户ID为空
|
||||||
UserRoleBatchRelationRequest orgRequest = new UserRoleBatchRelationRequest();
|
UserRoleBatchRelationRequest orgRequest = new UserRoleBatchRelationRequest();
|
||||||
orgRequest.setUserIds(new ArrayList<>());
|
orgRequest.setSelectIds(new ArrayList<>());
|
||||||
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
||||||
// 项目为空
|
// 项目为空
|
||||||
orgRequest = new UserRoleBatchRelationRequest();
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
orgRequest.setRoleIds(new ArrayList<>());
|
orgRequest.setRoleIds(new ArrayList<>());
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
||||||
// 用户ID含有不存在的
|
// 用户ID含有不存在的
|
||||||
orgRequest = new UserRoleBatchRelationRequest();
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
orgRequest.setUserIds(Collections.singletonList("none user"));
|
orgRequest.setSelectIds(Collections.singletonList("none user"));
|
||||||
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
||||||
// 项目ID含有不存在的
|
// 项目ID含有不存在的
|
||||||
orgRequest = new UserRoleBatchRelationRequest();
|
orgRequest = new UserRoleBatchRelationRequest();
|
||||||
orgRequest.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
orgRequest.setRoleIds(Collections.singletonList("none role"));
|
orgRequest.setRoleIds(Collections.singletonList("none role"));
|
||||||
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
@ -892,11 +892,12 @@ public class UserControllerTests extends BaseTest {
|
||||||
//删除指定的用户
|
//删除指定的用户
|
||||||
{
|
{
|
||||||
UserCreateInfo deleteUser = USER_LIST.get(0);
|
UserCreateInfo deleteUser = USER_LIST.get(0);
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
request.setUserIds(Collections.singletonList(deleteUser.getId()));
|
request.setSelectIds(Collections.singletonList(deleteUser.getId()));
|
||||||
BatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), BatchProcessResponse.class);
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), TableBatchProcessResponse.class);
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
Assertions.assertEquals(request.getSelectIds().size(), response.getTotalCount());
|
||||||
|
Assertions.assertEquals(request.getSelectIds().size(), response.getSuccessCount());
|
||||||
//检查数据库
|
//检查数据库
|
||||||
User user = userMapper.selectByPrimaryKey(deleteUser.getId());
|
User user = userMapper.selectByPrimaryKey(deleteUser.getId());
|
||||||
Assertions.assertTrue(user.getDeleted());
|
Assertions.assertTrue(user.getDeleted());
|
||||||
|
@ -909,20 +910,20 @@ public class UserControllerTests extends BaseTest {
|
||||||
@Order(100)
|
@Order(100)
|
||||||
public void testUserDeleteError() throws Exception {
|
public void testUserDeleteError() throws Exception {
|
||||||
//参数为空
|
//参数为空
|
||||||
UserBaseBatchRequest request = new UserBaseBatchRequest();
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
||||||
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
||||||
//用户不存在
|
//用户不存在
|
||||||
request.setUserIds(Collections.singletonList("none user"));
|
request.setSelectIds(Collections.singletonList("none user"));
|
||||||
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
||||||
//测试用户已经被删除的
|
//测试用户已经被删除的
|
||||||
if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) {
|
if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) {
|
||||||
this.testUserDeleteSuccess();
|
this.testUserDeleteSuccess();
|
||||||
}
|
}
|
||||||
request.setUserIds(DELETED_USER_ID_LIST);
|
request.setSelectIds(DELETED_USER_ID_LIST);
|
||||||
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
||||||
|
|
||||||
//测试包含Admin用户
|
//测试包含Admin用户
|
||||||
request = new UserBaseBatchRequest();
|
request = new TableBatchProcessDTO();
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue