refactor: 优化项目创建相关代码

This commit is contained in:
Captain.B 2021-06-01 10:43:18 +08:00 committed by 刘瑞斌
parent 89b24fe0cc
commit 089db4d33d
30 changed files with 62 additions and 54 deletions

View File

@ -1,9 +1,7 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.base.domain.User;
import io.metersphere.controller.request.UserRequest;
import io.metersphere.controller.request.resourcepool.UserBatchProcessRequest;
import io.metersphere.notice.domain.UserDetail;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
@ -29,4 +27,6 @@ public interface ExtUserMapper {
List<String> selectAllId();
List<String> selectIdsByQuery(@Param("request") UserRequest request);
void updateLastProjectIdIfNull(@Param("projectId") String projectId, @Param("userId") String userId);
}

View File

@ -102,4 +102,9 @@
from user
<include refid="queryWhereCondition"/>
</select>
<update id="updateLastProjectIdIfNull">
update user set last_project_id = #{projectId} where id = #{userId}
and (last_project_id is null or last_project_id = '')
</update>
</mapper>

View File

@ -6,6 +6,7 @@ import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.RsaKey;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.LoginRequest;
import io.metersphere.dto.UserDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.service.BaseDisplayService;
@ -33,11 +34,13 @@ public class LoginController {
@GetMapping(value = "/isLogin")
public ResultHolder isLogin() {
if (SecurityUtils.getSubject().isAuthenticated()) {
SessionUser user = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(SessionUtils.getUserId());
if (StringUtils.isBlank(user.getLanguage())) {
user.setLanguage(LocaleContextHolder.getLocale().toString());
}
return ResultHolder.success(user);
SessionUser sessionUser = SessionUser.fromUser(user);
SessionUtils.putUser(sessionUser);
return ResultHolder.success(sessionUser);
}
return ResultHolder.error(rsaKey.getPublicKey());
}

View File

@ -10,6 +10,7 @@ import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtUserMapper;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils;
@ -81,6 +82,8 @@ public class ProjectService {
private ExtOrganizationMapper extOrganizationMapper;
@Resource
private ExtUserGroupMapper extUserGroupMapper;
@Resource
private ExtUserMapper extUserMapper;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
@ -118,6 +121,9 @@ public class ProjectService {
userGroup.setSourceId(project.getId());
userGroupMapper.insert(userGroup);
// 创建新项目检查当前用户 last_project_id
extUserMapper.updateLastProjectIdIfNull(project.getId(), SessionUtils.getUserId());
return project;
}

View File

@ -125,7 +125,6 @@
}
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.userOptions = response.data;
});

View File

@ -587,7 +587,6 @@ export default {
},
getPrincipalOptions(option) {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
option.push(...response.data);
this.userFilters = response.data.map(u => {

View File

@ -783,7 +783,6 @@
this.reload();
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.maintainerOptions = response.data;
});

View File

@ -239,7 +239,6 @@
this.httpForm.request = createComponent("DubboSampler");
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.maintainerOptions = response.data;
});

View File

@ -406,7 +406,6 @@
}
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.valueArr.userId = response.data;
this.userFilters = response.data.map(u => {

View File

@ -116,7 +116,6 @@
this.$emit("createRootModel");
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.maintainerOptions = response.data;
});

View File

@ -178,7 +178,6 @@
this.httpForm.request = createComponent("DubboSampler");
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.maintainerOptions = response.data;
});

View File

@ -107,7 +107,6 @@
},
methods: {
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.maintainerOptions = response.data;
});

View File

@ -246,7 +246,6 @@
});
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.maintainerOptions = response.data;
});

View File

@ -133,7 +133,6 @@
},
methods: {
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.maintainerOptions = response.data;
});

View File

@ -559,7 +559,6 @@ export default {
}
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.valueArr.userId = response.data;
this.userFilters = response.data.map(u => {

View File

@ -129,7 +129,6 @@ export default {
let workspace = data.filter(r => r.id === this.currentUser.lastWorkspaceId);
if (workspace.length > 0) {
this.currentWorkspaceName = workspace[0].name;
localStorage.setItem(WORKSPACE_ID, workspace[0].id);
}
}
});

View File

