From fee2123b49b4f4e943f9b4304a2a88697c85c558 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:05:49 +0800 Subject: [PATCH 1/2] Perf: Add Account Change Or Move To Different Asset (#4567) * Perf: Add Account Change Or Move To Different Asset * Fixed: Fixed Add Account And Template input disabled * Perf: Add Account Operation Bulk Result --------- Co-authored-by: zhaojisen <1301338853@qq.com> --- .../Apps/AccountCreateUpdateForm/const.js | 53 ++++++++++++-- .../AccountListTable/AccountCreateUpdate.vue | 41 +++++++---- .../Apps/AccountListTable/AccountList.vue | 69 +++++++++++++++---- .../GenericCreateUpdateForm/index.vue | 26 ++++--- src/views/pam/Account/AccountList.vue | 2 +- 5 files changed, 148 insertions(+), 43 deletions(-) diff --git a/src/components/Apps/AccountCreateUpdateForm/const.js b/src/components/Apps/AccountCreateUpdateForm/const.js index 3cbcfc56d..fdaf10949 100644 --- a/src/components/Apps/AccountCreateUpdateForm/const.js +++ b/src/components/Apps/AccountCreateUpdateForm/const.js @@ -5,6 +5,9 @@ import AutomationParamsForm from '@/views/assets/Platform/AutomationParamsSettin export const accountFieldsMeta = (vm) => { const defaultPrivilegedAccounts = ['root', 'administrator'] + + const isPam = vm.$route.query.flag === 'copy' || vm.$route.query.flag === 'move' + return { assets: { component: Select2, @@ -27,6 +30,7 @@ export const accountFieldsMeta = (vm) => { component: Select2, rules: [Required], el: { + disabled: isPam, multiple: false, ajax: { url: '/api/v1/accounts/account-templates/', @@ -43,6 +47,9 @@ export const accountFieldsMeta = (vm) => { rules: [Required], label: vm.$t('AccountPolicy'), helpTip: vm.$t('AccountPolicyHelpText'), + el: { + disabled: isPam + }, hidden: () => { return vm.platform || vm.asset } @@ -50,6 +57,9 @@ export const accountFieldsMeta = (vm) => { name: { label: vm.$t('Name'), rules: [RequiredChange], + el: { + disabled: isPam + }, on: { input: ([value], updateForm) => { if (!vm.usernameChanged) { @@ -66,7 +76,7 @@ export const accountFieldsMeta = (vm) => { }, username: { el: { - disabled: !!vm.account?.name + disabled: !!vm.account?.name || isPam }, on: { input: ([value], updateForm) => { @@ -85,6 +95,9 @@ export const accountFieldsMeta = (vm) => { }, privileged: { label: vm.$t('Privileged'), + el: { + disabled: isPam + }, hidden: () => { return vm.addTemplate } @@ -97,6 +110,7 @@ export const accountFieldsMeta = (vm) => { el: { multiple: false, clearable: true, + disabled: isPam, ajax: { url: `/api/v1/accounts/accounts/su-from-accounts/?account=${vm.account?.id || ''}&asset=${vm.asset?.id || ''}`, transformOption: (item) => { @@ -107,6 +121,7 @@ export const accountFieldsMeta = (vm) => { }, su_from_username: { label: vm.$t('UserSwitchFrom'), + disabled: isPam, hidden: (formValue) => { return vm.platform || vm.asset || vm.addTemplate } @@ -115,39 +130,57 @@ export const accountFieldsMeta = (vm) => { label: vm.$t('Password'), component: UpdateToken, hidden: (formValue) => { - return formValue.secret_type !== 'password' || vm.addTemplate + return formValue.secret_type !== 'password' || vm.addTemplate || vm.$route.fullPath.includes('pam') } }, ssh_key: { label: vm.$t('PrivateKey'), component: UploadSecret, + el: { + disabled: isPam + }, hidden: (formValue) => formValue.secret_type !== 'ssh_key' || vm.addTemplate }, passphrase: { label: vm.$t('Passphrase'), component: UpdateToken, + el: { + disabled: isPam + }, hidden: (formValue) => formValue.secret_type !== 'ssh_key' || vm.addTemplate }, token: { label: vm.$t('Token'), component: UploadSecret, + el: { + disabled: isPam + }, hidden: (formValue) => formValue.secret_type !== 'token' || vm.addTemplate }, access_key: { id: 'access_key', label: vm.$t('AccessKey'), component: UploadSecret, + el: { + disabled: isPam + }, hidden: (formValue) => formValue.secret_type !== 'access_key' || vm.addTemplate }, api_key: { id: 'api_key', label: vm.$t('ApiKey'), component: UploadSecret, + el: { + disabled: isPam + }, hidden: (formValue) => formValue.secret_type !== 'api_key' || vm.addTemplate }, secret_type: { type: 'radio-group', options: [], + el: { + disabled: isPam + }, hidden: () => { return vm.addTemplate } @@ -182,10 +215,22 @@ export const accountFieldsMeta = (vm) => { } }, is_active: { - label: vm.$t('IsActive') + label: vm.$t('IsActive'), + el: { + disabled: isPam + } }, comment: { - label: vm.$t('Comment') + label: vm.$t('Comment'), + el: { + disabled: isPam + } + }, + secret_reset: { + label: vm.$t('SecretReset'), + el: { + disabled: isPam + } } } } diff --git a/src/components/Apps/AccountListTable/AccountCreateUpdate.vue b/src/components/Apps/AccountListTable/AccountCreateUpdate.vue index 458cf1f93..4b134ca06 100644 --- a/src/components/Apps/AccountListTable/AccountCreateUpdate.vue +++ b/src/components/Apps/AccountListTable/AccountCreateUpdate.vue @@ -4,7 +4,7 @@ :title="title" :visible="iVisible" class="drawer" - @close-drawer="iVisible = false" + @close-drawer="handleCloseDrawer" > @@ -109,18 +109,27 @@ export default { } }).catch(error => { this.iVisible = true - console.log(this.iVisible) - console.log(this.origin) this.handleResult(null, error) }) }, editAccount(form) { const data = { ...form } - this.$axios.patch(`/api/v1/accounts/accounts/${this.account.id}/`, data).then(() => { - this.iVisible = false - this.$emit('add', true) - this.$message.success(this.$tc('UpdateSuccessMsg')) - }).catch(error => this.setFieldError(error)) + const flag = this.$route.query.flag + + switch (flag) { + case 'copy': + this.handleAccountOperation(this.account.id, 'copy-to-assets', data) + break + case 'move': + this.handleAccountOperation(this.account.id, 'move-to-assets', data) + break + default: + this.$axios.patch(`/api/v1/accounts/accounts/${this.account.id}/`, data).then(() => { + this.iVisible = false + this.$emit('add', true) + this.$message.success(this.$tc('UpdateSuccessMsg')) + }).catch(error => this.setFieldError(error)) + } }, handleResult(resp, error) { let bulkCreate = !this.asset @@ -173,6 +182,18 @@ export default { refsAutoDataForm.setFieldError(current, err) } } + }, + handleCloseDrawer() { + this.iVisible = false + Reflect.deleteProperty(this.$route.query, 'flag') + }, + handleAccountOperation(id, path, data) { + this.$axios.post(`/api/v1/accounts/accounts/${id}/${path}/`, data).then((res) => { + this.iVisible = false + this.$emit('add', true) + this.handleResult(res, null) + this.$message.success(this.$tc('UpdateSuccessMsg')) + }).catch(error => this.handleResult(null, error)) } } } @@ -187,8 +208,4 @@ export default { } } } - -.content { -} - diff --git a/src/components/Apps/AccountListTable/AccountList.vue b/src/components/Apps/AccountListTable/AccountList.vue index 9be18b8d2..73434fa15 100644 --- a/src/components/Apps/AccountListTable/AccountList.vue +++ b/src/components/Apps/AccountListTable/AccountList.vue @@ -50,18 +50,28 @@ v-bind="updateSelectedDialogSetting" @update="handleAccountBulkUpdate" /> + - diff --git a/src/layout/components/GenericCreateUpdateForm/index.vue b/src/layout/components/GenericCreateUpdateForm/index.vue index 57a667117..6a5c00cf9 100644 --- a/src/layout/components/GenericCreateUpdateForm/index.vue +++ b/src/layout/components/GenericCreateUpdateForm/index.vue @@ -391,18 +391,22 @@ export default { async getCloneForm(cloneFrom) { const [curUrl, query] = this.url.split('?') const url = `${curUrl}${cloneFrom}/${query ? ('?' + query) : ''}` - const object = await this.getObjectDetail(url) - let name = '' - let attr = '' - if (object['name']) { - name = object['name'] - attr = 'name' - } else if (object['hostname']) { - name = object['hostname'] - attr = 'hostname' + try { + const object = await this.getObjectDetail(url) + let name = '' + let attr = '' + if (object['name']) { + name = object['name'] + attr = 'name' + } else if (object['hostname']) { + name = object['hostname'] + attr = 'hostname' + } + object[attr] = name + '-' + this.cloneNameSuffix.toString() + return object + } catch (e) { + throw new Error(`Error for reason: ${e.message}`) } - object[attr] = name + '-' + this.cloneNameSuffix.toString() - return object }, async getFormValue() { if (this.action === 'create' || !this.needGetObjectDetail) { diff --git a/src/views/pam/Account/AccountList.vue b/src/views/pam/Account/AccountList.vue index c51517924..fa3e001e2 100644 --- a/src/views/pam/Account/AccountList.vue +++ b/src/views/pam/Account/AccountList.vue @@ -56,7 +56,7 @@ export default { this.getPermdProtocols(row.asset.id) } }, - command: protocol => { + 'command': protocol => { this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', { key: row.id, value: protocol From 5022ca90751fb968d34387fa51d49d7e4476cd84 Mon Sep 17 00:00:00 2001 From: zhaojisen <1301338853@qq.com> Date: Fri, 3 Jan 2025 14:49:13 +0800 Subject: [PATCH 2/2] Perf: Remove Unused Tips and Function --- .../AccountListTable/AccountCreateUpdate.vue | 1 - .../Apps/AccountListTable/AccountList.vue | 32 +++++++------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/components/Apps/AccountListTable/AccountCreateUpdate.vue b/src/components/Apps/AccountListTable/AccountCreateUpdate.vue index 4b134ca06..fc18c03f1 100644 --- a/src/components/Apps/AccountListTable/AccountCreateUpdate.vue +++ b/src/components/Apps/AccountListTable/AccountCreateUpdate.vue @@ -192,7 +192,6 @@ export default { this.iVisible = false this.$emit('add', true) this.handleResult(res, null) - this.$message.success(this.$tc('UpdateSuccessMsg')) }).catch(error => this.handleResult(null, error)) } } diff --git a/src/components/Apps/AccountListTable/AccountList.vue b/src/components/Apps/AccountListTable/AccountList.vue index 73434fa15..4809b8acd 100644 --- a/src/components/Apps/AccountListTable/AccountList.vue +++ b/src/components/Apps/AccountListTable/AccountList.vue @@ -479,28 +479,22 @@ export default { title: '复制到其他资产', type: 'primary', divided: true, - callback: async({ row }) => { - await this.getAssetDetail() - this.$nextTick(() => { - vm.$route.query.flag = 'copy' - vm.iAsset = this.asset - vm.account = row - vm.showAddDialog = true - }) + callback: ({ row }) => { + vm.$route.query.flag = 'copy' + vm.iAsset = this.asset + vm.account = row + vm.showAddDialog = true } }, { name: 'MoveToOther', title: '移动到其他资产', type: 'primary', - callback: async({ row }) => { - await this.getAssetDetail() - this.$nextTick(() => { - vm.$route.query.flag = 'move' - vm.iAsset = this.asset - vm.account = row - vm.showAddDialog = true - }) + callback: ({ row }) => { + vm.$route.query.flag = 'move' + vm.iAsset = this.asset + vm.account = row + vm.showAddDialog = true } }, { @@ -539,8 +533,7 @@ export default { can: () => { return vm.$hasPerm('accounts.add_account') && !this.$store.getters.currentOrgIsRoot }, - callback: async() => { - await this.getAssetDetail() + callback: () => { setTimeout(() => { vm.iAsset = this.asset vm.account = {} @@ -555,8 +548,7 @@ export default { can: () => { return vm.$hasPerm('accounts.add_account') && !this.$store.getters.currentOrgIsRoot }, - callback: async() => { - await this.getAssetDetail() + callback: () => { setTimeout(() => { vm.iAsset = this.asset vm.account = {}