/
GroupController.java
162 lines (137 loc) · 7.17 KB
/
GroupController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package io.metersphere.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.Group;
import io.metersphere.base.domain.User;
import io.metersphere.base.domain.UserGroup;
import io.metersphere.base.domain.Workspace;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.OperLogModule;
import io.metersphere.commons.constants.PermissionConstants;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.log.annotation.MsRequestLog;
import io.metersphere.request.GroupRequest;
import io.metersphere.request.group.EditGroupRequest;
import io.metersphere.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.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.*;
@RequestMapping("/user/group")
@RestController
public class GroupController {
@Resource
private GroupService groupService;
@PostMapping("/get/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ}, logical = Logical.OR)
public Pager<List<GroupDTO>> getGroupList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest request) {
request.setGoPage(goPage);
request.setPageSize(pageSize);
return groupService.getGroupList(request);
}
@GetMapping("/get/all")
public List<GroupDTO> getAllGroup() {
SessionUser user = SessionUtils.getUser();
Optional<UserGroup> any = user.getUserGroups().stream()
.filter(ug -> (ug.getGroupId().equals(UserGroupConstants.SUPER_GROUP)))
.findAny();
if (any.isEmpty()) {
return new ArrayList<>();
}
return groupService.getAllGroup();
}
@PostMapping("/get")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ, PermissionConstants.SYSTEM_USER_READ, PermissionConstants.WORKSPACE_USER_READ}, logical = Logical.OR)
public List<Group> getGroupByType(@RequestBody EditGroupRequest request) {
return groupService.getGroupByType(request);
}
@PostMapping("/add")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ_CREATE, PermissionConstants.PROJECT_GROUP_READ_CREATE}, logical = Logical.OR)
@MsAuditLog(module = OperLogModule.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.PROJECT_GROUP_READ_EDIT}, logical = Logical.OR)
@MsAuditLog(module = OperLogModule.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.PROJECT_GROUP_READ_DELETE}, logical = Logical.OR)
@MsAuditLog(module = OperLogModule.GROUP_PERMISSION, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = GroupService.class)
public void deleteGroup(@PathVariable String id) {
groupService.deleteGroup(id);
}
@PostMapping("/permission")
public GroupPermissionDTO getGroupResource(@RequestBody Group group) {
return groupService.getGroupResource(group);
}
@PostMapping("/permission/edit")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ_SETTING_PERMISSION, PermissionConstants.PROJECT_GROUP_READ_SETTING_PERMISSION}, logical = Logical.OR)
@MsRequestLog(module = OperLogModule.GROUP_PERMISSION)
public void editGroupPermission(@RequestBody EditGroupRequest editGroupRequest) {
groupService.editGroupPermission(editGroupRequest);
}
@GetMapping("/all/{userId}")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ_EDIT)
public List<Map<String, Object>> getAllUserGroup(@PathVariable("userId") String userId) {
return groupService.getAllUserGroup(userId);
}
@PostMapping("/list")
public List<Group> getGroupsByType(@RequestBody GroupRequest request) {
return groupService.getGroupsByType(request);
}
@GetMapping("/list/ws/{workspaceId}/{userId}")
public List<Group> getWorkspaceMemberGroups(@PathVariable String workspaceId, @PathVariable String userId) {
return groupService.getWorkspaceMemberGroups(workspaceId, userId);
}
@GetMapping("/list/project/{projectId}/{userId}")
public List<Group> getProjectMemberGroups(@PathVariable String projectId, @PathVariable String userId) {
return groupService.getProjectMemberGroups(projectId, userId);
}
@GetMapping("/ws/{userId}")
public List<Workspace> getWorkspace(@PathVariable String userId) {
return groupService.getWorkspace(userId);
}
@GetMapping("/{type}/{id}")
public List<?> getResource(@PathVariable String type, @PathVariable String id) {
return groupService.getResource(type, id);
}
@PostMapping("/user/{goPage}/{pageSize}")
@RequiresPermissions(value = {PermissionConstants.SYSTEM_GROUP_READ}, logical = Logical.OR)
public Pager<List<User>> getGroupUser(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EditGroupRequest editGroupRequest) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, groupService.getGroupUser(editGroupRequest));
}
@GetMapping("/rm/{userId}/{groupId}")
@RequiresPermissions(PermissionConstants.SYSTEM_GROUP_READ)
public void removeGroupMember(@PathVariable String userId, @PathVariable String groupId) {
groupService.removeGroupMember(userId, groupId);
}
@GetMapping("/source/{userId}/{groupId}")
public List<?> getGroupSource(@PathVariable String userId, @PathVariable String groupId) {
return groupService.getGroupSource(userId, groupId);
}
@PostMapping("/add/member")
@MsRequestLog(module = OperLogModule.GROUP_PERMISSION)
public void addGroupUser(@RequestBody EditGroupUserRequest request) {
groupService.addGroupUser(request);
}
@PostMapping("/edit/member")
@MsRequestLog(module = OperLogModule.GROUP_PERMISSION)
public void editGroupUser(@RequestBody EditGroupUserRequest request) {
groupService.editGroupUser(request);
}
}