Skip to content

Commit

Permalink
perf: update perm
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler committed Oct 11, 2024
1 parent 1477712 commit a23a0d0
Show file tree
Hide file tree
Showing 25 changed files with 1,031 additions and 97 deletions.
41 changes: 36 additions & 5 deletions src/components/Apps/AccountListTable/AccountList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<script>
import ListTable from '@/components/Table/ListTable/index.vue'
import { ActionsFormatter } from '@/components/Table/TableFormatters'
import { ActionsFormatter, PlatformFormatter } from '@/components/Table/TableFormatters'
import ViewSecret from './ViewSecret.vue'
import UpdateSecretInfo from './UpdateSecretInfo.vue'
import AccountCreateUpdate from './AccountCreateUpdate.vue'
Expand Down Expand Up @@ -89,7 +89,7 @@ export default {
},
hasClone: {
type: Boolean,
default: false
default: true
},
asset: {
type: Object,
Expand Down Expand Up @@ -119,7 +119,7 @@ export default {
columnsDefault: {
type: Array,
default: () => ([
'name', 'username', 'asset', 'date_updated'
'name', 'username', 'secret', 'asset', 'platform', 'date_updated', 'connect'
])
},
headerExtraActions: {
Expand Down Expand Up @@ -153,6 +153,7 @@ export default {
},
extraQuery: this.extraQuery,
columnsExclude: ['spec_info'],
columnsAdd: ['secret', 'platform', 'connect'],
columnsShow: {
min: ['name', 'username', 'actions'],
default: this.columnsDefault
Expand All @@ -172,6 +173,28 @@ export default {
}
}
},
secret: {
formatter: () => {
// Todo: 通用的 formatter, 点击后 10s 后还原为 *
return (
<span class='secret'>
<i class='fa fa-clone'/> ******
</span>
)
}
},
connect: {
label: this.$t('Connect'),
formatter: () => {
return (
<span class='connect'>
<el-button type='primary' size='mini'>
<i class='fa fa-terminal'/>
</el-button>
</span>
)
}
},
asset: {
formatter: function(row) {
const to = {
Expand All @@ -185,6 +208,13 @@ export default {
}
}
},
platform: {
label: this.$t('Platform'),
formatter: PlatformFormatter,
formatterArgs: {
platformAttr: 'asset.platform'
}
},
username: {
width: '120px'
},
Expand Down Expand Up @@ -218,6 +248,7 @@ export default {
hasUpdate: false, // can set function(row, value)
hasDelete: false, // can set function(row, value)
hasClone: this.hasClone,
canClone: true,
moreActionsTitle: this.$t('More'),
extraActions: [
{
Expand Down Expand Up @@ -350,8 +381,8 @@ export default {
icon: 'fa-link',
can: ({ selectedRows }) => {
return selectedRows.length > 0 &&
['clickhouse', 'redis', 'website', 'chatgpt'].indexOf(selectedRows[0].asset.type.value) === -1 &&
!this.$store.getters.currentOrgIsRoot
['clickhouse', 'redis', 'website', 'chatgpt'].indexOf(selectedRows[0].asset.type.value) === -1 &&
!this.$store.getters.currentOrgIsRoot
},
callback: function({ selectedRows }) {
const ids = selectedRows.map(v => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Table/AutoDataTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ export default {

let configColumns = config.columns || allColumnNames
const columnsExclude = config.columnsExclude || []
const columnsAdd = config.columnsAdd || []
configColumns = configColumns.concat(columnsAdd)
configColumns = configColumns.filter(item => !columnsExclude.includes(item))

// 解决后端 API 返回字段中包含 actions 的问题;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/TableFormatters/ActionsFormatter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default {
{
name: 'clone',
title: this.$t('Duplicate'),
type: 'info',
type: 'primary',
has: colActions.hasClone,
can: colActions.canClone,
callback: colActions.onClone,
Expand Down
60 changes: 60 additions & 0 deletions src/components/Table/TableFormatters/PlatformFormatter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<span class="platform-td">
<span class="icon-zone">
<img :src="icon" alt="icon" class="asset-icon">
</span>
<span class="platform-name">{{ value.name }}</span>
</span>
</template>

<script>
import BaseFormatter from './base.vue'
import { loadPlatformIcon } from '@/utils/jms'
export default {
name: 'PlatformFormatter',
extends: BaseFormatter,
props: {
formatterArgsDefault: {
type: Object,
default() {
return {
platformAttr: ''
}
}
}
},
data() {
return {
formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs)
}
},
computed: {
icon() {
return loadPlatformIcon(this.value.name, this.value.type)
},
value() {
if (!this.formatterArgs.platformAttr) {
return this.cellValue
} else {
return _.get(this.row, this.formatterArgs.platformAttr)
}
}
},
methods: {}
}
</script>

<style scoped>
.icon-zone {
display: inline-block;
width: 1.5em;
}
.asset-icon {
height: 1.5em;
vertical-align: -0.2em;
fill: currentColor;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
v-if="item.has"
:key="index"
:content="item.tooltip"
:open-delay="500"
effect="dark"
open-delay="500"
placement="top"
>
<i :class="[item.class, item.icon]" class="fa" @click="item.action()" />
Expand Down
3 changes: 3 additions & 0 deletions src/components/Table/TableFormatters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ProtocolsFormatter from './ProtocolsFormatter.vue'
import TagChoicesFormatter from './TagChoicesFormatter.vue'
import SwitchFormatter from './SwitchFormatter.vue'
import AccountInfoFormatter from './AccountInfoFormatter.vue'
import PlatformFormatter from './PlatformFormatter.vue'

export default {
DetailFormatter,
Expand All @@ -39,6 +40,7 @@ export default {
TagChoicesFormatter,
LabelsFormatter,
SwitchFormatter,
PlatformFormatter,
AccountInfoFormatter
}

Expand All @@ -62,5 +64,6 @@ export {
TagChoicesFormatter,
LabelsFormatter,
SwitchFormatter,
PlatformFormatter,
AccountInfoFormatter
}
2 changes: 1 addition & 1 deletion src/layout/components/NavHeader/Organization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
]
}
const hasPerms = this.$hasPerm('orgs.view_organization | orgs.add_organization')
const isConsole = this.currentViewRoute.name === 'console'
const isConsole = ['console'].includes(this.currentViewRoute.name)
return hasPerms && isConsole ? orgActions : {}
},
orgChoicesGroup() {
Expand Down
2 changes: 1 addition & 1 deletion src/router/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
children: [
{
path: '/console/dashboard',
component: () => import('@/views/dashboard/Console/index'),
component: () => import('@/views/dashboard/Console/index.vue'),
name: 'AdminDashboard',
meta: {
icon: 'dashboard',
Expand Down
4 changes: 2 additions & 2 deletions src/router/pam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
children: [
{
path: '/pam/dashboard',
component: () => import('@/views/dashboard/Audit/index'),
component: () => import('@/views/dashboard/Pam/index'),
name: 'PamDashboard',
meta: {
icon: 'dashboard',
Expand All @@ -34,7 +34,7 @@ export default {
{
path: '/pam/accounts',
name: 'PamAccounts',
component: () => import('@/views/pam/Account/AccountList.vue'),
component: () => import('@/views/pam/Account/index.vue'),
meta: {
title: i18n.t('Accounts'),
icon: 'accounts',
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const actions = {
commit('SET_MFA_VERIFY')
},
changeToView({ commit }, viewName) {
console.log('Change to view')
const mapper = {
console: state.consoleOrgs,
audit: state.auditOrgs,
Expand Down
22 changes: 21 additions & 1 deletion src/utils/jms.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function getPermedViews() {
['audit', store.getters.auditOrgs.length > 0],
['workbench', true],
['tickets', hasPermission('tickets.view_ticket')],
['settings', hasPermission('settings.view_setting')]
['settings', hasPermission('settings.view_setting')],
['pam', store.getters.consoleOrgs.length > 0]
]
return viewShowMapper.filter(i => i[1]).map(i => i[0])
}
Expand Down Expand Up @@ -155,3 +156,22 @@ export function IsSupportPauseSessionType(terminalType) {
const supportedType = ['koko', 'lion', 'chen', 'kael']
return supportedType.includes(terminalType)
}

export function loadPlatformIcon(name, type) {
const platformMap = {
'Huawei': 'huawei',
'Cisco': 'cisco',
'Gateway': 'gateway',
'macOS': 'macos',
'BSD': 'bsd',
'Vmware-vSphere': 'vmware'
}

const value = platformMap[name] || type

try {
return require(`@/assets/img/icons/${value}.png`)
} catch (error) {
return require(`@/assets/img/icons/other.png`)
}
}
2 changes: 1 addition & 1 deletion src/utils/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function checkUserFirstLogin({ to, from, next }) {
export async function changeCurrentViewIfNeed({ to, from, next }) {
let viewName = to.path.split('/')[1]
// 这几个是需要检测的, 切换视图组织时,避免 404, 这里不能加 settings, 因为 默认没有返回 setting 组织(System) 的管理权限
if (['console', 'audit', 'workbench', 'tickets', ''].indexOf(viewName) === -1) {
if (['console', 'audit', 'workbench', 'tickets', 'pam', ''].indexOf(viewName) === -1) {
Vue.$log.debug('Current view no need check', viewName)
return
}
Expand Down
5 changes: 3 additions & 2 deletions src/views/assets/Asset/AssetList/components/BaseList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<script>
import { ListTable } from '@/components'
import {
ActionsFormatter, ArrayFormatter, ChoicesFormatter, DetailFormatter, ProtocolsFormatter
ActionsFormatter, ArrayFormatter, ChoicesFormatter, DetailFormatter, ProtocolsFormatter, PlatformFormatter
} from '@/components/Table/TableFormatters'
import AssetBulkUpdateDialog from './AssetBulkUpdateDialog'
import { connectivityMeta } from '@/components/Apps/AccountListTable/const'
Expand Down Expand Up @@ -144,7 +144,8 @@ export default {
sortable: true
},
platform: {
sortable: true
sortable: true,
formatter: PlatformFormatter
},
protocols: {
showFullContent: true,
Expand Down
28 changes: 9 additions & 19 deletions src/views/assets/Asset/AssetList/components/PlatformDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
shadow="hover"
@click.native="createAsset(platform)"
>
<img :src="loadImage(platform)" alt="icon" class="asset-icon">
<div class="icon-zone">
<img :src="loadImage(platform)" alt="icon" class="asset-icon">
</div>
<span class="platform-name">{{ platform.name }}</span>
</el-card>
</el-tooltip>
Expand All @@ -42,6 +44,7 @@
</template>
<script>
import Dialog from '@/components/Dialog'
import { loadPlatformIcon } from '@/utils/jms'
export default {
name: 'PlatformDialog',
Expand Down Expand Up @@ -126,23 +129,7 @@ export default {
},
methods: {
loadImage(platform) {
const platformMap = {
'Huawei': 'huawei',
'Cisco': 'cisco',
'Gateway': 'gateway',
'macOS': 'macos',
'BSD': 'bsd',
'Vmware-vSphere': 'vmware'
}
const value = platformMap[platform.name] || platform.type.value
try {
return require(`@/assets/img/icons/${value}.png`)
} catch (error) {
this.$log.debug(`Image not found: ${value}.png`)
return require(`@/assets/img/icons/other.png`)
}
return loadPlatformIcon(platform.name, platform.type)
},
loadRecentPlatformIds() {
const recentPlatformIds = JSON.parse(localStorage.getItem('RecentPlatforms')) || []
Expand Down Expand Up @@ -235,8 +222,11 @@ export default {
align-items: center;
}
.asset-icon {
.icon-zone {
width: 2em;
}
.asset-icon {
height: 2em;
vertical-align: -0.2em;
fill: currentColor;
Expand Down
Loading

0 comments on commit a23a0d0

Please sign in to comment.