@ -241,11 +241,12 @@ export default {
this.$post("/workspace/" + saveType, this.form, () => {
this.dialogWsAddVisible = false;
this.dialogWsUpdateVisible = false;
this.list();
if (saveType == 'add') {
Message.success(this.$t('commons.save_success'));
window.location.reload();
} else if (saveType == 'update') {
Message.success(this.$t('commons.modify_success'));
this.list();
}
});
} else {

View File

@ -134,7 +134,8 @@
</template>
</el-dialog>
<el-dialog :close-on-click-modal="false" :visible.sync="memberVisible" width="70%" :destroy-on-close="true" @close="close"
<el-dialog :close-on-click-modal="false" :visible.sync="memberVisible" width="70%" :destroy-on-close="true"
@close="close"
class="dialog-css">
<div style="height: 60vh;overflow: auto">
<ms-table-header :condition.sync="dialogCondition" @create="open" @search="list" :have-search="false"
@ -164,7 +165,8 @@
</div>
</el-dialog>
<el-dialog :close-on-click-modal="false" :title="$t('member.modify')" :visible.sync="updateVisible" width="30%" :destroy-on-close="true"
<el-dialog :close-on-click-modal="false" :title="$t('member.modify')" :visible.sync="updateVisible" width="30%"
:destroy-on-close="true"
@close="handleClose">
<el-form :model="form" label-position="right" label-width="100px" size="small" ref="updateUserForm">
<el-form-item label="ID" prop="id">
@ -198,10 +200,12 @@
</el-dialog>
<el-dialog :close-on-click-modal="false" title="添加成员" :visible.sync="dialogMemberVisible" width="30%" :destroy-on-close="true"
<el-dialog :close-on-click-modal="false" title="添加成员" :visible.sync="dialogMemberVisible" width="30%"
:destroy-on-close="true"
@close="handleMemberClose">
<el-form :model="memberForm" ref="form" :rules="rules" label-position="right" label-width="100px" size="small">
<el-form-item :label="$t('commons.member')" prop="memberSign" :rules="{required: true, message: $t('member.input_id_or_email'), trigger: 'change'}">
<el-form-item :label="$t('commons.member')" prop="memberSign"
:rules="{required: true, message: $t('member.input_id_or_email'), trigger: 'change'}">
<el-autocomplete
class="input-with-autocomplete"
v-model="memberForm.memberSign"
@ -214,8 +218,8 @@
style="width: 100%"
>
<template v-slot:default="scope">
<span class="workspace-member-name">{{scope.item.id}}</span>
<span class="workspace-member-email">{{scope.item.email}}</span>
<span class="workspace-member-name">{{ scope.item.id }}</span>
<span class="workspace-member-email">{{ scope.item.email }}</span>
</template>
</el-autocomplete>
</el-form-item>
@ -290,7 +294,7 @@ export default {
ApiEnvironmentConfig,
MsTableOperatorButton,
MsDeleteConfirm,
MsMainContainer,MsRolesTag,
MsMainContainer, MsRolesTag,
MsContainer, MsTableOperator, MsCreateBox, MsTablePagination, MsTableHeader, MsDialogFooter
},
data() {
@ -424,8 +428,12 @@ export default {
this.form.protocal = protocol;
this.result = this.$post("/project/" + saveType, this.form, () => {
this.createVisible = false;
this.list();
Message.success(this.$t('commons.save_success'));
if (saveType === 'add') {
window.location.reload();
} else {
this.list();
}
});
} else {
return false;
@ -481,12 +489,12 @@ export default {
let param = {
name: '',
workspaceId: this.items[i].id
}
};
let path = "user/ws/member/list/all";
this.$post(path, param, res => {
let member = res.data;
this.$set(this.items[i], "memberSize", member.length);
})
});
}
this.total = data.itemCount;
});
@ -525,7 +533,7 @@ export default {
this.$get(url + "/" + encodeURIComponent(this.memberLineData[i].id), response => {
let groups = response.data;
this.$set(this.memberLineData[i], "groups", groups);
})
});
}
this.dialogTotal = data.itemCount;
});
@ -548,7 +556,7 @@ export default {
this.$get(url + "/" + encodeURIComponent(this.memberLineData[i].id), response => {
let groups = response.data;
this.$set(this.memberLineData[i], "groups", groups);
})
});
}
this.dialogTotal = data.itemCount;
});
@ -559,7 +567,7 @@ export default {
let groupIds = this.form.groups.map(r => r.id);
this.result = this.$post('/user/group/list', {type: GROUP_PROJECT, resourceId: this.projectId}, response => {
this.$set(this.form, "allgroups", response.data);
})
});
// 使
this.$set(this.form, 'groupIds', groupIds);
},
@ -569,7 +577,7 @@ export default {
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/project/member/delete/' + this.currentProjectId + '/' + encodeURIComponent(row.id),() => {
this.result = this.$get('/user/project/member/delete/' + this.currentProjectId + '/' + encodeURIComponent(row.id), () => {
this.$success(this.$t('commons.remove_success'));
this.dialogSearch();
});
@ -590,7 +598,7 @@ export default {
phone: this.form.phone,
groupIds: this.form.groupIds,
projectId: this.currentProjectId
}
};
this.$refs[formName].validate((valid) => {
if (valid) {
this.result = this.$post("/project/member/update", param, () => {
@ -606,7 +614,7 @@ export default {
if (valid) {
let userIds = [];
let userId = this.memberForm.userId;
let email = this.memberForm.memberSign;
let email = this.memberForm.memberSign;
let member = this.userList.find(user => user.id === email || user.email === email);
if (!member) {
this.$warning(this.$t('member.no_such_user'));
@ -624,7 +632,7 @@ export default {
this.$success(this.$t('commons.save_success'));
this.dialogSearch();
this.dialogMemberVisible = false;
})
});
}
});
},
@ -632,10 +640,13 @@ export default {
this.$get('/user/list/', response => {
this.dialogMemberVisible = true;
this.userList = response.data;
})
this.result = this.$post('/user/group/list', {type: GROUP_PROJECT, resourceId: this.currentProjectId}, response => {
});
this.result = this.$post('/user/group/list', {
type: GROUP_PROJECT,
resourceId: this.currentProjectId
}, response => {
this.$set(this.memberForm, "groups", response.data);
})
});
},
handleMemberClose() {
this.dialogMemberVisible = false;

View File

@ -22,6 +22,7 @@
import TestcaseTemplateItem from "../../../track/plan/view/comonents/report/TestcaseTemplateItem";
import {WORKSPACE_ID} from '../../../../../common/js/constants';
import MsMainContainer from "../../../common/components/MsMainContainer";
import {getCurrentWorkspaceId} from "@/common/js/utils";
export default {
name: "TestCaseReportTemplate",
@ -45,7 +46,7 @@
},
methods: {
initData() {
this.condition.workspaceId = localStorage.getItem(WORKSPACE_ID);
this.condition.workspaceId = getCurrentWorkspaceId();
this.result = this.$post('/case/report/template/list', this.condition, response => {
this.templates = response.data;
});

View File

@ -151,7 +151,6 @@ export default {
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.userOptions = response.data;
});

View File

@ -702,7 +702,6 @@
this.form.testId = '';
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.maintainerOptions = response.data;
});

