refactor: 使用前端session来保存当前项目、工作空间、组织的信息,切换后可以在不同的页面使用

This commit is contained in:
Captain.B 2021-06-10 19:06:07 +08:00 committed by 刘瑞斌
parent 6a0561462e
commit 9bae1ef89e
32 changed files with 116 additions and 111 deletions

View File

@ -49,7 +49,6 @@ public class APIReportController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APIReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) { public Pager<List<APIReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiReportService.list(request)); return PageUtils.setPageInfo(page, apiReportService.list(request));
} }

View File

@ -36,7 +36,6 @@ public class APIScenarioReportController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APIScenarioReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) { public Pager<List<APIScenarioReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiReportService.list(request)); return PageUtils.setPageInfo(page, apiReportService.list(request));
} }

View File

@ -82,8 +82,6 @@ public class APITestController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APITestResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPITestRequest request) { public Pager<List<APITestResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPITestRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(SessionUtils.getCurrentProjectId());
return PageUtils.setPageInfo(page, apiTestService.list(request)); return PageUtils.setPageInfo(page, apiTestService.list(request));
} }

View File

@ -53,7 +53,7 @@ public class ApiAutomationController {
}}); }});
} }
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiAutomationService.list(request)); return PageUtils.setPageInfo(page, apiAutomationService.list(request));
} }
@ -80,7 +80,6 @@ public class ApiAutomationController {
@RequiresPermissions("PROJECT_API_SCENARIO:READ") @RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<ApiScenarioDTO> list(@PathVariable String projectId) { public List<ApiScenarioDTO> list(@PathVariable String projectId) {
ApiScenarioRequest request = new ApiScenarioRequest(); ApiScenarioRequest request = new ApiScenarioRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(projectId); request.setProjectId(projectId);
return apiAutomationService.list(request); return apiAutomationService.list(request);
} }

View File

@ -64,21 +64,18 @@ public class ApiDefinitionController {
@RequiresPermissions("PROJECT_API_DEFINITION:READ") @RequiresPermissions("PROJECT_API_DEFINITION:READ")
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.list(request)); return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
} }
@PostMapping("/list/relevance/{goPage}/{pageSize}") @PostMapping("/list/relevance/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> listRelevance(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { public Pager<List<ApiDefinitionResult>> listRelevance(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.listRelevance(request)); return PageUtils.setPageInfo(page, apiDefinitionService.listRelevance(request));
} }
@PostMapping("/list/relevance/review/{goPage}/{pageSize}") @PostMapping("/list/relevance/review/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> listRelevanceReview(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { public Pager<List<ApiDefinitionResult>> listRelevanceReview(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.listRelevanceReview(request)); return PageUtils.setPageInfo(page, apiDefinitionService.listRelevanceReview(request));
} }

View File

@ -8,15 +8,11 @@ import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiTestCase; import io.metersphere.base.domain.ApiTestCase;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.service.TestPlanApiCaseService; import io.metersphere.track.service.TestPlanApiCaseService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -35,14 +31,12 @@ public class ApiTestCaseController {
@PostMapping("/list") @PostMapping("/list")
public List<ApiTestCaseResult> list(@RequestBody ApiTestCaseRequest request) { public List<ApiTestCaseResult> list(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return apiTestCaseService.list(request); return apiTestCaseService.list(request);
} }
@GetMapping("/findById/{id}") @GetMapping("/findById/{id}")
public ApiTestCaseResult single(@PathVariable String id) { public ApiTestCaseResult single(@PathVariable String id) {
ApiTestCaseRequest request = new ApiTestCaseRequest(); ApiTestCaseRequest request = new ApiTestCaseRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setId(id); request.setId(id);
List<ApiTestCaseResult> list = apiTestCaseService.list(request); List<ApiTestCaseResult> list = apiTestCaseService.list(request);
if (!list.isEmpty()) { if (!list.isEmpty()) {
@ -62,28 +56,24 @@ public class ApiTestCaseController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ApiTestCaseDTO>> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { public Pager<List<ApiTestCaseDTO>> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request)); return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request));
} }
@GetMapping("/list/{projectId}") @GetMapping("/list/{projectId}")
public List<ApiTestCaseDTO> list(@PathVariable String projectId) { public List<ApiTestCaseDTO> list(@PathVariable String projectId) {
ApiTestCaseRequest request = new ApiTestCaseRequest(); ApiTestCaseRequest request = new ApiTestCaseRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(projectId); request.setProjectId(projectId);
return apiTestCaseService.listSimple(request); return apiTestCaseService.listSimple(request);
} }
@PostMapping("/get/request") @PostMapping("/get/request")
public Map<String, String> listSimple(@RequestBody ApiTestCaseRequest request) { public Map<String, String> listSimple(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return apiTestCaseService.getRequest(request); return apiTestCaseService.getRequest(request);
} }
@PostMapping("/get/caseBLOBs/request") @PostMapping("/get/caseBLOBs/request")
public List<ApiTestCaseInfo> getCaseBLOBs(@RequestBody ApiTestCaseRequest request) { public List<ApiTestCaseInfo> getCaseBLOBs(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
List<ApiTestCaseInfo> returnList = apiTestCaseService.findApiTestCaseBLOBs(request); List<ApiTestCaseInfo> returnList = apiTestCaseService.findApiTestCaseBLOBs(request);
return returnList; return returnList;
} }

