Merge pull request #3111 from jumpserver/pr@dev@account_template

feat: 账号模版 切换自
This commit is contained in:
feng626 2023-05-09 15:29:15 +08:00 committed by GitHub
commit e80b162eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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,