From 04e8023b2b46688e565abcbee0654eced75ea073 Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Tue, 14 Jun 2022 16:22:11 +0200 Subject: [PATCH 1/7] fix(xapi/vm): throw forbiddenOperation on blockedOperation --- @xen-orchestra/xapi/vm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/@xen-orchestra/xapi/vm.js b/@xen-orchestra/xapi/vm.js index 0e8d0dea4ef..9a623fce57d 100644 --- a/@xen-orchestra/xapi/vm.js +++ b/@xen-orchestra/xapi/vm.js @@ -11,7 +11,7 @@ const { asyncMap } = require('@xen-orchestra/async-map') const { createLogger } = require('@xen-orchestra/log') const { decorateClass } = require('@vates/decorate-with') const { defer } = require('golike-defer') -const { incorrectState } = require('xo-common/api-errors.js') +const { incorrectState, forbiddenOperation } = require('xo-common/api-errors.js') const { Ref } = require('xen-api') const extractOpaqueRef = require('./_extractOpaqueRef.js') @@ -343,7 +343,7 @@ class Vm { const vm = await this.getRecord('VM', vmRef) if (!bypassBlockedOperation && 'destroy' in vm.blocked_operations) { - throw new Error('destroy is blocked') + throw forbiddenOperation('destroy is blocked') } if (!forceDeleteDefaultTemplate && isDefaultTemplate(vm)) { From b3a934a30f4caf33c77175aaf0358054f549dd4e Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Tue, 14 Jun 2022 16:27:38 +0200 Subject: [PATCH 2/7] CHANGELOG --- CHANGELOG.unreleased.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 541f4300bdb..97d824987c7 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -12,6 +12,7 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” - [VDI Import] Fix `this._getOrWaitObject is not a function` +- [VM delete] In case the "Protect from accidental deletion" is set to `true` on a VM, a force modal is displayed when trying to delete it. [#6283](https://github.com/vatesfr/xen-orchestra/issues/6283) (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) ### Packages to release @@ -30,6 +31,7 @@ - @vates/read-chunk major +- @xen-orchestra patch - xo-server patch From 9aeee7408f5b62845ce3867b52dfd9898f3f4d49 Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Tue, 14 Jun 2022 16:29:07 +0200 Subject: [PATCH 3/7] remove invalid issue reference --- CHANGELOG.unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 97d824987c7..407e8c8c0b2 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -12,7 +12,7 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” - [VDI Import] Fix `this._getOrWaitObject is not a function` -- [VM delete] In case the "Protect from accidental deletion" is set to `true` on a VM, a force modal is displayed when trying to delete it. [#6283](https://github.com/vatesfr/xen-orchestra/issues/6283) (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) +- [VM delete] In case the "Protect from accidental deletion" is set to `true` on a VM, a force modal is displayed when trying to delete it. (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) ### Packages to release From 8b4299c97601dd5ac6cd166b163a90f5c186a91c Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Wed, 15 Jun 2022 16:56:20 +0200 Subject: [PATCH 4/7] use the blocked_operation reason --- @xen-orchestra/xapi/vm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@xen-orchestra/xapi/vm.js b/@xen-orchestra/xapi/vm.js index 9a623fce57d..1597e200298 100644 --- a/@xen-orchestra/xapi/vm.js +++ b/@xen-orchestra/xapi/vm.js @@ -343,7 +343,7 @@ class Vm { const vm = await this.getRecord('VM', vmRef) if (!bypassBlockedOperation && 'destroy' in vm.blocked_operations) { - throw forbiddenOperation('destroy is blocked') + throw forbiddenOperation(`destroy: ${vm.blocked_operations.destroy}`) } if (!forceDeleteDefaultTemplate && isDefaultTemplate(vm)) { From 022fdc704ee4edd065a04ae25cce2c12baa902a4 Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Thu, 16 Jun 2022 10:00:05 +0200 Subject: [PATCH 5/7] explicit reason when 'true' --- @xen-orchestra/xapi/vm.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/@xen-orchestra/xapi/vm.js b/@xen-orchestra/xapi/vm.js index 1597e200298..349017053eb 100644 --- a/@xen-orchestra/xapi/vm.js +++ b/@xen-orchestra/xapi/vm.js @@ -343,7 +343,13 @@ class Vm { const vm = await this.getRecord('VM', vmRef) if (!bypassBlockedOperation && 'destroy' in vm.blocked_operations) { - throw forbiddenOperation(`destroy: ${vm.blocked_operations.destroy}`) + throw forbiddenOperation( + `destroy is blocked: ${ + vm.blocked_operations.destroy === 'true' + ? 'protected from accidental deletion' + : vm.blocked_operations.destroy + }` + ) } if (!forceDeleteDefaultTemplate && isDefaultTemplate(vm)) { From ea77cea6abbd0b5ffb43173a7923391fd720e80b Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Thu, 16 Jun 2022 10:23:39 +0200 Subject: [PATCH 6/7] Update CHANGELOG.unreleased.md Co-authored-by: Julien Fontanet --- CHANGELOG.unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 407e8c8c0b2..2aab7068307 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -31,7 +31,7 @@ - @vates/read-chunk major -- @xen-orchestra patch +- @xen-orchestra/xapi minor - xo-server patch From 2cfa3eaa5d1c877cfc614153b0400ad9a709c349 Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:32:45 +0200 Subject: [PATCH 7/7] Update CHANGELOG.unreleased.md Co-authored-by: Julien Fontanet --- CHANGELOG.unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 2aab7068307..fe8ce276419 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -12,7 +12,7 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” - [VDI Import] Fix `this._getOrWaitObject is not a function` -- [VM delete] In case the "Protect from accidental deletion" is set to `true` on a VM, a force modal is displayed when trying to delete it. (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) +- [VM] Attempting to delete a protected VM should display a modal with the error and the ability to bypass it (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290)) ### Packages to release