refactor(XPack): 认证机制重构,权限修改

This commit is contained in:
fit2-zhao 2020-09-22 12:35:07 +08:00
parent 421b522cc6
commit e50a952944
7 changed files with 69 additions and 38 deletions

View File

@ -12,6 +12,7 @@ import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.LicenseDTO;
import io.metersphere.dto.ScheduleDao;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
@ -19,7 +20,6 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@RestController
@ -127,4 +127,10 @@ public class APITestController {
public List<ScheduleDao> listSchedule(@RequestBody QueryScheduleRequest request) {
return apiTestService.listSchedule(request);
}
@GetMapping("/license/valid")
public LicenseDTO valid() {
return apiTestService.validateLicense();
}
}

View File

@ -12,7 +12,6 @@ import io.metersphere.api.parse.JmeterDocumentParser;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestFileMapper;
import io.metersphere.base.mapper.ApiTestMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.ExtApiTestMapper;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.FileType;
@ -21,15 +20,13 @@ import io.metersphere.commons.constants.ScheduleType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.LicenseDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import io.metersphere.service.FileService;
import io.metersphere.service.QuotaService;
import io.metersphere.service.ScheduleService;
import io.metersphere.service.UserService;
import io.metersphere.service.*;
import io.metersphere.track.service.TestCaseService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
@ -40,7 +37,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@ -441,4 +437,13 @@ public class APITestService {
quotaService.checkAPITestQuota();
}
}
public LicenseDTO validateLicense() {
LicenseService licenseService = CommonBeanFactory.getBean(LicenseService.class);
if (licenseService != null) {
return licenseService.valid();
}
return null;
}
}

View File

@ -0,0 +1,15 @@
package io.metersphere.dto;
import io.metersphere.xpack.license.dto.LicenseInfoDTO;
import lombok.Data;
import java.io.Serializable;
@Data
public class LicenseDTO implements Serializable {
private String status;
private LicenseInfoDTO license;
}

View File

@ -0,0 +1,10 @@
package io.metersphere.service;
import io.metersphere.dto.LicenseDTO;
public interface LicenseService {
public LicenseDTO valid();
public LicenseDTO addValidLicense(String reqLicenseCode);
}

View File

