diff --git a/api-test/frontend/src/business/automation/ApiAutomation.vue b/api-test/frontend/src/business/automation/ApiAutomation.vue index 0e5344ad09..81fd357556 100644 --- a/api-test/frontend/src/business/automation/ApiAutomation.vue +++ b/api-test/frontend/src/business/automation/ApiAutomation.vue @@ -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); // 找到当前选中tab的index if (index != -1) { diff --git a/api-test/frontend/src/business/definition/ApiDefinition.vue b/api-test/frontend/src/business/definition/ApiDefinition.vue index 0f4b43f8bb..fd77fd70d2 100644 --- a/api-test/frontend/src/business/definition/ApiDefinition.vue +++ b/api-test/frontend/src/business/definition/ApiDefinition.vue @@ -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 = ''; diff --git a/framework/sdk-parent/frontend/src/utils/custom_field.js b/framework/sdk-parent/frontend/src/utils/custom_field.js index 68f1a04daf..ff7cb718c0 100644 --- a/framework/sdk-parent/frontend/src/utils/custom_field.js +++ b/framework/sdk-parent/frontend/src/utils/custom_field.js @@ -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); }