refactor(系统管理): 修改组织与项目权限

This commit is contained in:
song-cc-rock 2023-07-06 18:28:27 +08:00 committed by 刘瑞斌
parent b04f23615f
commit cc2a6b9140
6 changed files with 33 additions and 38 deletions

View File

@ -26,10 +26,11 @@ public class PermissionConstants {
public static final String SYSTEM_USER_READ_DELETE = "SYSTEM_USER:READ+DELETE";
public static final String SYSTEM_USER_READ_UPDATE_PASSWORD = "SYSTEM_USER:READ+UPDATE_PASSWORD";
public static final String SYSTEM_ORGANIZATION_READ = "SYSTEM_ORGANIZATION:READ";
public static final String SYSTEM_ORGANIZATION_READ_ADD = "SYSTEM_ORGANIZATION:READ+ADD";
public static final String SYSTEM_ORGANIZATION_READ_UPDATE = "SYSTEM_ORGANIZATION:READ+UPDATE";
public static final String SYSTEM_ORGANIZATION_READ_DELETE = "SYSTEM_ORGANIZATION:READ+DELETE";
public static final String SYSTEM_ORGANIZATION_PROJECT_READ = "SYSTEM_ORGANIZATION_PROJECT:READ";
public static final String SYSTEM_ORGANIZATION_PROJECT_READ_ADD = "SYSTEM_ORGANIZATION_PROJECT:READ+ADD";
public static final String SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE = "SYSTEM_ORGANIZATION_PROJECT:READ+UPDATE";
public static final String SYSTEM_ORGANIZATION_PROJECT_READ_DELETE = "SYSTEM_ORGANIZATION_PROJECT:READ+DELETE";
public static final String SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER = "SYSTEM_ORGANIZATION_PROJECT:READ+RECOVER";
public static final String SYSTEM_TEST_RESOURCE_POOL_READ = "SYSTEM_TEST_RESOURCE_POOL:READ";
public static final String SYSTEM_TEST_RESOURCE_POOL_READ_ADD = "SYSTEM_TEST_RESOURCE_POOL:READ+ADD";
@ -62,13 +63,6 @@ public class PermissionConstants {
public static final String ORGANIZATION_USER_READ_UPDATE = "ORGANIZATION_USER:READ+UPDATE";
public static final String ORGANIZATION_USER_READ_DELETE = "ORGANIZATION_USER:READ+DELETE";
public static final String SYSTEM_PROJECT_READ = "SYSTEM_PROJECT:READ";
public static final String SYSTEM_PROJECT_READ_ADD = "SYSTEM_PROJECT:READ+ADD";
public static final String SYSTEM_PROJECT_READ_UPDATE = "SYSTEM_PROJECT:READ+UPDATE";
public static final String SYSTEM_PROJECT_READ_DELETE = "SYSTEM_PROJECT:READ+DELETE";
public static final String SYSTEM_PROJECT_READ_ADD_USER = "SYSTEM_PROJECT:READ+ADD_USER";
public static final String SYSTEM_PROJECT_READ_DELETE_USER = "SYSTEM_PROJECT:READ+DELETE_USER";
public static final String ORGANIZATION_PROJECT_ENVIRONMENT_READ = "ORGANIZATION_PROJECT_ENVIRONMENT:READ";
public static final String ORGANIZATION_PROJECT_ENVIRONMENT_READ_ADD = "ORGANIZATION_PROJECT_ENVIRONMENT:READ+ADD";
public static final String ORGANIZATION_PROJECT_ENVIRONMENT_READ_UPDATE = "ORGANIZATION_PROJECT_ENVIRONMENT:READ+UPDATE";

View File

@ -15,6 +15,9 @@ import io.metersphere.system.request.ProjectRequest;
import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SystemProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -38,7 +41,7 @@ public class OrganizationController {
@PostMapping("/list")
@Operation(summary = "获取组织列表")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public Pager<List<OrganizationDTO>> list(@Validated @RequestBody OrganizationRequest organizationRequest) {
Page<Object> page = PageHelper.startPage(organizationRequest.getCurrent(), organizationRequest.getPageSize());
return PageUtils.setPageInfo(page, organizationService.list(organizationRequest));
@ -46,14 +49,14 @@ public class OrganizationController {
@PostMapping("/list-all")
@Operation(summary = "获取系统所有组织")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<OrganizationDTO> listAll() {
return organizationService.listAll();
}
@PostMapping("/list-member")
@Operation(summary = "获取组织成员")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ)
@RequiresPermissions(value = {PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, PermissionConstants.SYSTEM_USER_READ})
public Pager<List<UserExtend>> listMember(@Validated @RequestBody OrganizationRequest organizationRequest) {
Page<Object> page = PageHelper.startPage(organizationRequest.getCurrent(), organizationRequest.getPageSize());
return PageUtils.setPageInfo(page, organizationService.listMember(organizationRequest));
@ -61,29 +64,32 @@ public class OrganizationController {
@PostMapping("/add-member")
@Operation(summary = "添加组织成员")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
public void addMember(@Validated @RequestBody OrganizationMemberRequest organizationMemberRequest) {
organizationMemberRequest.setCreateUserId(SessionUtils.getUserId());
organizationService.addMember(organizationMemberRequest);
organizationService.addMember(organizationMemberRequest, SessionUtils.getUserId());
}
@GetMapping("/remove-member/{organizationId}/{userId}")
@Operation(summary = "删除组织成员")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_READ)
@Parameters({
@Parameter(name = "organizationId", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)),
@Parameter(name = "userId", description = "用户ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
})
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
public void removeMember(@PathVariable String organizationId, @PathVariable String userId) {
organizationService.removeMember(organizationId, userId);
}
@GetMapping("/default")
@Operation(summary = "获取系统默认组织")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public OrganizationDTO getDefault() {
return organizationService.getDefault();
}
@PostMapping("/list-project")
@Operation(summary = "获取组织下的项目列表")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public Pager<List<ProjectDTO>> listProject(@Validated @RequestBody ProjectRequest projectRequest) {
Page<Object> page = PageHelper.startPage(projectRequest.getCurrent(), projectRequest.getPageSize());
return PageUtils.setPageInfo(page, systemProjectService.getProjectList(projectRequest));

View File

@ -38,7 +38,7 @@ public class SystemProjectController {
private SystemProjectService systemProjectService;
@PostMapping("/add")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_ADD)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_ADD)
@Log(type = OperationLogType.ADD, module = OperationLogModule.SYSTEM_PROJECT, details = "#project.name")
@Operation(summary = "添加项目")
public Project addProject(@RequestBody @Validated({Created.class}) AddProjectRequest project) {
@ -48,13 +48,13 @@ public class SystemProjectController {
@GetMapping("/get/{id}")
@Operation(summary = "根据ID获取项目信息")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public Project getProject(@PathVariable @NotBlank String id) {
return systemProjectService.get(id);
}
@PostMapping("/page")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
@Operation(summary = "获取项目列表")
public Pager<List<ProjectDTO>> getProjectList(@Validated @RequestBody ProjectRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
@ -66,13 +66,13 @@ public class SystemProjectController {
@Log(type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_PROJECT,
sourceId = "#project.id", details = "#project.name")
@Operation(summary = "更新项目信息")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_UPDATE)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
public Project updateProject(@RequestBody @Validated({Updated.class}) UpdateProjectRequest project) {
return systemProjectService.update(project, SessionUtils.getUserId());
}
@GetMapping("/delete/{id}")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_DELETE)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_DELETE)
@Operation(summary = "删除项目")
@Log(isBefore = true, type = OperationLogType.DELETE, module = OperationLogModule.SYSTEM_PROJECT,
details = "#msClass.getLogDetails(#id)", msClass = SystemProjectService.class, sourceId = "#id")
@ -81,7 +81,7 @@ public class SystemProjectController {
}
@GetMapping("/revoke/{id}")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_DELETE)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
@Log(isBefore = true, type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_PROJECT,
details = "#msClass.getLogDetails(#id)", msClass = SystemProjectService.class, sourceId = "#id")
public int revokeProject(@PathVariable String id) {
@ -89,7 +89,7 @@ public class SystemProjectController {
}
@PostMapping("/member-list")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_ADD_USER)
@RequiresPermissions(value = {PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, PermissionConstants.SYSTEM_USER_READ})
@Operation(summary = "获取项目下成员列表")
public Pager<List<UserExtend>> getProjectMember(@Validated @RequestBody ProjectMemberRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
@ -98,7 +98,7 @@ public class SystemProjectController {
}
@PostMapping("/add-member")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_ADD_USER)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
@Operation(summary = "添加项目成员")
public void addProjectMember(@Validated @RequestBody ProjectAddMemberRequest request) {
systemProjectService.addProjectMember(request, SessionUtils.getUserId(), false);
@ -106,7 +106,7 @@ public class SystemProjectController {
@GetMapping("/remove-member/{projectId}/{userId}")
@Operation(summary = "移除项目成员")
@RequiresPermissions(PermissionConstants.SYSTEM_PROJECT_READ_DELETE_USER)
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
@Log(isBefore = true, type = OperationLogType.DELETE, module = OperationLogModule.SYSTEM_PROJECT_MEMBER, sourceId = "#projectId",
details = "#msClass.getLogs(#userId)", msClass = SystemProjectService.class)
public int removeProjectMember(@PathVariable String projectId, @PathVariable String userId) {

View File

@ -27,10 +27,4 @@ public class OrganizationMemberRequest implements Serializable {
@Schema(title = "成员ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{member.id.not_null}")
private List<String> memberIds;
/**
* 创建人ID(组织-添加成员操作)
*/
@Schema(title = "创建人ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String createUserId;
}

View File

@ -42,8 +42,9 @@ public interface OrganizationService {
/**
* 添加组织成员
* @param organizationMemberRequest 添加组织成员请求参数
* @param createUserId 创建人ID
*/
void addMember(OrganizationMemberRequest organizationMemberRequest);
void addMember(OrganizationMemberRequest organizationMemberRequest, String createUserId);
/**
* 移除组织成员

View File

@ -65,7 +65,7 @@ public class OrganizationServiceImpl implements OrganizationService{
}
@Override
public void addMember(OrganizationMemberRequest organizationMemberRequest) {
public void addMember(OrganizationMemberRequest organizationMemberRequest, String createUserId) {
Organization organization = organizationMapper.selectByPrimaryKey(organizationMemberRequest.getOrganizationId());
if (organization == null) {
throw new MSException(Translator.get("organization_not_exist"));
@ -77,7 +77,7 @@ public class OrganizationServiceImpl implements OrganizationService{
userRoleRelation.setSourceId(organizationMemberRequest.getOrganizationId());
userRoleRelation.setRoleId(InternalUserRole.ORG_MEMBER.getValue());
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setCreateUser(organizationMemberRequest.getCreateUserId());
userRoleRelation.setCreateUser(createUserId);
userRoleRelationMapper.insertSelective(userRoleRelation);
}
}