View File

@ -49,13 +49,11 @@ public class APIReportService {
public List<APIReportResult> list(QueryAPIReportRequest request) { public List<APIReportResult> list(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestReportMapper.list(request); return extApiTestReportMapper.list(request);
} }
public List<APIReportResult> recentTest(QueryAPIReportRequest request) { public List<APIReportResult> recentTest(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestReportMapper.list(request); return extApiTestReportMapper.list(request);
} }

View File

@ -77,7 +77,6 @@ public class APITestService {
public List<APITestResult> recentTest(QueryAPITestRequest request) { public List<APITestResult> recentTest(QueryAPITestRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestMapper.list(request); return extApiTestMapper.list(request);
} }
@ -412,8 +411,8 @@ public class APITestService {
ApiTestExample example = new ApiTestExample(); ApiTestExample example = new ApiTestExample();
ApiTestExample.Criteria criteria = example.createCriteria(); ApiTestExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(resourceIds); criteria.andIdIn(resourceIds);
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) { if (StringUtils.isNotBlank(request.getProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId()); criteria.andProjectIdEqualTo(request.getProjectId());
} }
List<ApiTest> apiTests = apiTestMapper.selectByExample(example); List<ApiTest> apiTests = apiTestMapper.selectByExample(example);
Map<String, String> apiTestMap = apiTests.stream().collect(Collectors.toMap(ApiTest::getId, ApiTest::getName)); Map<String, String> apiTestMap = apiTests.stream().collect(Collectors.toMap(ApiTest::getId, ApiTest::getName));

View File

@ -87,7 +87,6 @@ public class ProjectController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ProjectDTO>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ProjectRequest request) { public Pager<List<ProjectDTO>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ProjectRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
if (StringUtils.isBlank(request.getProjectId())) { if (StringUtils.isBlank(request.getProjectId())) {
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList()); List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
request.setFilters(new HashMap<String, List<String>>() {{ request.setFilters(new HashMap<String, List<String>>() {{
@ -106,7 +105,6 @@ public class ProjectController {
*/ */
@PostMapping("/list/related") @PostMapping("/list/related")
public List<ProjectDTO> getUserProject(@RequestBody ProjectRequest request) { public List<ProjectDTO> getUserProject(@RequestBody ProjectRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return projectService.getUserProject(request); return projectService.getUserProject(request);
} }

View File

@ -32,8 +32,7 @@ public class WorkspaceController {
@PostMapping("add") @PostMapping("add")
@MsAuditLog(module = "system_workspace", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#workspace.id)", msClass = WorkspaceService.class) @MsAuditLog(module = "system_workspace", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#workspace.id)", msClass = WorkspaceService.class)
public Workspace addWorkspace(@RequestBody Workspace workspace) { public Workspace addWorkspace(@RequestBody Workspace workspace) {
String currentOrganizationId = SessionUtils.getCurrentOrganizationId(); organizationService.checkOrgOwner(workspace.getOrganizationId());
organizationService.checkOrgOwner(currentOrganizationId);
return workspaceService.saveWorkspace(workspace); return workspaceService.saveWorkspace(workspace);
} }
@ -78,7 +77,6 @@ public class WorkspaceController {
@PostMapping("list/{goPage}/{pageSize}") @PostMapping("list/{goPage}/{pageSize}")
public Pager<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) { public Pager<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) {
request.setOrganizationId(SessionUtils.getCurrentOrganizationId());
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request)); return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request));
} }

View File

@ -25,7 +25,6 @@ public class OperatingLogController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<OperatingLogDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody OperatingLogRequest request) { public Pager<List<OperatingLogDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody OperatingLogRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, operatingLogService.list(request)); return PageUtils.setPageInfo(page, operatingLogService.list(request));
} }

View File

@ -61,8 +61,10 @@ public class WorkspaceService {
MSException.throwException(Translator.get("workspace_name_is_null")); MSException.throwException(Translator.get("workspace_name_is_null"));
} }
// set organization id // set organization id
if (StringUtils.isBlank(workspace.getOrganizationId())) {
String currentOrgId = SessionUtils.getCurrentOrganizationId(); String currentOrgId = SessionUtils.getCurrentOrganizationId();
workspace.setOrganizationId(currentOrgId); workspace.setOrganizationId(currentOrgId);
}
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();

View File

@ -34,7 +34,6 @@ public class TestCaseReviewApiCaseController {
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REVIEW_READ_RELEVANCE_OR_CANCEL) @RequiresPermissions(PermissionConstants.PROJECT_TRACK_REVIEW_READ_RELEVANCE_OR_CANCEL)
public Pager<List<ApiTestCaseDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { public Pager<List<ApiTestCaseDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testCaseReviewApiCaseService.relevanceList(request)); return PageUtils.setPageInfo(page, testCaseReviewApiCaseService.relevanceList(request));
} }

View File

@ -33,7 +33,6 @@ public class TestCaseReviewScenarioCaseController {
@PostMapping("/relevance/list/{goPage}/{pageSize}") @PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testCaseReviewScenarioCaseService.relevanceList(request)); return PageUtils.setPageInfo(page, testCaseReviewScenarioCaseService.relevanceList(request));
} }

