Skip to content

Commit

Permalink
fix: 执行代理人限制仅能设置为本人 TencentBlueKing#7289
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 1852
  • Loading branch information
ywywZhou authored and luofann committed Jan 16, 2024
1 parent dcd485a commit d1b458e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
3 changes: 2 additions & 1 deletion frontend/desktop/src/config/i18n/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,8 @@ const cn = {
'exFailedText': '节点执行失败,请前往{0}查看错误原因',
'exFailedText_调用日志': '调用日志',
'任务还未执行,暂无执行历史': '任务还未执行,暂无执行历史',
'空分支': '空分支'
'空分支': '空分支',
'代理人仅可设置为本人': '代理人仅可设置为本人'
}

export default cn
3 changes: 2 additions & 1 deletion frontend/desktop/src/config/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,8 @@ const en = {
'exFailedText': 'Node execution failed. Please go to the {0} to check the error reason.',
'exFailedText_调用日志': 'call log',
'任务还未执行,暂无执行历史': 'Task not executed, no history available.',
'空分支': 'Empty branch'
'空分支': 'Empty branch',
'代理人仅可设置为本人': 'The executor proxy can only set yourself'
}

export default en
22 changes: 19 additions & 3 deletions frontend/desktop/src/pages/project/config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,17 @@
data-test-id="projectConfig_form_executeAgentDialog"
:cancel-text="$t('取消')"
@confirm="updateAgentData"
@cancel="isAgentDialogShow = false">
@cancel="closeAgentDialog">
<bk-form class="agent-dialog" :model="editingAgent" :label-width="180">
<bk-form-item :label="$t('执行代理人')">
<bk-user-selector
v-model="editingAgent.executor_proxy"
:placeholder="$t('请输入用户')"
:api="userApi"
:multiple="false">
:multiple="false"
@change="onSelectedExecutorProxy">
</bk-user-selector>
<p v-if="isProxyValidateError" class="form-error-tip">{{ $t('代理人仅可设置为本人') }}</p>
</bk-form-item>
<bk-form-item :label="$t('免代理用户')">
<bk-user-selector
Expand Down Expand Up @@ -436,6 +438,7 @@
}
]
},
isProxyValidateError: false,
labelRules: {
color: [
{
Expand Down Expand Up @@ -604,9 +607,13 @@
}
})
},
onSelectedExecutorProxy (val) {
this.editingAgent.executor_proxy = val
this.isProxyValidateError = val.length === 1 && val[0] !== this.username
},
// 更新代理人数据
async updateAgentData () {
if (this.pending.agent) {
if (this.pending.agent || this.isProxyValidateError) {
return
}
this.pending.agent = true
Expand All @@ -616,6 +623,10 @@
executor_proxy: this.editingAgent.executor_proxy.join(','),
executor_proxy_exempts: this.editingAgent.executor_proxy_exempts.join(',')
}
// 如果执行代理人没有修改则不传
if (this.agent.executor_proxy === data.executor_proxy) {
delete data.executor_proxy
}
const resp = await this.updateProjectConfig(data)
if (resp.result) {
this.isAgentDialogShow = false
Expand All @@ -628,6 +639,10 @@
this.pending.agent = false
}
},
closeAgentDialog () {
this.isProxyValidateError = false
this.isAgentDialogShow = false
},
// 获取人员分组数据
async getStaffGroupData () {
this.staffGroupLoading = true
Expand Down Expand Up @@ -1059,6 +1074,7 @@
}
.user-selector {
width: 100%;
display: block;
}
}
.create-variable-dialog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
:multiple="false"
@change="onUserSelectChange">
</bk-user-selector>
<p v-if="isProxyValidateError" class="form-error-tip">{{ $t('代理人仅可设置为本人') }}</p>
</bk-form-item>
</bk-form>
<!-- 子流程 -->
Expand Down Expand Up @@ -450,6 +451,7 @@
:multiple="false"
@change="onUserSelectChange">
</bk-user-selector>
<p v-if="isProxyValidateError" class="form-error-tip">{{ $t('代理人仅可设置为本人') }}</p>
</bk-form-item>
</bk-form>
</div>
Expand Down Expand Up @@ -562,6 +564,7 @@
}
]
},
isProxyValidateError: false,
errorHandleTipsConfig: {
allowHtml: true,
theme: 'light',
Expand All @@ -581,6 +584,7 @@
},
computed: {
...mapState({
'username': state => state.username,
'subprocessInfo': state => state.template.subprocess_info
}),
subflowHasUpdate () {
Expand Down Expand Up @@ -819,6 +823,7 @@
onUserSelectChange (tags) {
this.formData.executor_proxy = tags
this.updateData()
this.isProxyValidateError = tags.length === 1 && tags[0] !== this.username
},
async onAlwaysUseLatestChange (val) {
this.formData.alwaysUseLatest = val
Expand Down Expand Up @@ -1117,6 +1122,7 @@
}
}
.user-selector {
display: block;
width: 100%;
.disabled::before {
content: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,9 @@
// 节点配置面板表单校验,基础信息和输入参数
validate () {
return this.$refs.basicInfo.validate().then(validator => {
if (this.$refs.basicInfo.isProxyValidateError) {
return false
}
if (this.$refs.inputParams) {
return this.$refs.inputParams.validate()
} else if (this.$refs.jsonSchemaParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@
:disabled="isViewMode"
:placeholder="proxyPlaceholder"
:value="formData.executorProxy"
@change="formData.executorProxy = $event">
@change="onSelectedExecutorProxy">
</member-select>
<p v-if="isProxyValidateError" class="form-error-tip">{{ $t('代理人仅可设置为本人') }}</p>
<div class="executor-proxy-desc">
{{ $t('推荐留空使用') }}
<span
Expand Down Expand Up @@ -280,6 +281,7 @@
}
]
},
isProxyValidateError: false,
taskCategories: TASK_CATEGORIES,
labelDialogShow: false,
labelRules: {
Expand Down Expand Up @@ -408,6 +410,10 @@
default_flow_type: defaultFlowType
}
},
onSelectedExecutorProxy (val) {
this.formData.executorProxy = val
this.isProxyValidateError = val.length === 1 && val[0] !== this.username
},
jumpProjectManagement () {
if (this.isViewMode) return
if (this.authActions.includes('project_edit')) {
Expand All @@ -433,7 +439,7 @@
},
onSaveConfig () {
this.$refs.configForm.validate().then(result => {
if (!result) {
if (!result || this.isProxyValidateError) {
return
}
Expand Down
26 changes: 20 additions & 6 deletions frontend/desktop/src/store/modules/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const template = {
category: '',
description: '',
executor_proxy: '',
init_executor_proxy: '',
template_labels: '',
subprocess_info: {
details: [],
Expand Down Expand Up @@ -316,6 +317,7 @@ const template = {
state.notify_type = typeof notify_type === 'string' ? { success: JSON.parse(notify_type), fail: [] } : notify_type
state.description = description
state.executor_proxy = executor_proxy
state.init_executor_proxy = executor_proxy
state.template_labels = template_labels || []
state.time_out = time_out
state.category = category
Expand Down Expand Up @@ -353,6 +355,7 @@ const template = {
}
state.description = ''
state.executor_proxy = ''
state.init_executor_proxy = ''
state.template_labels = []
state.default_flow_type = 'common'
},
Expand All @@ -377,6 +380,7 @@ const template = {
}
state.description = ''
state.executor_proxy = ''
state.init_executor_proxy = ''
state.template_labels = []
state.default_flow_type = 'common'
},
Expand Down Expand Up @@ -926,7 +930,8 @@ const template = {
saveTemplateData ({ state }, { templateId, projectId, common }) {
const { activities, constants, end_event, flows, gateways, line,
location, outputs, start_event, notify_receivers, notify_type,
time_out, category, description, executor_proxy, template_labels, default_flow_type
time_out, category, description, executor_proxy, template_labels, default_flow_type,
init_executor_proxy
} = state
// 剔除 location 的冗余字段
const pureLocation = location.map(item => ({
Expand Down Expand Up @@ -986,9 +991,7 @@ const template = {
url = `${url}${templateId}/`
headers['X-HTTP-Method-Override'] = 'PATCH'
}

// 新增用post, 编辑用put
return axios[templateId === undefined ? 'post' : 'put'](url, {
const params = {
name,
project,
category,
Expand All @@ -1000,9 +1003,20 @@ const template = {
notify_type,
pipeline_tree: pipelineTree,
notify_receivers: notifyReceivers
}, {
}
// 更新时如果执行代理人没有修改则不传
if (templateId && init_executor_proxy === executor_proxy) {
delete params.executor_proxy
}

// 新增用post, 编辑用patch
const method = templateId === undefined ? 'post' : common ? 'put' : 'patch'
return axios[method](url, params, {
headers
}).then(response => response.data)
}).then(response => {
state.init_executor_proxy = state.executor_proxy
return response.data
})
},
// 自动排版
getLayoutedPipeline ({ commit }, data) {
Expand Down

0 comments on commit d1b458e

Please sign in to comment.