From 0583a978be9ae1387f30ff56c989df318050421e Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:19:07 +0200 Subject: [PATCH] feat(xo-web/VM): display creator email and template name (#6771) See xoa-support #13064 & #13094 --- CHANGELOG.unreleased.md | 1 + packages/xo-web/src/common/intl/messages.js | 3 +- packages/xo-web/src/xo-app/vm/tab-advanced.js | 4 -- packages/xo-web/src/xo-app/vm/tab-general.js | 62 +++++++++++++++---- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index cf1b4782ac6..4d45de92349 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -9,6 +9,7 @@ - [VM/Advanced] Automatically eject removable medias when converting a VM to a template [#6752](https://github.com/vatesfr/xen-orchestra/issues/6752) (PR [#6769](https://github.com/vatesfr/xen-orchestra/pull/6769)) - [Dashboard/Health] Add free space column for storage state table (PR [#6778](https://github.com/vatesfr/xen-orchestra/pull/6778)) +- [VM/General] Displays the template name used to create the VM, as well as the email address of the VM creator for admin users (PR [#6771](https://github.com/vatesfr/xen-orchestra/pull/6771)) ### Bug fixes diff --git a/packages/xo-web/src/common/intl/messages.js b/packages/xo-web/src/common/intl/messages.js index 6f6ada07701..2d089fc2fab 100644 --- a/packages/xo-web/src/common/intl/messages.js +++ b/packages/xo-web/src/common/intl/messages.js @@ -1120,11 +1120,12 @@ const messages = { noIpv4Record: 'No IPv4 record', noIpRecord: 'No IP record', started: 'Started {ago}', - created: 'Created on {date}', paraVirtualizedMode: 'Paravirtualization (PV)', hardwareVirtualizedMode: 'Hardware virtualization (HVM)', hvmModeWithPvDriversEnabled: 'Hardware virtualization with paravirtualization drivers enabled (PVHVM)', pvInPvhMode: 'PV inside a PVH container (PV in PVH)', + vmCreatedAdmin: 'Created by {user}\non {date}\nwith template {template}', + vmCreatedNonAdmin: 'Created on {date}\nwith template {template}', windowsUpdateTools: 'Manage Citrix PV drivers via Windows Update', windowsToolsModalTitle: 'Windows Update Tools', windowsToolsModalMessage: diff --git a/packages/xo-web/src/xo-app/vm/tab-advanced.js b/packages/xo-web/src/xo-app/vm/tab-advanced.js index 341fbc42dc9..c4969faea90 100644 --- a/packages/xo-web/src/xo-app/vm/tab-advanced.js +++ b/packages/xo-web/src/xo-app/vm/tab-advanced.js @@ -914,10 +914,6 @@ export default class TabAdvanced extends Component {
{_('originalTemplate')} | -{vm.other.base_template_name ? vm.other.base_template_name : _('unknownOriginalTemplate')} | -
---|---|
{_('resourceSet')} |
diff --git a/packages/xo-web/src/xo-app/vm/tab-general.js b/packages/xo-web/src/xo-app/vm/tab-general.js
index f3fb356016c..86c64d0226b 100644
--- a/packages/xo-web/src/xo-app/vm/tab-general.js
+++ b/packages/xo-web/src/xo-app/vm/tab-general.js
@@ -7,9 +7,9 @@ import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'
import React from 'react'
import HomeTags from 'home-tags'
-import renderXoItem from 'render-xo-item'
+import renderXoItem, { VmTemplate } from 'render-xo-item'
import Tooltip from 'tooltip'
-import { addTag, editVm, removeTag } from 'xo'
+import { addTag, editVm, removeTag, subscribeUsers } from 'xo'
import { BlockLink } from 'link'
import { FormattedRelative, FormattedDate } from 'react-intl'
import { Container, Row, Col } from 'grid'
@@ -20,10 +20,16 @@ import {
createGetVmLastShutdownTime,
createSelector,
getResolvedPendingTasks,
+ isAdmin,
} from 'selectors'
-import { connectStore, formatSizeShort, getVirtualizationModeLabel, osFamily } from 'utils'
+import { addSubscriptions, connectStore, formatSizeShort, getVirtualizationModeLabel, osFamily } from 'utils'
import { CpuSparkLines, MemorySparkLines, NetworkSparkLines, XvdSparkLines } from 'xo-sparklines'
import { injectState, provideState } from 'reaclette'
+import { find } from 'lodash'
+
+const CREATED_VM_STYLES = {
+ whiteSpace: 'pre-line',
+}
const GuestToolsDetection = ({ vm }) => {
if (vm.power_state !== 'Running' || vm.pvDriversDetected === undefined) {
@@ -93,13 +99,25 @@ const GeneralTab = decorate([
)
return (state, props) => ({
+ isAdmin: isAdmin(state, props),
lastShutdownTime: createGetVmLastShutdownTime()(state, props),
// true: useResourceSet to bypass permissions
resolvedPendingTasks: getResolvedPendingTasks(state, props, true),
vgpu: getAttachedVgpu(state, props),
vgpuTypes: getVgpuTypes(state, props),
+ vmTemplate: createGetObjectsOfType('VM-template').find(
+ (_, { pool, vm }) =>
+ template =>
+ template.$poolId === pool.id && template.uuid === vm.creation?.template
+ )(state, props),
})
}),
+ addSubscriptions(
+ ({ isAdmin, vm }) =>
+ isAdmin && {
+ vmCreator: cb => subscribeUsers(users => cb(find(users, user => user.id === vm.creation?.user))),
+ }
+ ),
provideState({
computed: {
vmResolvedPendingTasks: (_, { resolvedPendingTasks, vm }) => {
@@ -109,7 +127,18 @@ const GeneralTab = decorate([
},
}),
injectState,
- ({ state: { vmResolvedPendingTasks }, lastShutdownTime, statsOverview, vgpu, vgpuTypes, vm, vmTotalDiskSpace }) => {
+ ({
+ isAdmin,
+ state: { vmResolvedPendingTasks },
+ lastShutdownTime,
+ statsOverview,
+ vgpu,
+ vgpuTypes,
+ vm,
+ vmCreator,
+ vmTemplate,
+ vmTotalDiskSpace,
+ }) => {
const {
CPUs: cpus,
id,
@@ -122,6 +151,7 @@ const GeneralTab = decorate([
tags,
VIFs: vifs,
} = vm
+
return (
- {_('created', {
- date:
- )}
+
+ {_(isAdmin ? 'vmCreatedAdmin' : 'vmCreatedNonAdmin', {
+ user: vmCreator?.email ?? _('unknown'),
+ date:
+ installTime !== null ? (
+
|