fix(用户组和权限): 记录操作日志#1006075

--bug=1006075 --user=lyh 【系统设置】-【用户组与权限】-创建用户组没有操作日志信息
https://www.tapd.cn/55049933/s/1038558
This commit is contained in:
shiziyuan9527 2021-08-24 11:42:54 +08:00 committed by 刘瑞斌
parent 110769f6cf
commit 266f1b744d
6 changed files with 56 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.Group;
import io.metersphere.base.domain.Organization;
import io.metersphere.base.domain.User;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.PermissionConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
@ -13,6 +14,7 @@ import io.metersphere.controller.request.group.EditGroupRequest;
import io.metersphere.controller.request.group.EditGroupUserRequest;
import io.metersphere.dto.GroupDTO;
import io.metersphere.dto.GroupPermissionDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.service.GroupService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RequestMapping("/user/group")
@ -50,18 +53,22 @@ public class GroupController {
@PostMapping("/add")
@RequiresPermissions(value={PermissionConstants.SYSTEM_GROUP_READ_CREATE, PermissionConstants.ORGANIZATION_GROUP_READ_CREATE}, logical = Logical.OR)
@MsAuditLog(module = "group_permission", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#request.id)", msClass = GroupService.class)
public Group addGroup(@RequestBody EditGroupRequest request) {
request.setId(UUID.randomUUID().toString());
return groupService.addGroup(request);
}
@PostMapping("/edit")
@RequiresPermissions(value={PermissionConstants.SYSTEM_GROUP_READ_EDIT, PermissionConstants.ORGANIZATION_GROUP_READ_EDIT}, logical = Logical.OR)
@MsAuditLog(module = "group_permission", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", content = "#msClass.getLogDetails(#request.id)", msClass = GroupService.class)
public void editGroup(@RequestBody EditGroupRequest request) {
groupService.editGroup(request);
}
@GetMapping("/delete/{id}")
@RequiresPermissions(value={PermissionConstants.SYSTEM_GROUP_READ_DELETE, PermissionConstants.ORGANIZATION_GROUP_READ_DELETE}, logical = Logical.OR)
@MsAuditLog(module = "group_permission", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = GroupService.class)
public void deleteGroup(@PathVariable String id) {
groupService.deleteGroup(id);
}

View File

@ -21,6 +21,7 @@ public class SystemReference {
public static Map<String, String> ldapColumns = new LinkedHashMap<>();
public static Map<String, String> mailColumns = new LinkedHashMap<>();
public static Map<String, String> baseColumns = new LinkedHashMap<>();
public static Map<String, String> groupColumns = new LinkedHashMap<>();
static {
@ -40,6 +41,7 @@ public class SystemReference {
licenseColumns.clear();
ldapColumns.clear();
mailColumns.clear();
groupColumns.clear();
userColumns.put("name", "用户名称");
userColumns.put("createUser", "创建人");
@ -142,7 +144,9 @@ public class SystemReference {
baseColumns.put("concurrency","并发数");
baseColumns.put("prometheusHost","Prometheus地址");
groupColumns.put("name", "名称");
groupColumns.put("description", "描述");
groupColumns.put("type", "所属类型");
groupColumns.put("scopeId", "全局用户组");
}
}

View File

@ -17,6 +17,10 @@ import io.metersphere.controller.request.group.EditGroupRequest;
import io.metersphere.controller.request.group.EditGroupUserRequest;
import io.metersphere.dto.*;
import io.metersphere.i18n.Translator;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.system.SystemReference;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
@ -68,6 +72,13 @@ public class GroupService {
put(UserGroupType.PROJECT, Collections.singletonList(UserGroupType.PROJECT));
}};
private static final Map<String, String> typeMap = new HashMap<String, String>(4){{
put(UserGroupType.SYSTEM, "系统");
put(UserGroupType.ORGANIZATION, "组织");
put(UserGroupType.WORKSPACE, "工作空间");
put(UserGroupType.PROJECT, "项目");
}};
public Pager<List<GroupDTO>> getGroupList(EditGroupRequest request) {
SessionUser user = SessionUtils.getUser();
List<UserGroupDTO> userGroup = extUserGroupMapper.getUserGroup(Objects.requireNonNull(user).getId());
@ -78,7 +89,7 @@ public class GroupService {
public Group addGroup(EditGroupRequest request) {
Group group = new Group();
checkGroupExist(request);
group.setId(UUID.randomUUID().toString());
group.setId(request.getId());
group.setName(request.getName());
group.setCreator(SessionUtils.getUserId());
group.setDescription(request.getDescription());
@ -518,4 +529,32 @@ public class GroupService {
}
}
}
public String getLogDetails(String id) {
Group group = groupMapper.selectByPrimaryKey(id);
if (group != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(group, SystemReference.groupColumns);
for (DetailColumn column : columns) {
if ("scopeId".equals(column.getColumnName()) && column.getOriginalValue() != null && StringUtils.isNotEmpty(column.getOriginalValue().toString())) {
if ("global".equals(column.getOriginalValue())) {
column.setOriginalValue("");
} else {
String scopeId = group.getScopeId();
Organization organization = organizationMapper.selectByPrimaryKey(scopeId);
if (organization != null) {
column.setOriginalValue("否; 所属组织:" + organization.getName());
} else {
column.setOriginalValue("");
}
}
}
if ("type".equals(column.getColumnName()) && column.getOriginalValue() != null && StringUtils.isNotEmpty(column.getOriginalValue().toString())) {
column.setOriginalValue(typeMap.get((String) column.getOriginalValue()));
}
}
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(group.getId()), null, group.getName(), group.getCreator(), columns);
return JSON.toJSONString(details);
}
return null;
}
}

View File

@ -264,7 +264,7 @@ project_file_management=Project file management
personal_information_personal_settings=Personal information personal settings
personal_information_apikeys=Personal information API Keys
auth_title=Auth
group_permission=Group
# track home
api_case=API
performance_case=PERFORMANCE

View File

@ -263,6 +263,7 @@ project_file_management=项目-文件管理
personal_information_personal_settings=个人信息-个人设置
personal_information_apikeys=个人信息-API Keys
auth_title=系统认证
group_permission=用户组与权限
# track home
api_case=接口用例

View File

@ -264,6 +264,7 @@ project_file_management=項目-文件管理
personal_information_personal_settings=個人信息-個人設置
personal_information_apikeys=個人信息-API Keys
auth_title=系统认证
group_permission=用戶組與權限
# track home
api_case=接口用例
performance_case=性能用例