View File

@ -49,8 +49,6 @@ public class TestPlanController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_TRACK_PLAN:READ") @RequiresPermissions("PROJECT_TRACK_PLAN:READ")
public Pager<List<TestPlanDTOWithMetric>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) { public Pager<List<TestPlanDTOWithMetric>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanService.listTestPlan(request)); return PageUtils.setPageInfo(page, testPlanService.listTestPlan(request));
} }

View File

@ -32,8 +32,6 @@ public class TestPlanReportController {
private TestPlanReportService testPlanReportService; private TestPlanReportService testPlanReportService;
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<TestPlanReportDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanReportRequest request) { public Pager<List<TestPlanReportDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanReportRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanReportService.list(request)); return PageUtils.setPageInfo(page, testPlanReportService.list(request));
} }

View File

@ -41,7 +41,6 @@ public class TestPlanScenarioCaseController {
@PostMapping("/relevance/list/{goPage}/{pageSize}") @PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testPlanScenarioCaseService.relevanceList(request)); return PageUtils.setPageInfo(page, testPlanScenarioCaseService.relevanceList(request));
} }

View File

@ -114,7 +114,9 @@ public class TestCaseReviewService {
reviewRequest.setUpdateTime(System.currentTimeMillis()); reviewRequest.setUpdateTime(System.currentTimeMillis());
reviewRequest.setCreator(SessionUtils.getUser().getId());//创建人 reviewRequest.setCreator(SessionUtils.getUser().getId());//创建人
reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name());
if (StringUtils.isBlank(reviewRequest.getProjectId())) {
reviewRequest.setProjectId(SessionUtils.getCurrentProjectId()); reviewRequest.setProjectId(SessionUtils.getCurrentProjectId());
}
testCaseReviewMapper.insert(reviewRequest); testCaseReviewMapper.insert(reviewRequest);
// 发送通知 // 发送通知
String context = getReviewContext(reviewRequest, NoticeConstants.Event.CREATE); String context = getReviewContext(reviewRequest, NoticeConstants.Event.CREATE);
@ -496,7 +498,6 @@ public class TestCaseReviewService {
} else { } else {
request.setReviewerId(user.getId()); request.setReviewerId(user.getId());
} }
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(SessionUtils.getCurrentProjectId()); request.setProjectId(SessionUtils.getCurrentProjectId());
request.setReviewIds(extTestReviewCaseMapper.findRelateTestReviewId(user.getId(), SessionUtils.getCurrentWorkspaceId(), user.getLastProjectId())); request.setReviewIds(extTestReviewCaseMapper.findRelateTestReviewId(user.getId(), SessionUtils.getCurrentWorkspaceId(), user.getLastProjectId()));

View File

