perf: ticket

This commit is contained in:
feng626
2022-09-22 14:02:46 +08:00
parent d7dedf15f1
commit 8514444508
12 changed files with 14 additions and 651 deletions

View File

@@ -91,26 +91,6 @@ export default {
},
hidden: true
},
{
path: 'request-application-perm/create',
name: 'RequestApplicationPermTicketCreateUpdate',
component: () => import('@/views/tickets/RequestApplicationPerm/CreateUpdate'),
meta: {
title: i18n.t('route.TicketCreate'),
permissions: ['tickets.view_ticket']
},
hidden: true
},
{
path: 'request-application-perm/:id',
name: 'AppsTicketDetail',
component: () => import('@/views/tickets/RequestApplicationPerm/Detail'),
meta: {
title: i18n.t('route.TicketDetail'),
permissions: ['tickets.view_ticket']
},
hidden: true
},
{
path: 'command-confirm/:id',
name: 'CommandConfirmDetail',

View File

@@ -46,8 +46,6 @@ export default {
getRoute: function({ row }) {
if (row.type === 'apply_asset') {
return 'AssetsTicketDetail'
} else if (row.type === 'apply_application') {
return 'AppsTicketDetail'
} else if (row.type === 'login_asset_confirm') {
return 'LoginAssetTicketDetail'
} else if (row.type === 'login_confirm') {
@@ -175,13 +173,6 @@ export default {
callback: () => this.$router.push({
name: 'RequestAssetPermTicketCreateUpdate'
})
},
{
name: 'RequestApplicationPerm',
title: this.$t('tickets.RequestApplicationPerm'),
callback: () => this.$router.push({
name: 'RequestApplicationPermTicketCreateUpdate'
})
}
]
}

View File

@@ -65,8 +65,8 @@ export default {
value: object.apply_run_asset
},
{
key: this.$t('tickets.ApplyRunSystemUser'),
value: object.rel_snapshot.apply_run_system_user
key: this.$t('tickets.ApplyRunAccount'),
value: object.rel_snapshot.apply_run_account
},
{
key: this.$t('tickets.ApplyRunCommand'),

View File

@@ -61,8 +61,8 @@ export default {
value: object.rel_snapshot.apply_login_asset
},
{
key: this.$t('acl.apply_login_system_user'),
value: object.rel_snapshot.apply_login_system_user
key: this.$t('acl.apply_login_account'),
value: object.rel_snapshot.apply_login_account
},
{
key: this.$t('acl.apply_login_user'),

View File

@@ -1,212 +0,0 @@
<template>
<GenericCreateUpdatePage
v-if="!loading"
v-bind="$data"
:perform-submit="performSubmit"
:create-success-next-route="createSuccessNextRoute"
/>
</template>
<script>
import { GenericCreateUpdatePage } from '@/layout/components'
import Select2 from '@/components/FormFields/Select2'
import { getDaysFuture } from '@/utils/common'
import { Required } from '@/components/DataForm/rules'
import { ApplicationCascader } from '@/views/applications/const'
import { mapState, mapGetters } from 'vuex'
export default {
components: {
GenericCreateUpdatePage
},
data() {
const vm = this
const now = new Date()
const date_expired = getDaysFuture(7, now).toISOString()
const date_start = now.toISOString()
let apply_category_type = []
return {
hasDetailInMsg: false,
loading: true,
initial: {
ips_or_not: true,
apply_date_expired: date_expired,
apply_date_start: date_start,
org_id: '',
type: 'apply_application'
},
fields: [
[this.$t('common.Basic'), ['title', 'type', 'org_id', 'comment']],
[this.$t('tickets.RequestPerm'), [
'apply_category_type', 'apply_applications', 'apply_system_users',
'apply_date_start', 'apply_date_expired'
]]
],
fieldsMeta: {
type: {
hidden: () => true,
el: {
disabled: true
}
},
meta: {
fields: [
'apply_category_type', 'apply_applications', 'apply_system_users',
'apply_date_start', 'apply_date_expired'],
fieldsMeta: {
apply_date_start: {
label: this.$t('common.DateStart'),
type: 'date-picker',
el: {
type: 'datetime'
}
},
apply_applications: {
type: 'assetSelect',
component: Select2,
label: this.$t('applications.App'),
el: {
value: [],
ajax: {
url: '',
transformOption: (item) => {
return { label: item.name, value: item.id }
}
}
}
},
apply_system_users: {
type: 'systemUserSelect',
component: Select2,
label: this.$t('assets.SystemUser'),
el: {
value: [],
ajax: {
url: '',
transformOption: (item) => {
if (this.$route.query.type === 'k8s') {
return { label: item.name, value: item.id }
}
const username = item.username || '*'
return { label: item.name + '(' + username + ')', value: item.id }
}
}
}
},
apply_date_expired: {
label: this.$t('common.DateEnd'),
type: 'date-picker',
el: {
type: 'datetime'
}
},
apply_category_type: {
type: 'cascader',
label: this.$t('applications.appType'),
rules: [Required],
el: {
multiple: false,
options: ApplicationCascader
},
on: {
change: ([event], updateForm) => {
this.apply_category_type = event
updateForm({
apply_applications: [],
apply_system_users: []
})
const fieldsMeta = this.fieldsMeta.meta.fieldsMeta
const appUrl = `/api/v1/applications/applications/suggestion/?oid=${vm.org_id}&category=${event[0]}&type=${event[1]}`
fieldsMeta.apply_applications.el.ajax.url = appUrl
let protocol = event[1]
if (event[0] === 'remote_app') {
protocol = 'rdp'
}
const sysUserUrl = `/api/v1/assets/system-users/suggestion/?oid=${vm.org_id}&protocol=${protocol}`
fieldsMeta.apply_system_users.el.ajax.url = sysUserUrl
}
}
}
}
},
org_id: {
component: Select2,
el: {
multiple: false,
options: this.$store.state.users.workbenchOrgs.filter(item => {
return item.id !== '00000000-0000-0000-0000-000000000000'
})?.map((item) => {
return { label: item.name, value: item.id }
})
},
hidden: (form) => {
this.org_id = form['org_id']
apply_category_type = this.apply_category_type
const fieldsMeta = this.fieldsMeta
if (apply_category_type) {
fieldsMeta.apply_applications.el.ajax.url = `/api/v1/applications/applications/suggestions/?oid=${vm.org_id}&category=${apply_category_type[0]}&type=${apply_category_type[1]}`
fieldsMeta.apply_system_users.el.ajax.url = apply_category_type[0] === 'remote_app' ? `/api/v1/assets/system-users/suggestions/?oid=${vm.org_id}&protocol=rdp` : `/api/v1/assets/system-users/suggestions/?oid=${vm.org_id}&protocol=${apply_category_type[1]}`
}
}
}
},
url: '/api/v1/tickets/apply-app-tickets/?state=pending',
createSuccessNextRoute: {
name: 'MyTicketList'
},
cleanFormValue(value) {
const applications = value.apply_applications
const systemUsers = value.apply_system_users
if (applications && Array.isArray(applications) && applications.length < 1) {
delete value.apply_applications
}
if (systemUsers && Array.isArray(systemUsers) && systemUsers.length < 1) {
delete value.apply_system_users
}
return value
}
}
},
computed: {
...mapState({
workbenchOrgs: state => state.users.workbenchOrgs.filter(item => {
return item.id !== '00000000-0000-0000-0000-000000000000'
})
}),
...mapGetters(['currentOrg'])
},
mounted() {
const currentOrgId = this.currentOrg.id || ''
const userAllOrgIds = this.workbenchOrgs.map(i => i.id) || []
if (userAllOrgIds.includes(currentOrgId)) {
this.initial.org_id = currentOrgId
} else {
this.initial.org_id = userAllOrgIds[0]
}
this.loading = false
},
methods: {
performSubmit(validValues) {
const applyCategoryType = validValues.apply_category_type
const filter = (len, field) => {
return applyCategoryType && applyCategoryType.length > 0 ? applyCategoryType[len] : validValues[field]
}
validValues.apply_category = filter(0, 'apply_category')
validValues.apply_type = filter(1, 'apply_type')
delete validValues['apply_category_type']
return this.$axios['post'](`/api/v1/tickets/apply-app-tickets/open/`, validValues)
}
}
}
</script>
<style lang="less" scoped>
.el-form ::v-deep .el-cascader {
width: 100%;
}
</style>

View File

@@ -1,47 +0,0 @@
<template>
<el-select v-model="value" v-bind="$attrs" class="select2" v-on="$listeners">
<el-option-group
v-for="group in options"
:key="group.org_name"
:label="group.org_name"
>
<el-option
v-for="item in group.org_admins"
:key="item.id"
:label="item.name + '(' + item.username + ')'"
:value="item.id"
/>
</el-option-group>
</el-select>
</template>
<script>
export default {
name: 'GroupSelectFormatter',
props: {
url: {
type: String,
default: ''
}
},
data() {
return {
value: '',
options: []
}
},
created() {
this.$axios.get(this.url).then(
res => {
this.options = res
}
)
}
}
</script>
<style scoped>
.select2 {
width: 100%;
}
</style>

View File

@@ -1,268 +0,0 @@
<template>
<GenericTicketDetail
:object="object"
:detail-card-items="detailCardItems"
:special-card-items="specialCardItems"
:assigned-card-items="assignedCardItems"
:approve="handleApprove"
:close="handleClose"
:reject="handleReject"
>
<IBox v-if="hasActionPerm&&object.status !== 'closed'" class="box">
<div slot="header" class="clearfix ibox-title">
<i class="fa fa-edit" /> {{ $t('common.Actions') }}
</div>
<template>
<el-form ref="requestForm" :model="requestForm" label-width="140px" label-position="left" class="assets">
<el-form-item :label="$t('assets.Applications')" :rules="isRequired">
<Select2 v-model="requestForm.applications" v-bind="appsSelect2" style="width: 50% !important" />
</el-form-item>
<el-form-item :label="$t('tickets.SystemUser')" :rules="isRequired">
<Select2 v-model="requestForm.systemusers" v-bind="systemuserSelect2" style="width: 50% !important" />
</el-form-item>
<el-form-item :label="$t('common.dateStart')" required>
<el-date-picker
v-model="requestForm.apply_date_start"
type="datetime"
/>
</el-form-item>
<el-form-item :label="$t('common.dateExpired')" required>
<el-date-picker
v-model="requestForm.apply_date_expired"
type="datetime"
/>
</el-form-item>
</el-form>
</template>
</IBox>
</GenericTicketDetail>
</template>
<script>
import IBox from '@/components/IBox'
import { formatTime, getDateTimeStamp } from '@/utils/index'
import { toSafeLocalDateStr } from '@/utils/common'
import Select2 from '@/components/FormFields/Select2'
import GenericTicketDetail from '@/views/tickets/components/GenericTicketDetail'
import { STATUS_MAP } from '../../const'
export default {
name: '',
components: { GenericTicketDetail, IBox, Select2 },
props: {
object: {
type: Object,
default: () => ({})
}
},
data() {
return {
statusMap: this.object.status === 'open' ? STATUS_MAP['pending'] : STATUS_MAP[this.object.state],
requestForm: {
applications: this.object.apply_applications,
systemusers: this.object.apply_system_users,
apply_date_expired: this.object.apply_date_expired,
apply_date_start: this.object.apply_date_start
},
appsSelect2: {
multiple: true,
value: this.object.apply_applications,
ajax: {
url: function() {
const oid = this.object.org_id === '' ? 'DEFAULT' : this.object.org_id
return `/api/v1/applications/applications/?oid=${oid}&type=${this.object.apply_type}`
}.bind(this)(),
transformOption: (item) => {
return { label: item.name, value: item.id }
}
}
},
systemuserSelect2: {
multiple: true,
value: this.object.apply_system_users,
ajax: {
url: function() {
const oid = this.object.org_id === '' ? 'DEFAULT' : this.object.org_id
const protocol = this.object.apply_category === 'remote_app' ? 'rdp' : this.object.apply_type
return `/api/v1/assets/system-users/?oid=${oid}&protocol=${protocol}`
}.bind(this)(),
transformOption: (item) => {
const username = item.username || '*'
return { label: item.name + '(' + username + ')', value: item.id }
}
}
}
}
},
computed: {
isRequired() {
if (this.object.approval_step === this.object.process_map.length) {
return [{ required: true }]
}
return [{ required: false }]
},
detailCardItems() {
const { object } = this
return [
{
key: this.$t('common.Number'),
value: object.serial_num
},
{
key: this.$t('tickets.status'),
value: object.status,
formatter: (item, val) => {
return <el-tag type={this.statusMap.type} size='mini'> { this.statusMap.title }</el-tag>
}
},
{
key: this.$t('tickets.type'),
value: object.type_display
},
{
key: this.$t('tickets.user'),
value: object.rel_snapshot.applicant
},
{
key: this.$t('tickets.OrgName'),
value: object.org_name
},
{
key: this.$t('common.dateCreated'),
value: toSafeLocalDateStr(object.date_created)
},
{
key: this.$t('common.Comment'),
value: object.comment
}
]
},
specialCardItems() {
const { object } = this
const rel_snapshot = object.rel_snapshot
return [
{
key: this.$t('applications.appType'),
value: `${object.apply_category} / ${object.apply_type} `
},
{
key: this.$t('applications.appName'),
value: rel_snapshot.apply_applications.join(', ')
},
{
key: this.$t('tickets.SystemUser'),
value: rel_snapshot.apply_system_users.join(', ')
},
{
key: this.$t('common.dateStart'),
value: toSafeLocalDateStr(object.apply_date_start)
},
{
key: this.$t('common.dateExpired'),
value: toSafeLocalDateStr(object.apply_date_expired)
}
]
},
assignedCardItems() {
const vm = this
const { object } = this
const rel_snapshot = object.rel_snapshot
return [
{
key: this.$t('tickets.PermissionName'),
value: vm.object.apply_permission_name,
formatter: function(item, value) {
const to = { name: 'ApplicationPermissionDetail', params: { id: object.id }, query: { oid: object.org_id }}
if (vm.$hasPerm('perms.view_applicationpermission') && object.status === 'closed' && object.state === 'approved') {
return <router-link to={to}>{ value }</router-link>
} else {
return <span>{ value }</span>
}
}
},
{
key: this.$t('applications.appName'),
value: rel_snapshot.apply_applications.join(', ')
},
{
key: this.$t('tickets.SystemUser'),
value: rel_snapshot.apply_system_users.join(', ')
},
{
key: this.$t('common.dateStart'),
value: toSafeLocalDateStr(object.apply_date_start)
},
{
key: this.$t('common.dateExpired'),
value: toSafeLocalDateStr(object.apply_date_expired)
}
]
},
hasActionPerm() {
const approval_step = this.object.approval_step
const current_user_id = this.$store.state.users.profile.id
return this.object.process_map[approval_step - 1].assignees.indexOf(current_user_id) !== -1
}
},
methods: {
formatTime(dateStr) {
return formatTime(getDateTimeStamp(dateStr))
},
toSafeLocalDateStr(dataStr) {
return toSafeLocalDateStr(dataStr)
},
reloadPage() {
window.location.reload()
},
handleApprove() {
if (this.object.approval_step === this.object.process_map.length) {
if (this.requestForm.applications.length === 0 || this.requestForm.systemusers.length === 0) {
return this.$message.error(this.$tc('common.NeedAddAppsOrSystemUserErrMsg'))
}
}
this.$axios.patch(`/api/v1/tickets/apply-app-tickets/${this.object.id}/approve/`, {
apply_category: this.object.apply_category,
apply_type: this.object.apply_type,
apply_system_users: this.requestForm.systemusers ? this.requestForm.systemusers : [],
apply_applications: this.requestForm.applications ? this.requestForm.applications : [],
apply_date_start: this.requestForm.apply_date_start,
apply_date_expired: this.requestForm.apply_date_expired,
org_id: this.object.org_id
}).then(
() => {
this.$message.success(this.$tc('common.updateSuccessMsg'))
this.reloadPage()
}
).catch(
() => this.$message.success(this.$tc('common.updateErrorMsg'))
)
},
handleClose() {
const url = `/api/v1/tickets/apply-app-tickets/${this.object.id}/close/`
this.$axios.put(url).then(res => this.reloadPage()).catch(err => this.$message.error(err))
},
handleReject() {
const url = `/api/v1/tickets/apply-app-tickets/${this.object.id}/reject/`
this.$axios.put(url).then(res => this.reloadPage()).catch(err => this.$message.error(err))
}
}
}
</script>
<style scoped>
.assets{
margin-top: 14px;
}
.feed-activity-list .feed-element {
border-bottom: 1px solid #e7eaec;
}
.feed-element > .pull-left {
margin-right: 10px;
}
.feed-element .header-avatar {
width: 38px;
height: 38px;
}
.box {
margin-bottom: 15px;
}
</style>

View File

@@ -1,50 +0,0 @@
<template>
<GenericDetailPage :object.sync="ticket" :active-menu.sync="config.activeMenu" v-bind="config" v-on="$listeners">
<component :is="config.activeMenu" :object="ticket" />
</GenericDetailPage>
</template>
<script>
import { GenericDetailPage, TabPage } from '@/layout/components'
import TicketDetail from './TicketDetail'
export default {
components: {
GenericDetailPage,
TicketDetail,
TabPage
},
data() {
return {
ticket: { title: '', user_display: '', type_display: '', status: '', assignees_display: '', date_created: '' },
config: {
activeMenu: 'TicketDetail',
url: '',
submenu: [
{
title: this.$t('route.TicketDetail'),
name: 'TicketDetail'
}
],
actions: {
detailApiUrl: `/api/v1/tickets/apply-app-tickets/${this.$route.params.id}/`
},
getObjectName: this.getObjectName,
hasRightSide: false
}
}
},
mounted() {
},
methods: {
getObjectName() {
return this.ticket.title
}
}
}
</script>
<style scoped>
</style>

View File

@@ -37,7 +37,7 @@ export default {
fields: [
[this.$t('common.Basic'), ['title', 'type', 'org_id', 'comment']],
[this.$t('tickets.RequestPerm'), [
'apply_nodes', 'apply_assets', 'apply_system_users',
'apply_nodes', 'apply_assets', 'apply_accounts',
'apply_actions', 'apply_date_start', 'apply_date_expired'
]]
],
@@ -81,21 +81,6 @@ export default {
}
}
},
apply_system_users: {
type: 'systemUserSelect',
component: Select2,
label: this.$t('assets.SystemUser'),
el: {
value: [],
ajax: {
url: '',
transformOption: (item) => {
const username = item.username || '*'
return { label: item.name + '(' + username + ')', value: item.id }
}
}
}
},
org_id: {
component: Select2,
el: {
@@ -108,7 +93,6 @@ export default {
},
hidden: (form) => {
const fieldsMeta = this.fieldsMeta
fieldsMeta.apply_system_users.el.ajax.url = `/api/v1/assets/system-users/suggestions/?oid=${form['org_id']}&protocol__in=rdp,ssh,vnc,telnet`
fieldsMeta.apply_assets.el.ajax.url = `/api/v1/assets/assets/suggestions/?oid=${form['org_id']}`
fieldsMeta.apply_nodes.el.ajax.url = `/api/v1/assets/nodes/suggestions/?oid=${form['org_id']}`
}
@@ -116,7 +100,7 @@ export default {
},
cleanFormValue(value) {
Object.keys(value).forEach((item, index, arr) => {
if (['apply_system_users', 'apply_assets', 'apply_nodes'].includes(item)) {
if (['apply_accounts', 'apply_assets', 'apply_nodes'].includes(item)) {
if (value[item].length < 1) {
delete value[item]
}

View File

@@ -21,7 +21,7 @@
<Select2 v-model="requestForm.assets" v-bind="assetSelect2" style="width: 50% !important" />
</el-form-item>
<el-form-item :label="$t('tickets.SystemUser')" :rules="isRequired">
<Select2 v-model="requestForm.systemusers" v-bind="systemuserSelect2" style="width: 50% !important" />
<Select2 v-model="requestForm.accounts" style="width: 50% !important" />
</el-form-item>
<el-form-item :label="$t('common.dateStart')" required>
<el-date-picker
@@ -67,7 +67,7 @@ export default {
requestForm: {
nodes: this.object.apply_nodes,
assets: this.object.apply_assets,
systemusers: this.object.apply_system_users,
accounts: this.object.apply_accounts,
actions: this.object.apply_actions,
apply_date_expired: this.object.apply_date_expired,
apply_date_start: this.object.apply_date_start
@@ -97,20 +97,6 @@ export default {
return { label: item.hostname, value: item.id }
}
}
},
systemuserSelect2: {
multiple: true,
value: this.object.apply_system_users,
ajax: {
url: (function(object) {
const oid = object.org_id === '' ? 'DEFAULT' : object.org_id
return `/api/v1/assets/system-users/?oid=${oid}&protocol__in=rdp,vnc,ssh,telnet`
}(this.object)),
transformOption: (item) => {
const username = item.username || '*'
return { label: item.name + '(' + username + ')', value: item.id }
}
}
}
}
},
@@ -170,8 +156,8 @@ export default {
value: rel_snapshot.apply_assets.join(', ')
},
{
key: this.$t('tickets.SystemUser'),
value: rel_snapshot.apply_system_users.join(', ')
key: this.$t('tickets.Account'),
value: rel_snapshot.apply_accounts.join(', ')
},
{
key: this.$t('assets.Action'),
@@ -213,8 +199,8 @@ export default {
value: rel_snapshot.apply_assets.join(', ')
},
{
key: this.$t('tickets.SystemUser'),
value: rel_snapshot.apply_system_users.join(', ')
key: this.$t('tickets.Account'),
value: rel_snapshot.apply_accounts.join(', ')
},
{
key: this.$t('assets.Action'),

View File

@@ -50,7 +50,6 @@ export default {
afterGetTicket(ticket) {
const ticketRouteMapper = {
'apply_asset': 'AssetsTicketDetail',
'apply_application': 'AppsTicketDetail',
'login_confirm': 'LoginTicketDetail',
'login_asset_confirm': 'LoginAssetTicketDetail',
'command_confirm': 'CommandConfirmDetail'

View File

@@ -15,8 +15,8 @@
<span class="item-value">{{ session.asset }}</span>
</el-col>
<el-col>
<span class="item-label">{{ $t('tickets.SystemUser') }}</span>
<span class="item-value">{{ session.system_user }}</span>
<span class="item-label">{{ $t('tickets.Account') }}</span>
<span class="item-value">{{ session.account }}</span>
</el-col>
<el-col>
<span class="item-label">{{ $t('sessions.UseProtocol') }}</span>