diff --git a/src/components/AccountCreateUpdateForm/index.vue b/src/components/AccountCreateUpdateForm/index.vue index 087fdbeb1..536132c3c 100644 --- a/src/components/AccountCreateUpdateForm/index.vue +++ b/src/components/AccountCreateUpdateForm/index.vue @@ -65,7 +65,7 @@ export default { fields: [ [this.$t('assets.Asset'), ['assets']], [this.$t('accounts.AccountTemplate'), ['template']], - [this.$t('common.Basic'), ['name', 'username', 'privileged', 'su_from']], + [this.$t('common.Basic'), ['name', 'username', 'privileged', 'su_from', 'su_from_username']], [this.$t('assets.Secret'), [ 'secret_type', 'secret', 'ssh_key', 'token', 'access_key', 'passphrase' @@ -167,6 +167,12 @@ export default { } } }, + su_from_username: { + label: this.$t('assets.UserSwitchFrom'), + hidden: (formValue) => { + return this.platform || this.asset + } + }, secret: { label: this.$t('assets.Password'), component: UpdateToken, diff --git a/src/utils/common.js b/src/utils/common.js index fdac73aa8..ca159fd14 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -156,6 +156,7 @@ export function formatDate(inputTime) { } const uuidPattern = /[0-9a-zA-Z\-]{36}/ +const uuidRegex = /\/([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12})\// export function hasUUID(path) { const index = path.indexOf('?') @@ -165,6 +166,15 @@ export function hasUUID(path) { return path.search(uuidPattern) !== -1 } +export function getUuidUpdateFromUrl(path) { + const matches = uuidRegex.exec(path) + if (matches !== null) { + return matches[1] + } else { + return '' + } +} + export function replaceUUID(s, n) { const index = s.search(uuidPattern) if (index > 0) return s.substr(0, index) diff --git a/src/views/accounts/AccountTemplate/const.js b/src/views/accounts/AccountTemplate/const.js index 802453524..79ce0ad05 100644 --- a/src/views/accounts/AccountTemplate/const.js +++ b/src/views/accounts/AccountTemplate/const.js @@ -1,8 +1,10 @@ +import { getUuidUpdateFromUrl } from '@/utils/common' import { UpdateToken } from '@/components/FormFields' +import Select2 from '@/components/FormFields/Select2' export const templateFields = (vm) => { return [ - [vm.$t('common.Basic'), ['name', 'username', 'privileged']], + [vm.$t('common.Basic'), ['name', 'username', 'privileged', 'su_from']], [vm.$t('assets.Secret'), [ 'secret_type', 'secret', 'ssh_key', 'token', 'access_key', 'passphrase' @@ -12,7 +14,21 @@ export const templateFields = (vm) => { } export const templateFieldsMeta = (vm) => { + const id = getUuidUpdateFromUrl(vm.$route.path) return { + su_from: { + component: Select2, + el: { + multiple: false, + clearable: true, + ajax: { + url: `/api/v1/accounts/account-templates/su-from-account-templates/?${id ? 'template_id=' + id : ''}`, + transformOption: (item) => { + return { label: `${item.name}(${item.username})`, value: item.id } + } + } + } + }, secret: { label: vm.$t('assets.Password'), component: UpdateToken,