feat(系统设置): 添加组织-用户组权限日志

This commit is contained in:
song-cc-rock 2023-07-17 18:27:28 +08:00 committed by 刘瑞斌
parent 58707ad414
commit 14355b0562
6 changed files with 141 additions and 8 deletions

View File

@ -9,6 +9,7 @@ public class OperationLogModule {
public static final String SYSTEM_USER_ROLE = "SYSTEM_USER_ROLE";
public static final String SYSTEM_USER_ROLE_RELATION = "SYSTEM_USER_ROLE_RELATION";
public static final String SYSTEM_ORGANIZATION = "SYSTEM_ORGANIZATION";
public static final String ORGANIZATION_USER_ROLE = "ORGANIZATION_USER_ROLE";
public static final String ORGANIZATION_TEMPLATE_SETTINGS = "ORGANIZATION_TEMPLATE_SETTINGS";
public static final String ORGANIZATION_MESSAGE_SETTINGS = "ORGANIZATION_MESSAGE_SETTINGS";
public static final String ORGANIZATION_TEMPLATE_SETTINGS_FIELD = "ORGANIZATION_TEMPLATE_SETTINGS_FIELD";

View File

@ -5,6 +5,8 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.PermissionDefinitionItem;
import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
import io.metersphere.sdk.log.annotation.Log;
import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
@ -14,6 +16,7 @@ import io.metersphere.system.domain.UserRole;
import io.metersphere.system.request.OrganizationUserRoleEditRequest;
import io.metersphere.system.request.OrganizationUserRoleMemberEditRequest;
import io.metersphere.system.request.OrganizationUserRoleMemberRequest;
import io.metersphere.system.service.OrganizationUserRoleLogService;
import io.metersphere.system.service.OrganizationUserRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -45,6 +48,7 @@ public class OrganizationUserRoleController {
@PostMapping("/add")
@Operation(summary = "添加组织用户组")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_ADD)
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = OrganizationUserRoleLogService.class)
public UserRole add(@Validated @RequestBody OrganizationUserRoleEditRequest request) {
UserRole userRole = new UserRole();
userRole.setCreateUser(SessionUtils.getUserId());
@ -55,6 +59,7 @@ public class OrganizationUserRoleController {
@PostMapping("/update")
@Operation(summary = "修改组织用户组")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = OrganizationUserRoleLogService.class)
public UserRole update(@Validated @RequestBody OrganizationUserRoleEditRequest request) {
UserRole userRole = new UserRole();
BeanUtils.copyBean(userRole, request);
@ -64,6 +69,7 @@ public class OrganizationUserRoleController {
@GetMapping("/delete/{id}")
@Operation(summary = "删除组织用户组")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_DELETE)
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = OrganizationUserRoleLogService.class)
public void delete(@PathVariable String id) {
organizationUserRoleService.delete(id);
}
@ -78,6 +84,7 @@ public class OrganizationUserRoleController {
@PostMapping("/permission/update")
@Operation(summary = "编辑组织用户组对应的权限配置")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePermissionSettingLog(#request)", msClass = OrganizationUserRoleLogService.class)
public void updatePermissionSetting(@Validated @RequestBody PermissionSettingUpdateRequest request) {
organizationUserRoleService.updatePermissionSetting(request);
}
@ -93,6 +100,7 @@ public class OrganizationUserRoleController {
@PostMapping("/add-member")
@Operation(summary = "添加组织用户组成员")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.editMemberLog(#request)", msClass = OrganizationUserRoleLogService.class)
public void addMember(@Validated @RequestBody OrganizationUserRoleMemberEditRequest request) {
organizationUserRoleService.addMember(request, SessionUtils.getUserId());
}
@ -100,6 +108,7 @@ public class OrganizationUserRoleController {
@PostMapping("/remove-member")
@Operation(summary = "删除组织用户组成员")
@RequiresPermissions(PermissionConstants.ORGANIZATION_USER_ROLE_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.editMemberLog(#request)", msClass = OrganizationUserRoleLogService.class)
public void removeMember(@Validated @RequestBody OrganizationUserRoleMemberEditRequest request) {
organizationUserRoleService.removeMember(request);
}

View File

@ -14,8 +14,11 @@ import java.util.List;
@Data
public class OrganizationEditRequest implements Serializable {
@Schema(title = "组织ID")
private String id;
@Schema(title = "组织名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{organization.name.not_blank}", groups = {Created.class})
@NotBlank(message = "{organization.name.not_blank}", groups = {Created.class, Updated.class})
@Size(min = 1, max = 100, message = "{organization.name.length_range}", groups = {Created.class, Updated.class})
private String name;
@ -23,6 +26,6 @@ public class OrganizationEditRequest implements Serializable {
private String description;
@Schema(title = "成员ID集合")
@NotEmpty(groups = {Created.class}, message = "{member.id.not_empty}")
@NotEmpty(message = "{member.id.not_empty}", groups = {Created.class, Updated.class})
private List<String> memberIds;
}

View File

@ -91,10 +91,6 @@ public class OrganizationService{
}
UserRoleRelationExample example = new UserRoleRelationExample();
example.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId);
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
if (CollectionUtils.isEmpty(userRoleRelations)) {
throw new MSException(Translator.get("organization_member_not_exist"));
}
userRoleRelationMapper.deleteByExample(example);
}

View File

@ -0,0 +1,126 @@
package io.metersphere.system.service;
import io.metersphere.constants.HttpMethodConstants;
import io.metersphere.sdk.dto.LogDTO;
import io.metersphere.sdk.dto.request.PermissionSettingUpdateRequest;
import io.metersphere.sdk.log.constants.OperationLogModule;
import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.UserRole;
import io.metersphere.system.mapper.UserRoleMapper;
import io.metersphere.system.request.OrganizationUserRoleEditRequest;
import io.metersphere.system.request.OrganizationUserRoleMemberEditRequest;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(rollbackFor = Exception.class)
public class OrganizationUserRoleLogService {
@Resource
private UserRoleMapper userRoleMapper;
private static final String PRE_URI = "/user/role/organization";
/**
* 新增组织-用户组
* @param request 接口请求参数
* @return 日志详情
*/
public LogDTO addLog(OrganizationUserRoleEditRequest request) {
LogDTO dto = new LogDTO(
"",
request.getScopeId(),
null,
null,
OperationLogType.ADD.name(),
OperationLogModule.ORGANIZATION_USER_ROLE,
request.getName());
dto.setPath(PRE_URI + "/add");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(request));
return dto;
}
/**
* 更新组织-用户组
* @param request 接口请求参数
* @return 日志详情
*/
public LogDTO updateLog(OrganizationUserRoleEditRequest request) {
LogDTO dto = new LogDTO(
"",
request.getScopeId(),
null,
null,
OperationLogType.UPDATE.name(),
OperationLogModule.ORGANIZATION_USER_ROLE,
request.getName());
dto.setPath(PRE_URI + "/update");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(request));
return dto;
}
/**
* 删除组织-用户组
* @param id 接口请求参数
* @return 日志详情
*/
public LogDTO deleteLog(String id) {
UserRole userRole = userRoleMapper.selectByPrimaryKey(id);
LogDTO dto = new LogDTO(
"",
userRole.getScopeId(),
null,
null,
OperationLogType.DELETE.name(),
OperationLogModule.ORGANIZATION_USER_ROLE,
userRole.getName());
dto.setPath(PRE_URI + "/delete");
dto.setMethod(HttpMethodConstants.GET.name());
dto.setOriginalValue(JSON.toJSONBytes(userRole));
return dto;
}
/**
* 更新组织-用户组-权限
* @param request 接口请求参数
* @return 日志详情
*/
public LogDTO updatePermissionSettingLog(PermissionSettingUpdateRequest request) {
LogDTO dto = getLog(request.getUserRoleId());
dto.setType(OperationLogType.UPDATE.name());
dto.setPath(PRE_URI + "/update");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(request));
return dto;
}
/**
* 更新组织-用户组-成员
* @param request 接口请求参数
* @return 日志详情
*/
public LogDTO editMemberLog(OrganizationUserRoleMemberEditRequest request) {
LogDTO dto = getLog(request.getUserRoleId());
dto.setType(OperationLogType.UPDATE.name());
dto.setPath(PRE_URI + "/update");
dto.setMethod(HttpMethodConstants.POST.name());
dto.setOriginalValue(JSON.toJSONBytes(request));
return dto;
}
private LogDTO getLog(String roleId) {
UserRole userRole = userRoleMapper.selectByPrimaryKey(roleId);
return new LogDTO(
"",
userRole.getScopeId(),
null,
null,
null,
OperationLogModule.ORGANIZATION_USER_ROLE,
userRole.getName());
}
}

View File

@ -240,8 +240,6 @@ public class OrganizationControllerTests extends BaseTest{
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-x/admin", status().is5xxServerError());
// 用户不存在
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-3/admin-x", status().is5xxServerError());
// 用户组织关系不存在
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-4/default-admin", status().is5xxServerError());
}
@Test