feat: ad domain as asset

This commit is contained in:
ibuler
2025-04-02 19:14:40 +08:00
parent 9af896898e
commit a45d86c568
14 changed files with 126 additions and 31 deletions

View File

@@ -45,7 +45,6 @@ export default {
}, },
methods: { methods: {
createWatermark() { createWatermark() {
console.log('currentUser', this.currentUser)
if (this.currentUser?.username && this.publicSettings?.SECURITY_WATERMARK_ENABLED) { if (this.currentUser?.username && this.publicSettings?.SECURITY_WATERMARK_ENABLED) {
this.watermark = new Watermark({ this.watermark = new Watermark({
content: `${this.currentUser.username}(${this.currentUser.name})`, content: `${this.currentUser.username}(${this.currentUser.name})`,
@@ -53,7 +52,7 @@ export default {
height: 200, height: 200,
rotate: 45, rotate: 45,
fontWeight: 'normal', fontWeight: 'normal',
fontColor: 'rgba(128, 128, 128, 0.3)' fontColor: 'rgba(128, 128, 128, 0.2)'
}) })
this.watermark.create() this.watermark.create()

View File

@@ -6,6 +6,13 @@ import AutomationParamsForm from '@/views/assets/Platform/AutomationParamsSettin
export const accountFieldsMeta = (vm) => { export const accountFieldsMeta = (vm) => {
const defaultPrivilegedAccounts = ['root', 'administrator'] const defaultPrivilegedAccounts = ['root', 'administrator']
function onPrivilegedUser(value, updateForm) {
const maybePrivileged = defaultPrivilegedAccounts.includes(value)
if (maybePrivileged) {
updateForm({ privileged: true, secret_reset: false, push_now: false })
}
}
return { return {
assets: { assets: {
component: Select2, component: Select2,
@@ -70,11 +77,8 @@ export const accountFieldsMeta = (vm) => {
if (!vm.account?.name) { if (!vm.account?.name) {
updateForm({ username: value }) updateForm({ username: value })
} }
const maybePrivileged = defaultPrivilegedAccounts.includes(value)
if (maybePrivileged) {
updateForm({ privileged: true })
}
} }
onPrivilegedUser(value, updateForm)
} }
}, },
hidden: () => { hidden: () => {
@@ -92,10 +96,7 @@ export const accountFieldsMeta = (vm) => {
vm.usernameChanged = true vm.usernameChanged = true
}, },
change: ([value], updateForm) => { change: ([value], updateForm) => {
const maybePrivileged = defaultPrivilegedAccounts.includes(value) onPrivilegedUser(value, updateForm)
if (maybePrivileged) {
updateForm({ privileged: true })
}
} }
}, },
hidden: () => { hidden: () => {

View File

@@ -147,6 +147,10 @@ export default {
showActions: { showActions: {
type: Boolean, type: Boolean,
default: true default: true
},
target: {
type: Object,
default: null
} }
}, },
data() { data() {
@@ -182,7 +186,7 @@ export default {
}, },
columnsMeta: { columnsMeta: {
name: { name: {
width: '120px', minWidth: '120px',
formatterArgs: { formatterArgs: {
can: () => vm.$hasPerm('accounts.view_account'), can: () => vm.$hasPerm('accounts.view_account'),
getRoute: ({ row }) => ({ getRoute: ({ row }) => ({
@@ -234,7 +238,14 @@ export default {
} }
}, },
username: { username: {
width: '120px' minWidth: '120px',
formatter: function(row) {
if (row.ad_domain) {
return `${row.username}@${row.ad_domain}`
} else {
return row.username
}
}
}, },
secret_type: { secret_type: {
formatter: function(row) { formatter: function(row) {

View File

@@ -10,7 +10,7 @@
<span>{{ $t('No accounts') }}</span> <span>{{ $t('No accounts') }}</span>
</div> </div>
<div v-for="account of accountData" :key="account.id" class="detail-item"> <div v-for="account of accountData" :key="account.id" class="detail-item">
<span>{{ account.name }}({{ account.username }})</span> <span>{{ getDisplay(account) }}</span>
</div> </div>
</div> </div>
<el-button slot="reference" class="link-btn" plain size="mini" type="primary"> <el-button slot="reference" class="link-btn" plain size="mini" type="primary">
@@ -39,10 +39,20 @@ export default {
} }
}, },
methods: { methods: {
getDisplay(account) {
const { username, name } = account
if (username.startsWith('@')) {
return name
} else if (name === username) {
return username
} else {
return `${name}(${username})`
}
},
async getAsyncItems() { async getAsyncItems() {
this.loading = true this.loading = true
const userId = this.$route.params.id || 'self' const userId = this.$route.params.id || 'self'
const url = `/api/v1/perms/users/${userId}/assets/${this.row.id}` const url = `/api/v1/perms/users/${userId}/assets/${this.row.id}/`
this.$axios.get(url).then(res => { this.$axios.get(url).then(res => {
this.accountData = res?.permed_accounts || [] this.accountData = res?.permed_accounts || []
}).finally(() => { }).finally(() => {

View File

@@ -89,6 +89,9 @@ const actions = {
}) })
}) })
}, },
cleanPlatforms({ commit, dispatch, state }) {
state.platforms = []
},
addToRecentPlatforms({ commit, display, state }, platform) { addToRecentPlatforms({ commit, display, state }, platform) {
const recentPlatformIds = state.recentPlatformIds.filter(i => i !== platform.id) const recentPlatformIds = state.recentPlatformIds.filter(i => i !== platform.id)
recentPlatformIds.unshift(platform.id) recentPlatformIds.unshift(platform.id)

View File

@@ -0,0 +1,23 @@
<template>
<BaseAssetCreateUpdate v-bind="$data" />
</template>
<script>
import BaseAssetCreateUpdate from './BaseAssetCreateUpdate'
export default {
name: 'ADCreateUpdate',
components: { BaseAssetCreateUpdate },
data() {
return {
url: '/api/v1/assets/directories/',
addFields: [
[this.$t('Domain name'), ['domain_name'], 1]
]
}
}
}
</script>
<style>
</style>

View File

@@ -59,7 +59,7 @@ export default {
return { return {
title: this.$t('Test'), title: this.$t('Test'),
templateDialogVisible: false, templateDialogVisible: false,
columnsDefault: ['name', 'username', 'asset', 'connect'], columnsDefault: ['name', 'username', 'connect'],
headerExtraActions: [ headerExtraActions: [
{ {
name: this.$t('AccountTemplate'), name: this.$t('AccountTemplate'),
@@ -96,7 +96,7 @@ export default {
}, },
computed: { computed: {
iUrl() { iUrl() {
return this.url || `/api/v1/accounts/accounts/?asset=${this.object.id}` return this.url || `/api/v1/assets/assets/${this.object.id}/accounts/`
} }
}, },
methods: { methods: {

View File

@@ -0,0 +1,21 @@
<template>
<BaseList v-bind="tableConfig" />
</template>
<script>
import BaseList from './components/BaseList'
export default {
components: {
BaseList
},
data() {
return {
tableConfig: {
category: 'ad',
url: '/api/v1/assets/directories/'
}
}
}
}
</script>

View File

@@ -143,7 +143,8 @@ export default {
'custom': () => import('@/views/assets/Asset/AssetCreateUpdate/CustomCreateUpdate.vue'), 'custom': () => import('@/views/assets/Asset/AssetCreateUpdate/CustomCreateUpdate.vue'),
'cloud': () => import('@/views/assets/Asset/AssetCreateUpdate/CloudCreateUpdate.vue'), 'cloud': () => import('@/views/assets/Asset/AssetCreateUpdate/CloudCreateUpdate.vue'),
'device': () => import('@/views/assets/Asset/AssetCreateUpdate/DeviceCreateUpdate.vue'), 'device': () => import('@/views/assets/Asset/AssetCreateUpdate/DeviceCreateUpdate.vue'),
'database': () => import('@/views/assets/Asset/AssetCreateUpdate/DatabaseCreateUpdate.vue') 'database': () => import('@/views/assets/Asset/AssetCreateUpdate/DatabaseCreateUpdate.vue'),
'ad': () => import('@/views/assets/Asset/AssetCreateUpdate/ADCreateUpdate.vue')
}, },
createProps: {}, createProps: {},
showPlatform: false, showPlatform: false,

View File

@@ -76,7 +76,7 @@ export default {
platforms: [], platforms: [],
recentPlatformIds: [], recentPlatformIds: [],
loading: true, loading: true,
activeType: 'host', activeType: [],
recentUsedLabel: this.$t('RecentlyUsed'), recentUsedLabel: this.$t('RecentlyUsed'),
typeIconMapper: { typeIconMapper: {
linux: 'fa-linux', linux: 'fa-linux',
@@ -130,9 +130,7 @@ export default {
async created() { async created() {
this.platforms = await this.$store.dispatch('assets/getPlatforms') this.platforms = await this.$store.dispatch('assets/getPlatforms')
this.allRecentPlatforms = await this.$store.dispatch('assets/getRecentPlatforms') this.allRecentPlatforms = await this.$store.dispatch('assets/getRecentPlatforms')
if (this.allRecentPlatforms.length > 0) { this.activeType = Object.keys(this.iPlatforms)[0]
this.activeType = this.recentUsedLabel
}
this.loading = false this.loading = false
}, },
methods: { methods: {

View File

@@ -56,6 +56,12 @@ export default {
hidden: true, hidden: true,
component: () => import('@/views/assets/Asset/AssetList/WebList.vue') component: () => import('@/views/assets/Asset/AssetList/WebList.vue')
}, },
{
icon: 'fa-comment',
name: 'ad',
hidden: true,
component: () => import('@/views/assets/Asset/AssetList/ADList.vue')
},
{ {
icon: 'fa-comment', icon: 'fa-comment',
name: 'gpt', name: 'gpt',

View File

@@ -11,6 +11,7 @@
:has-reset="false" :has-reset="false"
:initial="initial" :initial="initial"
:url="url" :url="url"
@submitSuccess="onSubmitSuccess"
/> />
</div> </div>
</template> </template>
@@ -49,7 +50,8 @@ export default {
]], ]],
[this.$t('Config'), [ [this.$t('Config'), [
'protocols', 'su_enabled', 'su_method', 'protocols', 'su_enabled', 'su_method',
'domain_enabled', 'charset' 'domain_enabled', 'ad_enabled', 'ad',
'charset'
]], ]],
[this.$t('Automations'), ['automation']], [this.$t('Automations'), ['automation']],
[this.$t('Other'), ['comment']] [this.$t('Other'), ['comment']]
@@ -105,6 +107,9 @@ export default {
} }
}, },
methods: { methods: {
onSubmitSuccess() {
this.$store.dispatch('assets/cleanPlatforms')
},
updateSuMethodOptions() { updateSuMethodOptions() {
const options = this.suMethods.filter(i => { const options = this.suMethods.filter(i => {
return this.suMethodLimits.includes(i.value) return this.suMethodLimits.includes(i.value)
@@ -141,7 +146,6 @@ export default {
const constraints = await this.$axios.get(url) const constraints = await this.$axios.get(url)
this.defaultOptions = constraints this.defaultOptions = constraints
const fieldsCheck = ['domain_enabled', 'su_enabled']
let protocols = constraints?.protocols || [] let protocols = constraints?.protocols || []
protocols = protocols?.map(i => { protocols = protocols?.map(i => {
if (i.name === 'http') { if (i.name === 'http') {
@@ -151,6 +155,7 @@ export default {
}) })
this.fieldsMeta.protocols.el.choices = protocols this.fieldsMeta.protocols.el.choices = protocols
const fieldsCheck = ['domain_enabled', 'su_enabled', 'ad_enabled']
for (const field of fieldsCheck) { for (const field of fieldsCheck) {
const disabled = constraints[field] === false const disabled = constraints[field] === false
this.initial[field] = !disabled this.initial[field] = !disabled

View File

@@ -149,14 +149,7 @@ export default {
return `/api/v1/assets/platforms/?category=${this.tab.activeMenu}` return `/api/v1/assets/platforms/?category=${this.tab.activeMenu}`
} }
}, },
deactivated() {
window.localStorage.setItem('lastTab', this.tab.activeMenu)
},
activated() { activated() {
setTimeout(() => {
this.tab.activeMenu = window.localStorage.getItem('lastTab') || 'host'
this.$refs.genericListTable?.reloadTable()
}, 300)
}, },
async mounted() { async mounted() {
try { try {
@@ -173,9 +166,19 @@ export default {
this.tableConfig.url = this.url this.tableConfig.url = this.url
this.headerActions.importOptions.url = this.url this.headerActions.importOptions.url = this.url
this.headerActions.exportOptions.url = this.url this.headerActions.exportOptions.url = this.url
this.headerActions.moreCreates.dropdown = this.$store.state.assets.assetCategoriesDropdown.filter(item => { const types = this.$store.state.assets.assetCategoriesDropdown.filter(item => {
return item.category === this.tab.activeMenu return item.category === this.tab.activeMenu
}).map(item => {
if (!item.group) {
return item
} else {
return {
...item,
group: item.group + this.$t('WordSep') + this.$t('Type')
}
}
}) })
this.headerActions.moreCreates.dropdown = types
}, },
async setCategoriesTab() { async setCategoriesTab() {
const categoryIcon = { const categoryIcon = {
@@ -185,6 +188,7 @@ export default {
cloud: 'fa-cloud', cloud: 'fa-cloud',
web: 'fa-globe', web: 'fa-globe',
gpt: 'fa-comment', gpt: 'fa-comment',
ad: 'fa-comment',
custom: 'fa-cube' custom: 'fa-cube'
} }
const state = await this.$store.dispatch('assets/getAssetCategories') const state = await this.$store.dispatch('assets/getAssetCategories')

View File

@@ -81,6 +81,19 @@ export const platformFieldsMeta = (vm) => {
disabled: false disabled: false
} }
}, },
ad_enabled: {
el: {
disabled: false
}
},
ad: {
el: {
multiple: false,
url: '/api/v1/assets/directories/',
disabled: false
},
hidden: (formValue) => !formValue['ad_enabled']
},
protocols: { protocols: {
label: i18n.t('SupportedProtocol'), label: i18n.t('SupportedProtocol'),
...assetMeta.protocols, ...assetMeta.protocols,