View File

@ -655,7 +655,6 @@ export default {
this.$refs.testBatchMove.open(this.treeNodes, Array.from(this.selectRows).map(row => row.id), this.moduleOptions);
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.valueArr.maintainer = response.data;
});

View File

@ -125,7 +125,7 @@
import {WORKSPACE_ID} from '@/common/js/constants';
import TestPlanStatusButton from "../common/TestPlanStatusButton";
import {getCurrentProjectID, listenGoBack, removeGoBackListener} from "@/common/js/utils";
import {getCurrentProjectID, getCurrentWorkspaceId, listenGoBack, removeGoBackListener} from "@/common/js/utils";
import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag";
export default {
@ -196,7 +196,7 @@ export default {
this.$warning(this.$t('test_track.plan.input_plan_name'));
return;
}
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
param.workspaceId = getCurrentWorkspaceId();
if (this.form.tags instanceof Array) {
this.form.tags = JSON.stringify(this.form.tags);
}
@ -221,7 +221,7 @@ export default {
this.$warning(this.$t('test_track.plan.input_plan_name'));
return;
}
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
param.workspaceId = getCurrentWorkspaceId();
if (this.form.tags instanceof Array) {
this.form.tags = JSON.stringify(this.form.tags);
}
@ -248,7 +248,6 @@ export default {
return true;
},
setPrincipalOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.principalOptions = response.data;
});

View File

@ -39,7 +39,6 @@
},
methods: {
setMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.executorOptions = response.data;
});

View File

@ -16,6 +16,7 @@
<script>
import TestcaseTemplateItem from "./report/TestcaseTemplateItem";
import {WORKSPACE_ID} from "../../../../../../common/js/constants";
import {getCurrentWorkspaceId} from "@/common/js/utils";
export default {
name: "TestReportTemplateList",
components: {TestcaseTemplateItem},
@ -30,7 +31,7 @@
initData() {
let condition = {};
condition.queryDefault = true;
condition.workspaceId = localStorage.getItem(WORKSPACE_ID);
condition.workspaceId = getCurrentWorkspaceId();
this.result = this.$post('/case/report/template/list', condition, response => {
this.templates = response.data;
});

View File

@ -350,7 +350,6 @@ export default {
this.$refs.headerCustom.open(list);
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.valueArr.userId = response.data;
this.userFilters = response.data.map(u => {

View File

@ -681,7 +681,6 @@ export default {
this.$refs.batchEdit.open();
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()}, response => {
this.valueArr.executor = response.data;
this.executorFilters = response.data.map(u => {

View File

@ -54,7 +54,7 @@
import TemplateComponentBar from "./TemplateComponentBar";
import TemplateComponentEditHeader from "./TemplateComponentEditHeader";
import {WORKSPACE_ID} from '../../../../../../../common/js/constants';
import {jsonToMap, mapToJson} from "../../../../../../../common/js/utils";
import {getCurrentWorkspaceId, jsonToMap, mapToJson} from "../../../../../../../common/js/utils";
import TemplateComponent from "./TemplateComponent/TemplateComponent";
export default {
@ -262,10 +262,10 @@
if (this.type == 'edit') {
param.id = this.template.id;
} else {
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
param.workspaceId = getCurrentWorkspaceId();
}
if (this.template.workspaceId) {
param.workspaceId = localStorage.getItem(WORKSPACE_ID);
param.workspaceId = getCurrentWorkspaceId();
}
if (this.metric && this.metric.startTime) {
param.startTime = this.metric.startTime.getTime();

View File

@ -232,7 +232,6 @@ export default {
});
},
setReviewerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.result = this.$post('/user/project/member/tester/list', {projectId: getCurrentProjectID()},response => {
this.reviewerOptions = response.data;
});

@ -1 +1 @@
Subproject commit 526400764fc45b12dd81f5b89137f8bc5a012f4d
Subproject commit 1ac463ed7ef667d3f75c3ba64fab8331ecaa02c2