Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
OrangeM21
2020-06-11 18:29:53 +08:00
11 changed files with 106 additions and 80 deletions

View File

@@ -538,7 +538,10 @@
"terminate": "终断", "terminate": "终断",
"test": "测试", "test": "测试",
"type": "类型", "type": "类型",
"user": "用户" "user": "用户",
"riskLevels": {
"common": "普通"
}
}, },
"setting": { "setting": {
"Secret": "密钥", "Secret": "密钥",

View File

@@ -533,7 +533,10 @@
"terminate": "Terminate", "terminate": "Terminate",
"test": "Test", "test": "Test",
"type": "Type", "type": "Type",
"user": "Use" "user": "Use",
"riskLevels": {
"common": "common"
}
}, },
"setting": { "setting": {
"Basic": "Basic setting", "Basic": "Basic setting",

View File

@@ -4,8 +4,7 @@
ref="form" ref="form"
:method="method" :method="method"
:form="form" :form="form"
:fields="fields" :url="iUrl"
:url="totalUrl"
:is-submitting="isSubmitting" :is-submitting="isSubmitting"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
@@ -24,12 +23,6 @@ export default {
type: String, type: String,
default: '' default: ''
}, },
fields: {
type: Array,
default: () => {
return []
}
},
object: { object: {
type: Object, type: Object,
default: null default: null
@@ -48,7 +41,9 @@ export default {
}, },
performSubmit: { performSubmit: {
type: Function, type: Function,
default: null default(validValues) {
return this.$axios[this.method](this.iUrl, validValues)
}
}, },
createSuccessMsg: { createSuccessMsg: {
type: String, type: String,
@@ -76,6 +71,12 @@ export default {
return { name: routeName } return { name: routeName }
} }
}, },
getNextRoute: {
type: Function,
default(res, method) {
return method === 'post' ? this.createSuccessNextRoute : this.updateSuccessNextRoute
}
},
getMethod: { getMethod: {
type: Function, type: Function,
default: function() { default: function() {
@@ -87,12 +88,6 @@ export default {
} }
} }
}, },
getNextRoute: {
type: Function,
default(res, method) {
return method === 'post' ? this.createSuccessNextRoute : this.updateSuccessNextRoute
}
},
getUrl: { getUrl: {
type: Function, type: Function,
default: function() { default: function() {
@@ -103,6 +98,33 @@ export default {
} }
return url return url
} }
},
onPerformSuccess: {
type: Function,
default(res, method, vm) {
const msg = method === 'post' ? this.createSuccessMsg : this.updateSuccessMsg
const route = this.getNextRoute(res, method)
this.$emit('submitSuccess', res)
this.$message.success(msg)
setTimeout(() => this.$router.push(route), 100)
}
},
onPerformError: {
type: Function,
default(error, method, vm) {
this.$emit('submitError', error)
const response = error.response
const data = response.data
if (response.status === 400) {
for (const key of Object.keys(data)) {
let value = data[key]
if (value instanceof Array) {
value = value.join(';')
}
this.$refs.form.setFieldError(key, value)
}
}
}
} }
}, },
data() { data() {
@@ -116,11 +138,11 @@ export default {
method() { method() {
return this.getMethod(this) return this.getMethod(this)
}, },
totalUrl() { iUrl() {
return this.getUrl() return this.getUrl()
} }
}, },
async mounted() { async created() {
this.loading = true this.loading = true
try { try {
const values = await this.getFormValue() const values = await this.getFormValue()
@@ -136,36 +158,12 @@ export default {
values = this.cleanFormValue(values) values = this.cleanFormValue(values)
return handler(values) return handler(values)
}, },
defaultPerformSubmit(validValues) {
return this.$axios[this.method](this.totalUrl, validValues)
},
defaultOnSubmit(validValues) { defaultOnSubmit(validValues) {
const performSubmit = this.performSubmit || this.defaultPerformSubmit
const msg = this.method === 'post' ? this.createSuccessMsg : this.updateSuccessMsg
const event = this.method === 'post' ? 'createSuccess' : 'updateSuccess'
this.isSubmitting = true this.isSubmitting = true
performSubmit(validValues).then((res) => { this.performSubmit(validValues)
const route = this.getNextRoute(res, this.method) .then((res) => this.onPerformSuccess.bind(this)(res, this.method, this))
this.$emit(event, res) .catch((error) => this.onPerformError(error, this.method, this))
this.$emit('submitSuccess', res) .finally(() => { this.isSubmitting = false })
this.$message.success(msg)
setTimeout(() => this.$router.push(route), 100)
}).catch(error => {
this.$emit('submitError', error)
const response = error.response
const data = response.data
if (response.status === 400) {
for (const key of Object.keys(data)) {
let value = data[key]
if (value instanceof Array) {
value = value.join(';')
}
this.$refs.form.setFieldError(key, value)
}
}
}).finally(() => {
this.isSubmitting = false
})
}, },
async getFormValue() { async getFormValue() {
if (this.method !== 'put') { if (this.method !== 'put') {
@@ -174,11 +172,12 @@ export default {
let object = this.object let object = this.object
if (object === null) { if (object === null) {
object = await this.getObjectDetail() object = await this.getObjectDetail()
this.$emit('update:object', object)
} }
return object return object
}, },
async getObjectDetail() { async getObjectDetail() {
return this.$axios.get(this.totalUrl) return this.$axios.get(this.iUrl)
} }
} }
} }

View File

@@ -37,6 +37,9 @@ const mutations = {
SET_ORGS: (state, orgs) => { SET_ORGS: (state, orgs) => {
state.orgs = orgs state.orgs = orgs
}, },
ADD_ORG: (state, org) => {
state.orgs.push(org)
},
SET_ROLES(state, roles) { SET_ROLES(state, roles) {
state.roles = roles state.roles = roles
}, },
@@ -119,6 +122,9 @@ const actions = {
}).catch((e) => reject(e)) }).catch((e) => reject(e))
}) })
}, },
addAdminOrg({ commit, state }, org) {
commit('ADD_ORG', org)
},
// user logout // user logout
logout({ commit, state }) { logout({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@@ -9,7 +9,7 @@
</el-row> </el-row>
</template>a </template>a
<script> <script type="text/jsx">
import DetailCard from '@/components/DetailCard' import DetailCard from '@/components/DetailCard'
import QuickActions from '@/components/QuickActions' import QuickActions from '@/components/QuickActions'
import { toSafeLocalDateStr } from '@/utils/common' import { toSafeLocalDateStr } from '@/utils/common'
@@ -99,8 +99,13 @@ export default {
key: this.$t('users.IsActive') key: this.$t('users.IsActive')
}, },
{ {
value: `${this.object.public_key_comment} ${this.object.public_key_hash_md5}`, value: this.object,
key: 'SSHKey' key: 'SSHKey',
formatter: (item, val) => {
const comment = val.public_key_comment
const md5 = val.public_key_hash_md5
return <span>{ comment } <br /> { md5 }</span>
}
}, },
{ {
value: this.object.mfa_level_display, value: this.object.mfa_level_display,

View File

@@ -11,7 +11,7 @@ export default {
GenericCreateUpdatePage GenericCreateUpdatePage
}, },
data() { data() {
const appType = this.$route.query.type const appType = this.$route.query.type || 'chrome'
const fieldsMap = REMOTE_APP_TYPE_FIELDS_MAP[appType] const fieldsMap = REMOTE_APP_TYPE_FIELDS_MAP[appType]
const appTypeMeta = REMOTE_APP_TYPE_META_MAP[appType] const appTypeMeta = REMOTE_APP_TYPE_META_MAP[appType]
const pathInitial = REMOTE_APP_PATH_DEFAULT_MAP[appType] const pathInitial = REMOTE_APP_PATH_DEFAULT_MAP[appType]

View File

@@ -15,7 +15,7 @@ export default {
name: 'RulesCreateUpdate', name: 'RulesCreateUpdate',
components: { GenericCreateUpdatePage }, components: { GenericCreateUpdatePage },
data() { data() {
const filterId = this.$route.query.filter const filterId = this.$route.query.filter || '00000000-0000-0000-0000-000000000000'
const regexPlaceholder = 'rm.*|reboot|shutdown' const regexPlaceholder = 'rm.*|reboot|shutdown'
const commandPlaceholder = 'rm\rreboot' const commandPlaceholder = 'rm\rreboot'
const commandHelpText = this.$t('assets.CommandFilterRuleContentHelpText') const commandHelpText = this.$t('assets.CommandFilterRuleContentHelpText')
@@ -41,7 +41,7 @@ export default {
multiple: false multiple: false
} }
}, },
'action.value': { type: {
on: { on: {
change: ([val]) => { change: ([val]) => {
if (val === 'command') { if (val === 'command') {
@@ -81,11 +81,6 @@ export default {
}, },
url: `/api/v1/assets/cmd-filters/${filterId}/rules/` url: `/api/v1/assets/cmd-filters/${filterId}/rules/`
} }
},
computed: {
},
mounted() {
console.log(this.url)
} }
} }
</script> </script>

View File

@@ -6,7 +6,7 @@
import { GenericListPage } from '@/layout/components' import { GenericListPage } from '@/layout/components'
import { getDaysAgo, toSafeLocalDateStr } from '@/utils/common' import { getDaysAgo, toSafeLocalDateStr } from '@/utils/common'
import { OutputExpandFormatter } from './formatters' import { OutputExpandFormatter } from './formatters'
import { DetailFormatter } from '@/components/ListTable/formatters' import { DetailFormatter, BooleanFormatter } from '@/components/ListTable/formatters'
export default { export default {
components: { components: {
@@ -38,7 +38,19 @@ export default {
label: this.$t('sessions.command') label: this.$t('sessions.command')
}, },
risk_level: { risk_level: {
label: this.$t('sessions.riskLevel') label: this.$t('sessions.riskLevel'),
formatter: BooleanFormatter,
formatterArgs: {
hasTips: true,
tips(val) {
switch (val) {
case 0:
return vm.$t('sessions.riskLevels.common')
default:
return vm.$t('sessions.riskLevels.common')
}
}
}
}, },
user: { user: {
label: this.$t('sessions.user') label: this.$t('sessions.user')
@@ -75,6 +87,7 @@ export default {
headerActions: { headerActions: {
hasLeftActions: false, hasLeftActions: false,
hasExport: false, hasExport: false,
hasImport: false,
hasDatePicker: true, hasDatePicker: true,
datePicker: { datePicker: {
dateStart: dateFrom, dateStart: dateFrom,

View File

@@ -1,5 +1,5 @@
<template> <template>
<TabPage :submenu="submenu" :active-menu="activeMenu"> <Page>
<IBox v-if="!loading"> <IBox v-if="!loading">
<GenericCreateUpdateForm <GenericCreateUpdateForm
:fields="fields" :fields="fields"
@@ -11,11 +11,11 @@
:more-buttons="moreButtons" :more-buttons="moreButtons"
/> />
</IBox> </IBox>
</TabPage> </Page>
</template> </template>
<script> <script>
import { TabPage } from '@/layout/components' import { Page } from '@/layout/components'
import { IBox, UploadField } from '@/components' import { IBox, UploadField } from '@/components'
import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm' import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm'
import { getInterfaceInfo, postInterface, restoreInterface } from '@/views/xpack/api' import { getInterfaceInfo, postInterface, restoreInterface } from '@/views/xpack/api'
@@ -24,7 +24,7 @@ export default {
name: 'InterfaceSettings', name: 'InterfaceSettings',
components: { components: {
IBox, IBox,
TabPage, Page,
GenericCreateUpdateForm GenericCreateUpdateForm
}, },
data() { data() {
@@ -32,13 +32,6 @@ export default {
loading: true, loading: true,
files: {}, files: {},
interfaceInfo: {}, interfaceInfo: {},
activeMenu: 'interface',
submenu: [
{
title: this.$t('xpack.InterfaceSettings'),
name: 'interface'
}
],
successUrl: { name: 'Settings' }, successUrl: { name: 'Settings' },
fields: [ fields: [
['', ['login_title']], ['', ['login_title']],

View File

@@ -15,7 +15,10 @@ export default {
initial: { initial: {
}, },
url: '/api/v1/orgs/orgs/', url: '/api/v1/orgs/orgs/',
fields: ['name', 'admins', 'auditors', 'users', 'comment'], fields: [
[this.$t('common.Basic'), ['name', 'comment']],
[this.$t('common.Members'), ['admins', 'auditors', 'users']]
],
fieldsMeta: { fieldsMeta: {
admins: { admins: {
label: this.$t('xpack.Admin'), label: this.$t('xpack.Admin'),
@@ -53,6 +56,11 @@ export default {
} }
} }
} }
},
onPerformSuccess(res, method) {
const org = { id: res.id, name: res.name }
this.$store.dispatch('users/addAdminOrg', org)
return this.$router.push({ name: 'OrganizationList' })
} }
} }
} }

View File

@@ -165,24 +165,24 @@ export default {
path: '', path: '',
component: () => import('@/views/xpack/Org/OrganizationList'), component: () => import('@/views/xpack/Org/OrganizationList'),
name: 'OrganizationList', name: 'OrganizationList',
meta: { title: i18n.t('xpack.Organization.OrganizationList') } meta: { title: i18n.t('xpack.Organization.OrganizationList'), activeMenu: '/xpack/orgs' }
}, },
{ {
path: 'orgs/create', path: 'create',
component: () => import('@/views/xpack/Org/OrganizationCreateUpdate'), component: () => import('@/views/xpack/Org/OrganizationCreateUpdate'),
name: 'OrganizationCreate', name: 'OrganizationCreate',
hidden: true, hidden: true,
meta: { title: i18n.t('xpack.Organization.OrganizationCreate'), activeMenu: '/xpack/orgs', action: 'create' } meta: { title: i18n.t('xpack.Organization.OrganizationCreate'), activeMenu: '/xpack/orgs', action: 'create' }
}, },
{ {
path: 'orgs/:id/update', path: ':id/update',
component: () => import('@/views/xpack/Org/OrganizationCreateUpdate'), component: () => import('@/views/xpack/Org/OrganizationCreateUpdate'),
name: 'OrganizationUpdate', name: 'OrganizationUpdate',
hidden: true, hidden: true,
meta: { title: i18n.t('xpack.Organization.OrganizationUpdate'), activeMenu: '/xpack/orgs', action: 'update' } meta: { title: i18n.t('xpack.Organization.OrganizationUpdate'), activeMenu: '/xpack/orgs', action: 'update' }
}, },
{ {
path: 'orgs/:id', path: ':id',
component: () => import('@/views/xpack/Org/OrganizationDetail/index'), component: () => import('@/views/xpack/Org/OrganizationDetail/index'),
name: 'OrganizationDetail', name: 'OrganizationDetail',
hidden: true, hidden: true,
@@ -193,16 +193,17 @@ export default {
{ {
path: 'vault', path: 'vault',
component: empty, component: empty,
meta: { title: i18n.t('xpack.Vault.Vault'), activeMenu: '/xpack/vault/vault' }, redirect: '',
meta: { },
children: [ children: [
{ {
path: 'vault', path: '',
component: () => import('@/views/xpack/Vault/VaultList.vue'), component: () => import('@/views/xpack/Vault/VaultList.vue'),
name: 'VaultList', name: 'VaultList',
meta: { title: i18n.t('xpack.Vault.Vault'), activeMenu: '/xpack/vault/vault' } meta: { title: i18n.t('xpack.Vault.Vault'), activeMenu: '/xpack/vault/vault' }
}, },
{ {
path: 'vault/create', path: 'create',
component: () => import('@/views/xpack/Vault/VaultCreate'), component: () => import('@/views/xpack/Vault/VaultCreate'),
name: 'VaultCreate', name: 'VaultCreate',
meta: { title: i18n.t('xpack.Vault.Create'), activeMenu: '/xpack/vault/vault' }, meta: { title: i18n.t('xpack.Vault.Create'), activeMenu: '/xpack/vault/vault' },