perf: 修改账号模版

This commit is contained in:
ibuler
2023-08-28 15:19:20 +08:00
parent 38ea835df5
commit e0411010d1
6 changed files with 177 additions and 50 deletions

View File

@@ -2,21 +2,23 @@
<div>
<div>
<el-button
:disabled="isDisabled"
size="mini"
type="primary"
:disabled="isDisabled"
@click="onOpenDialog"
>{{ $tc('common.Setting') }}</el-button>
>
{{ $tc('common.Setting') }}
</el-button>
</div>
<Dialog
v-if="visible"
width="60%"
:visible.sync="visible"
:title="title"
:destroy-on-close="true"
:show-cancel="false"
:show-confirm="false"
:destroy-on-close="true"
:title="title"
:visible.sync="visible"
v-bind="$attrs"
width="60%"
v-on="$listeners"
>
<AutoDataForm
@@ -31,7 +33,7 @@
</template>
<script>
import { Dialog, AutoDataForm } from '@/components'
import { AutoDataForm, Dialog } from '@/components'
export default {
componentName: 'AutomationParams',
@@ -58,6 +60,10 @@ export default {
type: Array,
default: () => []
},
platforms: {
type: Array,
default: () => []
},
method: {
type: String,
default: ''
@@ -68,13 +74,12 @@ export default {
}
},
data() {
const vm = this
return {
remoteMeta: {},
visible: false,
isDisabled: true,
form: this.value,
node_ids: this.nodes,
asset_ids: this.assets,
config: {
url: this.url,
hasSaveContinue: false,
@@ -82,7 +87,8 @@ export default {
method: 'get',
fields: [],
fieldsMeta: {}
}
},
onFieldChangeHandler: _.debounce(vm.handleFieldChange, 1000)
}
},
computed: {
@@ -92,22 +98,29 @@ export default {
},
watch: {
nodes: {
handler(val) {
this.node_ids = val
this.onFieldChangeHandle()
handler() {
this.onFieldChangeHandler()
},
deep: true
},
assets: {
handler(val) {
this.asset_ids = val
this.onFieldChangeHandle()
handler() {
this.onFieldChangeHandler()
},
deep: true
},
platforms: {
handler(newVal) {
console.log('Found platforms change, ', newVal.length)
this.onFieldChangeHandler()
},
deep: true,
immediate: true
}
},
created() {
this.getUrlMeta()
async mounted() {
await this.getUrlMeta()
await this.handleFieldChange()
},
methods: {
async getUrlMeta() {
@@ -115,34 +128,35 @@ export default {
this.remoteMeta = data.actions[this.config.method.toUpperCase()] || {}
},
async getFilterPlatforms() {
console.log('this.Platforms', this.platforms)
return await this.$axios.post(
'/api/v1/assets/platforms/filter-nodes-assets/',
{
'node_ids': this.node_ids,
'asset_ids': this.asset_ids
'node_ids': this.nodes,
'asset_ids': this.assets,
'platform_ids': this.platforms.map(i => i.id || i.pk || i)
}
)
},
async onFieldChangeHandle() {
async handleFieldChange() {
const platforms = await this.getFilterPlatforms()
let pushAccountMethods = platforms.map(i => i.automation[this.method])
pushAccountMethods = _.uniq(pushAccountMethods)
// 检测是否有可设置的推送方式
const hasCanSettingPushMethods = _.intersection(pushAccountMethods, Object.keys(this.remoteMeta))
this.setFormConfig(hasCanSettingPushMethods)
if (hasCanSettingPushMethods.length > 0) {
this.isDisabled = false
this.$emit('input', this.form)
} else {
this.isDisabled = true
this.$emit('input', {})
}
this.isDisabled = hasCanSettingPushMethods.length <= 0
},
setFormConfig(methods) {
const newForm = {}
const fields = []
const fieldsMeta = {}
this.config.fields = []
// Todo: 未来改成后端处理,生成 serializer, 这里就不用判断类型了
const typeMapper = {
'string': 'input',
'boolean': 'switch'
}
for (const method of methods) {
const filterField = this.remoteMeta[method] || {}
@@ -159,7 +173,7 @@ export default {
for (const [k, v] of Object.entries(filterField.children)) {
const item = {
...v,
type: 'input'
type: typeMapper[v.type] || 'input'
}
delete item.default
fieldsMeta[method].fields.push(k)
@@ -176,8 +190,11 @@ export default {
this.visible = true
},
onSubmit(form) {
this.visible = false
this.form = form
this.$emit('input', form)
setTimeout(() => {
this.visible = false
}, 100)
this.$log.debug('Auto push form:', form)
}
}

View File

@@ -115,7 +115,10 @@
"AccountExportTips": "The exported information contains account secret, which involves sensitive information. The exported format is an encrypted zip file (if no encryption password is set, please go to personal information to set the file encryption password).",
"TaskID": "Task ID",
"AccountTemplate": "Account template",
"AddAccountResult": "Add account result"
"AddAccountResult": "Add account result",
"AutoPush": "Auto Push",
"GeneralAccounts": "General Accounts",
"VirtualAccounts": "Virtual Accounts"
},
"acl": {
"CommandFilterACLHelpMsg": "You can control whether commands can be executed on assets. Based on the rules, certain commands can be allowed while others are prohibited.",
@@ -1202,7 +1205,8 @@
"userCount": "User count",
"userGroupCount": "User group count",
"usersAndUserGroups": "Users and user groups",
"Account": "Account"
"Account": "Account",
"AnonymousAccount": "Anonymous Account"
},
"route": {
"": "",
@@ -1421,7 +1425,23 @@
"ConnectMethodAclDetail": "Connect method acl detail",
"ConnectMethodAclCreate": "Create connect method acl",
"ConnectMethodAclList": "Connect method acl",
"ConnectMethodAclUpdate": "Update connect method acl"
"ConnectMethodAclUpdate": "Update connect method acl",
"HostCreate": "Create Asset - Host",
"DatabaseCreate": "Create Asset - Database",
"DeviceCreate": "Create Asset - Network Device",
"CustomUpdate": "Update Asset - Custom",
"HostUpdate": "Update Asset - Host",
"WebCreate": "Create Asset - Web",
"WebUpdate": "Update Asset - Web",
"CustomCreate": "Create Asset - Custom",
"VirtualAccountUpdate": "Virtual Account Update",
"GPTUpdate": "Update Asset - GPT",
"GPTCreate": "Create Asset - GPT",
"VirtualAccountDetail": "Virtual Account Details",
"DeviceUpdate": "Update Asset - Network Device",
"CloudCreate": "Create Asset - Cloud Platform",
"DatabaseUpdate": "Update Asset - Database",
"CloudUpdate": "Update Asset - Cloud Platform"
},
"rbac": {
"Permissions": "Permissions",
@@ -1762,7 +1782,9 @@
"authCASAttrMap": "User Attribute Mapping",
"SignaturesAndTemplates": "Signatures and Templates",
"SystemTools": "Tools",
"BasicTools": "Basic tool"
"BasicTools": "Basic tool",
"sync": "Sync",
"AccountStorage": "Account Storage"
},
"tickets": {
"BatchApproval": "Batch approval",
@@ -2256,4 +2278,4 @@
"PublishStatus": "Publish status",
"NoPublished": "Unpublished"
}
}
}

View File

@@ -115,7 +115,10 @@
"AccountExportTips": "エクスポート情報には機密情報を含むアカウント暗号文が含まれており、エクスポートされたフォーマットは暗号化されたzipファイルです暗号化パスワードが設定されていない場合は、個人情報にファイル暗号化パスワードを設定してください。",
"TaskID": "タスク ID",
"AccountTemplate": "账号模版",
"AddAccountResult": "账号批量添加结果"
"AddAccountResult": "账号批量添加结果",
"AutoPush": "自動プッシュ",
"GeneralAccounts": "一般アカウント",
"VirtualAccounts": "仮想アカウント"
},
"acl": {
"CommandFilterACLHelpMsg": "コマンドフィルタリングを使用すると、コマンドがアセット上で実行されるかどうかを制御できます。ルールに基づいて、特定のコマンドは許可され、他のコマンドは禁止されることがあります。",
@@ -1201,7 +1204,8 @@
"userGroupCount": "ユーザーグループ数",
"usersAndUserGroups": "ユーザーまたはユーザーグループ",
"Account": "アカウント",
"ManualAccount": "手动账号"
"ManualAccount": "手动账号",
"AnonymousAccount": "匿名アカウント"
},
"route": {
"": "",
@@ -1416,7 +1420,23 @@
"ConnectMethodAclList": "接続方式",
"ConnectMethodAclDetail": "接続方式制御の詳細",
"UserLoginAclDetail": "ユーザーログイン制御の詳細",
"ConnectMethodAclUpdate": "接続方式制御ルールの更新"
"ConnectMethodAclUpdate": "接続方式制御ルールの更新",
"HostCreate": "アセット作成 - ホスト",
"DatabaseCreate": "アセット作成 - データベース",
"DeviceCreate": "アセット作成 - ネットワークデバイス",
"CustomUpdate": "アセット更新 - カスタム",
"HostUpdate": "アセット更新 - ホスト",
"WebCreate": "アセット作成 - ウェブ",
"WebUpdate": "アセット更新 - ウェブ",
"CustomCreate": "アセット作成 - カスタム",
"VirtualAccountUpdate": "仮想アカウント更新",
"GPTUpdate": "アセット更新 - GPT",
"GPTCreate": "アセット作成 - GPT",
"VirtualAccountDetail": "仮想アカウント詳細",
"DeviceUpdate": "アセット更新 - ネットワークデバイス",
"CloudCreate": "アセット作成 - クラウドプラットフォーム",
"DatabaseUpdate": "アセット更新 - データベース",
"CloudUpdate": "アセット更新 - クラウドプラットフォーム"
},
"rbac": {
"Permissions": "権限",
@@ -1755,7 +1775,9 @@
"TestParam": "パラメーター",
"testHelpText": "テストの宛先アドレスを入力してください",
"SMSProvider": "メールサービス業者 / プロトコル",
"Applets": "リモート アプリケーション"
"Applets": "リモート アプリケーション",
"sync": "同期",
"AccountStorage": "アカウントストレージ"
},
"tickets": {
"BatchApproval": "大量承認です",
@@ -2248,4 +2270,4 @@
"PublishStatus": "投稿ステータス",
"NoPublished": "未発表"
}
}
}

View File

@@ -1,6 +1,7 @@
{
"": "",
"accounts": {
"AutoPush": "自动推送",
"GeneralAccounts": "普通账号",
"VirtualAccounts": "虚拟账号",
"Accounts": "账号",

View File

@@ -13,15 +13,26 @@ export default {
GenericCreateUpdatePage
},
data() {
const vm = this
return {
initial: { secret_type: 'password' },
initial: {
secret_type: 'password',
push_params: { }
},
url: '/api/v1/accounts/account-templates/',
hasDetailInMsg: false,
fields: [
...templateFields(this)
...templateFields(vm)
],
fieldsMeta: {
...templateFieldsMeta(this)
...templateFieldsMeta(vm)
},
afterGetFormValue(value) {
if (!value.platforms) {
return
}
vm.fieldsMeta['push_params'].el.platforms = value['platforms']
return value
},
cleanFormValue(value) {
Object.keys(value).forEach((item, index, arr) => {

View File

@@ -1,20 +1,26 @@
import { getUuidUpdateFromUrl } from '@/utils/common'
import { UpdateToken } from '@/components/Form/FormFields'
import Select2 from '@/components/Form/FormFields/Select2'
import AutomationParams from '@/components/Apps/AutomationParams'
export const templateFields = (vm) => {
return [
[vm.$t('common.Basic'), ['name', 'username', 'privileged', 'su_from']],
[vm.$t('assets.Secret'), [
'secret_type', 'secret', 'ssh_key', 'token',
'secret_type', 'secret_strategy', 'secret', 'ssh_key', 'token',
'access_key', 'passphrase', 'api_key'
]],
[vm.$t('accounts.AutoPush'), [
'auto_push', 'platforms', 'push_params'
]],
[vm.$t('common.Other'), ['comment']]
]
}
export const templateFieldsMeta = (vm) => {
const id = getUuidUpdateFromUrl(vm.$route.path)
const platformIds = []
const canRandomSecretTypes = ['password']
return {
su_from: {
component: Select2,
@@ -29,10 +35,26 @@ export const templateFieldsMeta = (vm) => {
}
}
},
secret_type: {
on: {
change: ([event], updateForm) => {
if (!canRandomSecretTypes.includes(event)) {
updateForm({ secret_strategy: 'specific' })
}
}
}
},
secret_strategy: {
hidden: (formValue) => {
return !canRandomSecretTypes.includes(formValue.secret_type)
}
},
secret: {
label: vm.$t('assets.Password'),
component: UpdateToken,
hidden: (formValue) => formValue.secret_type !== 'password'
hidden: (formValue) => {
return formValue.secret_type !== 'password' || formValue.secret_strategy === 'random'
}
},
ssh_key: {
label: vm.$t('assets.PrivateKey'),
@@ -40,12 +62,12 @@ export const templateFieldsMeta = (vm) => {
type: 'textarea',
rows: 4
},
hidden: (formValue) => formValue.secret_type !== 'ssh_key'
hidden: (formValue) => formValue.secret_type !== 'ssh_key' || formValue.secret_strategy === 'random'
},
passphrase: {
label: vm.$t('assets.Passphrase'),
component: UpdateToken,
hidden: (formValue) => formValue.secret_type !== 'ssh_key'
hidden: (formValue) => formValue.secret_type !== 'ssh_key' || formValue.secret_strategy === 'random'
},
token: {
label: vm.$t('assets.Token'),
@@ -53,7 +75,7 @@ export const templateFieldsMeta = (vm) => {
type: 'textarea',
rows: 4
},
hidden: (formValue) => formValue.secret_type !== 'token'
hidden: (formValue) => formValue.secret_type !== 'token' || formValue.secret_strategy === 'random'
},
access_key: {
label: vm.$t('assets.AccessKey'),
@@ -61,7 +83,7 @@ export const templateFieldsMeta = (vm) => {
type: 'textarea',
rows: 4
},
hidden: (formValue) => formValue.secret_type !== 'access_key'
hidden: (formValue) => formValue.secret_type !== 'access_key' || formValue.secret_strategy === 'random'
},
api_key: {
label: vm.$t('assets.ApiKey'),
@@ -69,7 +91,39 @@ export const templateFieldsMeta = (vm) => {
type: 'textarea',
rows: 4
},
hidden: (formValue) => formValue.secret_type !== 'api_key'
hidden: (formValue) => formValue.secret_type !== 'api_key' || formValue.secret_strategy === 'random'
},
platforms: {
el: {
multiple: true,
ajax: {
url: `/api/v1/assets/platforms/`,
transformOption: (item) => {
return { label: item.name, value: item.id }
}
}
},
on: {
change: ([event], updateForm) => {
platformIds.splice(0, platformIds.length)
platformIds.push(...event)
console.log('On platfrom change: ', platformIds)
console.log(vm.fieldsMeta)
}
},
hidden: (formValue) => {
return !formValue['auto_push']
}
},
push_params: {
component: AutomationParams,
el: {
platforms: platformIds,
method: 'push_account_method'
},
hidden: (formValue) => {
return !formValue['auto_push']
}
}
}
}