refactor: 后台接口项目权限控制
This commit is contained in:
parent
b9e272d961
commit
c69640c1df
|
@ -10,6 +10,7 @@ import io.metersphere.api.service.ApiAutomationService;
|
|||
import io.metersphere.base.domain.ApiScenario;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.base.domain.UserGroup;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.OperLogConstants;
|
||||
import io.metersphere.commons.constants.PermissionConstants;
|
||||
|
@ -21,6 +22,7 @@ import io.metersphere.controller.request.ScheduleRequest;
|
|||
import io.metersphere.log.annotation.MsAuditLog;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -30,7 +32,9 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/automation")
|
||||
|
@ -42,6 +46,12 @@ public class ApiAutomationController {
|
|||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
|
||||
public Pager<List<ApiScenarioDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
|
||||
if (StringUtils.isBlank(request.getProjectId())) {
|
||||
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
|
||||
request.setFilters(new HashMap<String, List<String>>() {{
|
||||
put("project_id", sourceIds);
|
||||
}});
|
||||
}
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
return PageUtils.setPageInfo(page, apiAutomationService.list(request));
|
||||
|
|
|
@ -94,6 +94,12 @@
|
|||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key == 'project_id'">
|
||||
AND load_test.project_id IN
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
|
|
|
@ -107,6 +107,12 @@
|
|||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key=='project_id'">
|
||||
and ltr.project_id in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<otherwise>
|
||||
and ltr.trigger_mode in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
|
|
|
@ -56,6 +56,12 @@
|
|||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key == 'project_id'">
|
||||
AND p.id IN
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.UserGroup;
|
||||
import io.metersphere.commons.constants.OperLogConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
|
@ -16,12 +17,15 @@ import io.metersphere.dto.WorkspaceMemberDTO;
|
|||
import io.metersphere.log.annotation.MsAuditLog;
|
||||
import io.metersphere.service.CheckPermissionService;
|
||||
import io.metersphere.service.ProjectService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/project")
|
||||
|
@ -83,12 +87,19 @@ public class ProjectController {
|
|||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
public Pager<List<ProjectDTO>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ProjectRequest request) {
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
if (StringUtils.isBlank(request.getProjectId())) {
|
||||
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
|
||||
request.setFilters(new HashMap<String, List<String>>() {{
|
||||
put("project_id", sourceIds);
|
||||
}});
|
||||
}
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, projectService.getProjectList(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 在工作空间下与用户有关的项目
|
||||
*
|
||||
* @param request userId
|
||||
* @return List<ProjectDTO>
|
||||
*/
|
||||
|
|
|
@ -4,10 +4,12 @@ import com.github.pagehelper.Page;
|
|||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.base.domain.LoadTestReportLog;
|
||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||
import io.metersphere.base.domain.UserGroup;
|
||||
import io.metersphere.commons.constants.OperLogConstants;
|
||||
import io.metersphere.commons.constants.PermissionConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.LogDetailDTO;
|
||||
import io.metersphere.dto.ReportDTO;
|
||||
import io.metersphere.log.annotation.MsAuditLog;
|
||||
|
@ -17,12 +19,15 @@ import io.metersphere.performance.controller.request.RenameReportRequest;
|
|||
import io.metersphere.performance.controller.request.ReportRequest;
|
||||
import io.metersphere.performance.dto.LoadTestExportJmx;
|
||||
import io.metersphere.performance.service.PerformanceReportService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "performance/report")
|
||||
|
@ -34,13 +39,26 @@ public class PerformanceReportController {
|
|||
@PostMapping("/recent/{count}")
|
||||
@RequiresPermissions("PROJECT_PERFORMANCE_REPORT:READ")
|
||||
public List<ReportDTO> recentProjects(@PathVariable int count, @RequestBody ReportRequest request) {
|
||||
if (StringUtils.isBlank(request.getProjectId())) {
|
||||
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
|
||||
request.setFilters(new HashMap<String, List<String>>() {{
|
||||
put("project_id", sourceIds);
|
||||
}});
|
||||
}
|
||||
// 最近 `count` 个项目
|
||||
PageHelper.startPage(1, count);
|
||||
return performanceReportService.getRecentReportList(request);
|
||||
}
|
||||
|
||||
@PostMapping("/list/all/{goPage}/{pageSize}")
|
||||
@RequiresPermissions("PROJECT_PERFORMANCE_REPORT:READ")
|
||||
public Pager<List<ReportDTO>> getReportList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ReportRequest request) {
|
||||
if (StringUtils.isBlank(request.getProjectId())) {
|
||||
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
|
||||
request.setFilters(new HashMap<String, List<String>>() {{
|
||||
put("project_id", sourceIds);
|
||||
}});
|
||||
}
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, performanceReportService.getReportList(request));
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.LoadTest;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.base.domain.UserGroup;
|
||||
import io.metersphere.commons.constants.OperLogConstants;
|
||||
import io.metersphere.commons.constants.PermissionConstants;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
|
@ -23,9 +23,8 @@ import io.metersphere.performance.service.PerformanceTestService;
|
|||
import io.metersphere.service.CheckPermissionService;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -33,8 +32,10 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "performance")
|
||||
|
@ -55,6 +56,12 @@ public class PerformanceTestController {
|
|||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ")
|
||||
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
|
||||
if (StringUtils.isBlank(request.getProjectId())) {
|
||||
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
|
||||
request.setFilters(new HashMap<String, List<String>>() {{
|
||||
put("project_id", sourceIds);
|
||||
}});
|
||||
}
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, performanceTestService.list(request));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue