fix(接口测试): 成员下拉组件默认选中当前用户时校验用户权限

过滤掉非当前项目下的成员,可能是超级管理员用户组中的成员,导致成员下拉待选列表数据有问题
This commit is contained in:
shiziyuan9527 2022-12-29 17:19:07 +08:00 committed by fit2-zhao
parent 9188d7368a
commit d9f86bbd14
3 changed files with 34 additions and 4 deletions

View File

@ -327,7 +327,7 @@ export default {
this.activeName = name;
let currentScenario = {
status: 'Underway',
principal: getCurrentUser().id,
principal: this._getCurrentUserId(),
apiScenarioModuleId: 'default-module',
id: getUUID(),
modulePath: '/' + this.$t('commons.module_title'),
@ -371,6 +371,17 @@ export default {
this.addListener();
}
},
_getCurrentUserId() {
const {id, userGroups} = getCurrentUser();
if (userGroups) {
//
let index = userGroups.findIndex(ug => ug.sourceId === getCurrentProjectID());
if (index !== -1) {
return id;
}
}
return '';
},
addListener() {
let index = this.tabs.findIndex((item) => item.name === this.activeName); // tabindex
if (index != -1) {

View File

@ -659,7 +659,7 @@ export default {
name: '',
status: 'Underway',
method: 'GET',
userId: getCurrentUser().id,
userId: this._getCurrentUserId(),
url: '',
protocol: this.currentProtocol,
environmentId: '',
@ -681,6 +681,17 @@ export default {
}
this.handleTabsEdit(this.$t('api_test.definition.request.title'), e, api);
},
_getCurrentUserId() {
const {id, userGroups} = getCurrentUser();
if (userGroups) {
//
let index = userGroups.findIndex(ug => ug.sourceId === getCurrentProjectID());
if (index !== -1) {
return id;
}
}
return '';
},
handleTabClose() {
let tabs = this.apiTabs[0];
let message = '';

View File

@ -1,5 +1,5 @@
import i18n from "../i18n";
import { getCurrentUserId } from "../utils/token";
import {getCurrentProjectID, getCurrentUser} from "../utils/token";
import { SYSTEM_FIELD_NAME_MAP } from "../utils/table-constants";
function setDefaultValue(item, value) {
@ -39,7 +39,15 @@ export function parseCustomField(data, template, rules, oldFields) {
val &&
val === "CURRENT_USER"
) {
val = getCurrentUserId();
val = '';
const {id, userGroups} = getCurrentUser();
if (userGroups) {
// CURRENT_USER是否是当前项目下的成员
let index = userGroups.findIndex(ug => ug.sourceId === getCurrentProjectID());
if (index !== -1) {
val = id;
}
}
}
setDefaultValue(item, val);
}