@ -406,9 +406,8 @@ public class TestCaseService {
TestCaseExample testCaseExample = new TestCaseExample(); TestCaseExample testCaseExample = new TestCaseExample();
TestCaseExample.Criteria criteria = testCaseExample.createCriteria(); TestCaseExample.Criteria criteria = testCaseExample.createCriteria();
criteria.andMaintainerEqualTo(request.getUserId()); criteria.andMaintainerEqualTo(request.getUserId());
String projectId = SessionUtils.getCurrentProjectId(); if (StringUtils.isNotBlank(request.getProjectId())) {
if (StringUtils.isNotBlank(projectId)) { criteria.andProjectIdEqualTo(request.getProjectId());
criteria.andProjectIdEqualTo(projectId);
testCaseExample.setOrderByClause("update_time desc, sort desc"); testCaseExample.setOrderByClause("update_time desc, sort desc");
return testCaseMapper.selectByExample(testCaseExample); return testCaseMapper.selectByExample(testCaseExample);
} }

View File

@ -149,7 +149,9 @@ public class TestPlanService {
testPlan.setCreateTime(System.currentTimeMillis()); testPlan.setCreateTime(System.currentTimeMillis());
testPlan.setUpdateTime(System.currentTimeMillis()); testPlan.setUpdateTime(System.currentTimeMillis());
testPlan.setCreator(SessionUtils.getUser().getId()); testPlan.setCreator(SessionUtils.getUser().getId());
if (StringUtils.isBlank(testPlan.getProjectId())) {
testPlan.setProjectId(SessionUtils.getCurrentProjectId()); testPlan.setProjectId(SessionUtils.getCurrentProjectId());
}
testPlanMapper.insert(testPlan); testPlanMapper.insert(testPlan);
List<String> userIds = new ArrayList<>(); List<String> userIds = new ArrayList<>();
@ -172,7 +174,7 @@ public class TestPlanService {
public List<TestPlan> getTestPlanByName(String name) { public List<TestPlan> getTestPlanByName(String name) {
TestPlanExample example = new TestPlanExample(); TestPlanExample example = new TestPlanExample();
example.createCriteria().andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId()) example.createCriteria()
.andProjectIdEqualTo(SessionUtils.getCurrentProjectId()) .andProjectIdEqualTo(SessionUtils.getCurrentProjectId())
.andNameEqualTo(name); .andNameEqualTo(name);
return testPlanMapper.selectByExample(example); return testPlanMapper.selectByExample(example);
@ -385,9 +387,8 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listTestPlan(QueryTestPlanRequest request) { public List<TestPlanDTOWithMetric> listTestPlan(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
String projectId = SessionUtils.getCurrentProjectId(); if (StringUtils.isNotBlank(request.getProjectId())) {
if (StringUtils.isNotBlank(projectId)) { request.setProjectId(request.getProjectId());
request.setProjectId(projectId);
} }
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request); List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
testPlans.forEach(item -> { testPlans.forEach(item -> {
@ -990,7 +991,7 @@ public class TestPlanService {
APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(), APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(),
planScenarioID + ":" + request.getTestPlanReportId(), planScenarioID + ":" + request.getTestPlanReportId(),
item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
request.getExecuteType(), item.getProjectId(), request.getReportUserID(),request.getConfig()); request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig());
apiScenarioReportMapper.insert(report); apiScenarioReportMapper.insert(report);
group.setHashTree(scenarios); group.setHashTree(scenarios);
testPlan.getHashTree().add(group); testPlan.getHashTree().add(group);

View File

@ -70,6 +70,7 @@ import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem"
import {REPORT_CONFIGS} from "../../common/components/search/search-components"; import {REPORT_CONFIGS} from "../../common/components/search/search-components";
import ShowMoreBtn from "../../track/case/components/ShowMoreBtn"; import ShowMoreBtn from "../../track/case/components/ShowMoreBtn";
import {_filter, _sort} from "@/common/js/tableUtils"; import {_filter, _sort} from "@/common/js/tableUtils";
import {getCurrentProjectID} from "@/common/js/utils";
export default { export default {
components: { components: {
@ -121,7 +122,7 @@ export default {
if (this.testId !== 'all') { if (this.testId !== 'all') {
this.condition.testId = this.testId; this.condition.testId = this.testId;
} }
this.condition.projectId = getCurrentProjectID();
let url = "/api/report/list/" + this.currentPage + "/" + this.pageSize; let url = "/api/report/list/" + this.currentPage + "/" + this.pageSize;
this.result = this.$post(url, this.condition, response => { this.result = this.$post(url, this.condition, response => {
let data = response.data; let data = response.data;

View File

@ -28,7 +28,7 @@
{{ item.name }} {{ item.name }}
</span> </span>
<i class="el-icon-check" <i class="el-icon-check"
v-if="item.id === currentUserInfo.lastOrganizationId"></i> v-if="item.id === getCurrentOrganizationId()"></i>
</el-menu-item> </el-menu-item>
</div> </div>
</el-submenu> </el-submenu>
@ -53,7 +53,7 @@
<span class="title"> <span class="title">
{{ item.name }} {{ item.name }}
</span> </span>
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastWorkspaceId"></i> <i class="el-icon-check" v-if="item.id === getCurrentWorkspaceId()"></i>
</el-menu-item> </el-menu-item>
</div> </div>
</el-submenu> </el-submenu>
@ -61,7 +61,8 @@
</template> </template>
<script> <script>
import {getCurrentUser, saveLocalStorage} from "@/common/js/utils"; import {getCurrentOrganizationId, getCurrentUser, getCurrentWorkspaceId, saveLocalStorage} from "@/common/js/utils";
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
export default { export default {
name: "MsHeaderOrgWs", name: "MsHeaderOrgWs",
@ -108,12 +109,14 @@ export default {
} }
}, },
methods: { methods: {
getCurrentOrganizationId,
getCurrentWorkspaceId,
initMenuData() { initMenuData() {
this.$get("/organization/list/userorg/" + encodeURIComponent(this.currentUserId), response => { this.$get("/organization/list/userorg/" + encodeURIComponent(this.currentUserId), response => {
let data = response.data; let data = response.data;
this.organizationList = data; this.organizationList = data;
this.orgListCopy = data; this.orgListCopy = data;
let org = data.filter(r => r.id === this.currentUser.lastOrganizationId); let org = data.filter(r => r.id === getCurrentOrganizationId());
if (org.length > 0) { if (org.length > 0) {
this.currentOrganizationName = org[0].name; this.currentOrganizationName = org[0].name;
} }
@ -128,7 +131,7 @@ export default {
} else { } else {
this.workspaceList = data; this.workspaceList = data;
this.wsListCopy = data; this.wsListCopy = data;
let workspace = data.filter(r => r.id === this.currentUser.lastWorkspaceId); let workspace = data.filter(r => r.id === getCurrentWorkspaceId());
if (workspace.length > 0) { if (workspace.length > 0) {
this.currentWorkspaceName = workspace[0].name; this.currentWorkspaceName = workspace[0].name;
} }
@ -147,14 +150,11 @@ export default {
} }
this.$post("/user/switch/source/org/" + orgId, {}, response => { this.$post("/user/switch/source/org/" + orgId, {}, response => {
saveLocalStorage(response); saveLocalStorage(response);
if (response.data.workspaceId) {
localStorage.setItem("workspace_id", response.data.workspaceId); sessionStorage.setItem(ORGANIZATION_ID, orgId);
} sessionStorage.setItem(WORKSPACE_ID, response.data.lastWorkspaceId);
// if (response.data.lastProjectId) { sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// } else {
// localStorage.removeItem(PROJECT_ID);
// }
this.$router.push('/').then(() => { this.$router.push('/').then(() => {
this.reloadTopMenus(); this.reloadTopMenus();
}).catch(err => err); }).catch(err => err);
@ -167,12 +167,9 @@ export default {
} }
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => { this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
saveLocalStorage(response); saveLocalStorage(response);
localStorage.setItem("workspace_id", workspaceId); sessionStorage.setItem(WORKSPACE_ID, workspaceId);
// if (response.data.lastProjectId) { sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// } else {
// localStorage.removeItem(PROJECT_ID);
// }
this.$router.push('/').then(() => { this.$router.push('/').then(() => {
this.reloadTopMenus(); this.reloadTopMenus();
}).catch(err => err); }).catch(err => err);

View File

@ -28,6 +28,7 @@ import {getCurrentUser} from "@/common/js/utils";
import AboutUs from "./AboutUs"; import AboutUs from "./AboutUs";
import axios from "axios"; import axios from "axios";
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const auth = requireComponent.keys().length > 0 ? requireComponent("./auth/Auth.vue") : {}; const auth = requireComponent.keys().length > 0 ? requireComponent("./auth/Auth.vue") : {};
@ -53,10 +54,18 @@ export default {
axios.get("/signout").then(response => { axios.get("/signout").then(response => {
if (response.data.success) { if (response.data.success) {
localStorage.clear(); localStorage.clear();
sessionStorage.removeItem(ORGANIZATION_ID);
sessionStorage.removeItem(WORKSPACE_ID);
sessionStorage.removeItem(PROJECT_ID);
window.location.href = "/login"; window.location.href = "/login";
} }
}).catch(error => { }).catch(error => {
localStorage.clear(); localStorage.clear();
sessionStorage.removeItem(ORGANIZATION_ID);
sessionStorage.removeItem(WORKSPACE_ID);
sessionStorage.removeItem(PROJECT_ID);
window.location.href = "/login"; window.location.href = "/login";
}); });
}, },

View File

@ -24,7 +24,8 @@
<script> <script>
import SearchList from "@/business/components/common/head/SearchList"; import SearchList from "@/business/components/common/head/SearchList";
import {PROJECT_NAME} from "../../../../common/js/constants"; import {PROJECT_NAME} from "@/common/js/constants";
import {getCurrentProjectID} from "@/common/js/utils";
export default { export default {
name: "ProjectSwitch", name: "ProjectSwitch",
@ -34,24 +35,27 @@ export default {
components: {SearchList}, components: {SearchList},
watch: { watch: {
currentProject() { currentProject() {
localStorage.setItem(PROJECT_NAME, this.currentProject); sessionStorage.setItem(PROJECT_NAME, this.currentProject);
} }
}, },
methods: {
getCurrentProjectID,
},
data() { data() {
return { return {
currentProject: this.projectName currentProject: this.projectName
};
} }
} };
}
</script> </script>
<style scoped> <style scoped>
.project-name { .project-name {
display: inline-block; display: inline-block;
width: 130px; width: 130px;
white-space:nowrap; white-space: nowrap;
overflow:hidden; overflow: hidden;
text-overflow:ellipsis; text-overflow: ellipsis;
} }
.el-divider--horizontal { .el-divider--horizontal {

View File

@ -17,7 +17,7 @@
<div class="title"> <div class="title">
{{ i.name }} {{ i.name }}
</div> </div>
<i class="el-icon-check" v-if="i.id === currentProjectId"></i> <i class="el-icon-check" v-if="i.id === getCurrentProjectID()"></i>
</template> </template>
</el-menu-item> </el-menu-item>
</div> </div>
@ -26,8 +26,15 @@
</template> </template>
<script> <script>
import {getCurrentProjectID, getCurrentUser, getCurrentUserId, saveLocalStorage} from "@/common/js/utils"; import {
getCurrentProjectID,
getCurrentUser,
getCurrentUserId,
getCurrentWorkspaceId,
saveLocalStorage
} from "@/common/js/utils";
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
import {PROJECT_ID} from "@/common/js/constants";
export default { export default {
name: "SearchList", name: "SearchList",
@ -54,17 +61,21 @@ export default {
searchArray: [], searchArray: [],
searchString: '', searchString: '',
userId: getCurrentUser().id, userId: getCurrentUser().id,
currentProjectId: getCurrentProjectID(), };
}
}, },
watch: { watch: {
searchString(val) { searchString(val) {
this.query(val) this.query(val);
} }
}, },
methods: { methods: {
getCurrentProjectID,
init: function () { init: function () {
this.result = this.$post("/project/list/related", {userId: getCurrentUserId()}, response => { let data = {
userId: getCurrentUserId(),
workspaceId: getCurrentWorkspaceId()
};
this.result = this.$post("/project/list/related", data, response => {
this.items = response.data; this.items = response.data;
this.searchArray = response.data; this.searchArray = response.data;
let projectId = getCurrentProjectID(); let projectId = getCurrentProjectID();
@ -79,7 +90,7 @@ export default {
} }
} }
this.changeProjectName(projectId); this.changeProjectName(projectId);
}) });
}, },
query(queryString) { query(queryString) {
this.items = queryString ? this.searchArray.filter(this.createFilter(queryString)) : this.searchArray; this.items = queryString ? this.searchArray.filter(this.createFilter(queryString)) : this.searchArray;
@ -99,6 +110,8 @@ export default {
this.currentProjectId = projectId; this.currentProjectId = projectId;
this.$EventBus.$emit('projectChange'); this.$EventBus.$emit('projectChange');
// sessionprojectId
sessionStorage.setItem(PROJECT_ID, projectId);
// //
this.reload(); this.reload();
@ -116,7 +129,7 @@ export default {
} }
} }
} }
} };
</script> </script>
<style scoped> <style scoped>

View File

@ -116,7 +116,7 @@
<script> <script>
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableOperator from "../../common/components/MsTableOperator"; import MsTableOperator from "../../common/components/MsTableOperator";
import {getCurrentProjectID, getCurrentUser, hasRoles} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentUser, getCurrentWorkspaceId, hasRoles} from "@/common/js/utils";
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, WORKSPACE_ID} from "@/common/js/constants"; import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, WORKSPACE_ID} from "@/common/js/constants";
import MsLogDetail from "./LogDetail"; import MsLogDetail from "./LogDetail";
@ -246,11 +246,11 @@
this.getMember(); this.getMember();
break; break;
case "organization": case "organization":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId); this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember(); this.getMember();
break; break;
case "workspace": case "workspace":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId); this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember(); this.getMember();
break; break;
case "project": case "project":
@ -267,11 +267,11 @@
this.getMember(); this.getMember();
break; break;
case "organization": case "organization":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId); this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember(); this.getMember();
break; break;
case "workspace": case "workspace":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId); this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember(); this.getMember();
break; break;
case "project": case "project":

View File

@ -247,6 +247,7 @@ export default {
if (this.form.id) { if (this.form.id) {
saveType = 'update'; saveType = 'update';
} }
this.form.organizationId = getCurrentOrganizationId();
this.$post("/workspace/" + saveType, this.form, () => { this.$post("/workspace/" + saveType, this.form, () => {
this.dialogWsAddVisible = false; this.dialogWsAddVisible = false;
this.dialogWsUpdateVisible = false; this.dialogWsUpdateVisible = false;
@ -296,7 +297,7 @@ export default {
}, },
list() { list() {
let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize; let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize;
let lastOrganizationId = this.currentUser.lastOrganizationId; let lastOrganizationId = getCurrentOrganizationId();
// let userRole = this.currentUser.userRoles.filter(r => r.sourceId === lastOrganizationId); // let userRole = this.currentUser.userRoles.filter(r => r.sourceId === lastOrganizationId);
// if (userRole.length > 0) { // if (userRole.length > 0) {
// let isOrg_admin = false; // let isOrg_admin = false;
@ -327,6 +328,7 @@ export default {
// this.items = []; // this.items = [];
// this.total = 0; // this.total = 0;
// } // }
this.condition.organizationId = lastOrganizationId;
this.result = this.$post(url, this.condition, response => { this.result = this.$post(url, this.condition, response => {
let data = response.data; let data = response.data;
this.items = data.listObject; this.items = data.listObject;

View File

@ -245,7 +245,7 @@ export default {
}); });
}, },
create() { create() {
let workspaceId = this.currentUser.lastWorkspaceId; let workspaceId = getCurrentWorkspaceId();
this.getOptions(); this.getOptions();
if (!workspaceId) { if (!workspaceId) {
this.$warning(this.$t('project.please_choose_workspace')); this.$warning(this.$t('project.please_choose_workspace'));

View File

@ -380,7 +380,7 @@ export default {
}); });
}, },
create() { create() {
let workspaceId = this.currentUser.lastWorkspaceId; let workspaceId = getCurrentWorkspaceId();
this.getOptions(); this.getOptions();
if (!workspaceId) { if (!workspaceId) {
this.$warning(this.$t('project.please_choose_workspace')); this.$warning(this.$t('project.please_choose_workspace'));

View File

@ -133,7 +133,7 @@
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import { import {
getCurrentOrganizationId, getCurrentProjectID, getCurrentOrganizationId, getCurrentProjectID,
getCurrentUser, getCurrentUser, getCurrentWorkspaceId,
listenGoBack, listenGoBack,
removeGoBackListener removeGoBackListener
} from "../../../../common/js/utils"; } from "../../../../common/js/utils";
@ -197,19 +197,19 @@
return getCurrentUser(); return getCurrentUser();
}, },
initTableData() { initTableData() {
if (this.currentUser().lastWorkspaceId === null) { if (getCurrentWorkspaceId() === null) {
return false; return false;
} }
this.loading = true; this.loading = true;
let param = { let param = {
name: this.condition.name, name: this.condition.name,
workspaceId: this.currentUser().lastWorkspaceId workspaceId: getCurrentWorkspaceId()
}; };
this.result = this.$post(this.buildPagePath(this.queryPath), param, response => { this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
let data = response.data; let data = response.data;
this.tableData = data.listObject; this.tableData = data.listObject;
let url = "/user/group/list/ws/" + this.currentUser().lastWorkspaceId; let url = "/user/group/list/ws/" + getCurrentWorkspaceId();
for (let i = 0; i < this.tableData.length; i++) { for (let i = 0; i < this.tableData.length; i++) {
this.$get(url + "/" + encodeURIComponent(this.tableData[i].id), response => { this.$get(url + "/" + encodeURIComponent(this.tableData[i].id), response => {
let groups = response.data; let groups = response.data;
@ -260,7 +260,7 @@
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.result = this.$get('/user/ws/member/delete/' + this.currentUser().lastWorkspaceId + '/' + encodeURIComponent(row.id),() => { this.result = this.$get('/user/ws/member/delete/' + getCurrentWorkspaceId() + '/' + encodeURIComponent(row.id), () => {
this.$success(this.$t('commons.remove_success')); this.$success(this.$t('commons.remove_success'));
this.initTableData(); this.initTableData();
}); });
@ -286,7 +286,7 @@
email: this.form.email, email: this.form.email,
phone: this.form.phone, phone: this.form.phone,
groupIds: this.form.groupIds, groupIds: this.form.groupIds,
workspaceId: this.currentUser().lastWorkspaceId workspaceId: getCurrentWorkspaceId()
} }
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
@ -304,7 +304,7 @@
// name: this.condition.name, // name: this.condition.name,
// organizationId: this.currentUser().lastOrganizationId // organizationId: this.currentUser().lastOrganizationId
// }; // };
let wsId = this.currentUser().lastWorkspaceId; let wsId = getCurrentWorkspaceId();
if (typeof wsId == "undefined" || wsId == null || wsId == "") { if (typeof wsId == "undefined" || wsId == null || wsId == "") {
this.$warning(this.$t('workspace.please_select_a_workspace_first')); this.$warning(this.$t('workspace.please_select_a_workspace_first'));
return false; return false;
@ -339,7 +339,7 @@
let param = { let param = {
userIds: userIds, userIds: userIds,
groupIds: this.form.groupIds, groupIds: this.form.groupIds,
workspaceId: this.currentUser().lastWorkspaceId workspaceId: getCurrentWorkspaceId()
}; };
this.result = this.$post("user/ws/member/add", param, () => { this.result = this.$post("user/ws/member/add", param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));

View File

@ -20,6 +20,7 @@ export const ROLE_TEST_MANAGER = 'test_manager';
export const ROLE_TEST_USER = 'test_user'; export const ROLE_TEST_USER = 'test_user';
export const ROLE_TEST_VIEWER = 'test_viewer'; export const ROLE_TEST_VIEWER = 'test_viewer';
export const ORGANIZATION_ID = 'organization_id';
export const WORKSPACE_ID = 'workspace_id'; export const WORKSPACE_ID = 'workspace_id';
export const CURRENT_PROJECT = 'current_project'; export const CURRENT_PROJECT = 'current_project';
export const PROJECT_ID = 'project_id'; export const PROJECT_ID = 'project_id';

View File

@ -2,6 +2,7 @@ import {
COUNT_NUMBER, COUNT_NUMBER,
COUNT_NUMBER_SHALLOW, COUNT_NUMBER_SHALLOW,
LicenseKey, LicenseKey,
ORGANIZATION_ID,
ORIGIN_COLOR, ORIGIN_COLOR,
ORIGIN_COLOR_SHALLOW, ORIGIN_COLOR_SHALLOW,
PRIMARY_COLOR, PRIMARY_COLOR,
@ -12,7 +13,8 @@ import {
ROLE_TEST_MANAGER, ROLE_TEST_MANAGER,
ROLE_TEST_USER, ROLE_TEST_USER,
ROLE_TEST_VIEWER, ROLE_TEST_VIEWER,
TokenKey TokenKey,
WORKSPACE_ID
} from "./constants"; } from "./constants";
import axios from "axios"; import axios from "axios";
import {jsPDF} from "jspdf"; import {jsPDF} from "jspdf";
@ -178,13 +180,15 @@ export function checkoutTestManagerOrTestUser() {
} }
export function getCurrentOrganizationId() { export function getCurrentOrganizationId() {
let user = getCurrentUser(); return sessionStorage.getItem(ORGANIZATION_ID);
return user.lastOrganizationId;
} }
export function getCurrentWorkspaceId() { export function getCurrentWorkspaceId() {
let user = getCurrentUser(); return sessionStorage.getItem(WORKSPACE_ID);
return user.lastWorkspaceId; }
export function getCurrentProjectID() {
return sessionStorage.getItem(PROJECT_ID);
} }
export function getCurrentUser() { export function getCurrentUser() {
@ -196,11 +200,6 @@ export function getCurrentUserId() {
return user.id; return user.id;
} }
export function getCurrentProjectID() {
let user = getCurrentUser();
return user.lastProjectId;
}
export function enableModules(...modules) { export function enableModules(...modules) {
for (let module of modules) { for (let module of modules) {
let moduleStatus = localStorage.getItem('module_' + module); let moduleStatus = localStorage.getItem('module_' + module);
@ -214,6 +213,15 @@ export function enableModules(...modules) {
export function saveLocalStorage(response) { export function saveLocalStorage(response) {
// 登录信息保存 cookie // 登录信息保存 cookie
localStorage.setItem(TokenKey, JSON.stringify(response.data)); localStorage.setItem(TokenKey, JSON.stringify(response.data));
if (!sessionStorage.getItem(PROJECT_ID)) {
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
}
if (!sessionStorage.getItem(ORGANIZATION_ID)) {
sessionStorage.setItem(ORGANIZATION_ID, response.data.lastOrganizationId);
}
if (!sessionStorage.getItem(WORKSPACE_ID)) {
sessionStorage.setItem(WORKSPACE_ID, response.data.lastWorkspaceId);
}
let rolesArray = response.data.roles; let rolesArray = response.data.roles;
let roles = rolesArray.map(r => r.id); let roles = rolesArray.map(r => r.id);
// 保存角色 // 保存角色