@ -281,8 +281,8 @@ public class TestCaseService {
errList.add(excelErrData);
excelResponse.setErrList(errList);
} else {
if (!xmindParser.testCases.isEmpty()) {
this.saveImportData(xmindParser.testCases, projectId);
if (!xmindParser.getTestCase().isEmpty()) {
this.saveImportData(xmindParser.getTestCase(), projectId);
xmindParser.clear();
}
excelResponse.setSuccess(true);

View File

@ -33,10 +33,12 @@ public class XmindCaseParser {
private StringBuffer process; // 过程校验记录
// 已存在用例名称
private Set<String> testCaseNames;
// 案例详情重写了hashCode方法去重用
public List<TestCaseWithBLOBs> testCases;
private List<TestCaseWithBLOBs> testCases;
// 用于重复对比
private List<TestCaseExcelData> xmindDataList;
private List<TestCaseExcelData> compartDatas;
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
this.testCaseService = testCaseService;
@ -44,21 +46,25 @@ public class XmindCaseParser {
this.projectId = projectId;
this.testCaseNames = testCaseNames;
testCases = new LinkedList<>();
xmindDataList = new ArrayList<>();
compartDatas = new ArrayList<>();
process = new StringBuffer();
}
// 这里清理是为了 加快jvm 回收
public void clear() {
xmindDataList.clear();
compartDatas.clear();
testCases.clear();
testCaseNames.clear();
}
public List<TestCaseWithBLOBs> getTestCase() {
return this.testCases;
}
// 递归处理案例数据
private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
for (Attached item : attacheds) {
if (isBlack(item.getTitle(), "(?:tc|tc:|tc)")) { // 用例
if (isAvailable(item.getTitle(), "(?:tc|tc:|tc)")) { // 用例
item.setParent(parent);
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
} else {
@ -72,8 +78,7 @@ public class XmindCaseParser {
}
}
private boolean isBlack(String str, String regex) {
// regex = "(?:tc:|tc)"
private boolean isAvailable(String str, String regex) {
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex))
return false;
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
@ -151,9 +156,9 @@ public class XmindCaseParser {
List<Attached> steps = new LinkedList<>();
if (attacheds != null && !attacheds.isEmpty()) {
attacheds.forEach(item -> {
if (isBlack(item.getTitle(), "(?:pc:|pc)")) {
if (isAvailable(item.getTitle(), "(?:pc:|pc)")) {
testCase.setPrerequisite(replace(item.getTitle(), "(?:pc:|pc)"));
} else if (isBlack(item.getTitle(), "(?:rc:|rc)")) {
} else if (isAvailable(item.getTitle(), "(?:rc:|rc)")) {
testCase.setRemark(replace(item.getTitle(), "(?:rc:|rc)"));
} else {
steps.add(item);
@ -174,7 +179,7 @@ public class XmindCaseParser {
}
TestCaseExcelData compartData = new TestCaseExcelData();
BeanUtils.copyBean(compartData, testCase);
if (xmindDataList.contains(compartData)) {
if (compartDatas.contains(compartData)) {
process.append(Translator.get("test_case_already_exists_excel") + "" + testCase.getName() + "; ");
} else if (validate(testCase)) {
testCase.setId(UUID.randomUUID().toString());
@ -182,7 +187,7 @@ public class XmindCaseParser {
testCase.setUpdateTime(System.currentTimeMillis());
testCases.add(testCase);
}
xmindDataList.add(compartData);
compartDatas.add(compartData);
}
// 验证合法性
@ -236,7 +241,7 @@ public class XmindCaseParser {
if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) {
// 判断是模块还是用例
for (Attached item : root.getRootTopic().getChildren().getAttached()) {
if (isBlack(item.getTitle(), "(?:tc:|tc|tc)")) { // 用例
if (isAvailable(item.getTitle(), "(?:tc:|tc|tc)")) { // 用例
return replace(item.getTitle(), "(?:tc:|tc|tc)") + "" + Translator.get("test_case_create_module_fail");
} else {
item.setPath(item.getTitle());
@ -247,9 +252,6 @@ public class XmindCaseParser {
}
}
}
//if (StringUtils.isEmpty(process.toString()) && !testCaseWithBLOBs.isEmpty()) {
// testCaseService.saveImportData(testCaseWithBLOBs, projectId);
//}
} catch (Exception ex) {
processBuffer.append(Translator.get("incorrect_format"));
LogUtil.error(ex.getMessage());

View File

@ -2,7 +2,7 @@
<el-col v-if="auth">
<el-row id="header-top1" type="flex" justify="space-between" align="middle">
<el-col>
<div class="license-head" v-if="valid === true && validData.status == 'expired'">License has expired since
<div class="license-head" v-if="validData.status == 'expired'">License has expired since
{{(validData!= undefined && validData.license!= undefined) ? validData.license.expired:''}},please
update license.
</div>
@ -40,15 +40,7 @@
export default {
name: 'app',
data() {
let xpack = false;
Setting.children.forEach(child => {
if (child.path === "license") {
xpack = true;
return;
}
})
return {
valid: xpack,
validData: {},
auth: false
}
@ -67,13 +59,14 @@
});
},
beforeMount() {
if (this.valid === true) {
// license
this.result = this.$get("/license/valid", response => {
// license
this.result = this.$get("/api/license/valid", response => {
let data = response.data;
if (data != undefined && data != null) {
this.validData = response.data;
saveLicense(response.data);
});
}
}
});
},
components: {MsLanguageSwitch, MsUser, MsView, MsTopMenus, MsHeaderOrgWs},
methods: {}