Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xapi/VM_destroy): throw forbiddenOperation if operation blocked #6290

Merged
merged 7 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions @xen-orchestra/xapi/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -343,7 +343,13 @@ 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: ${
vm.blocked_operations.destroy === 'true'
? 'protected from accidental deletion'
: vm.blocked_operations.destroy
}`
)
}

if (!forceDeleteDefaultTemplate && isDefaultTemplate(vm)) {
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. (PR [#6290](https://github.com/vatesfr/xen-orchestra/pull/6290))
MathieuRA marked this conversation as resolved.
Show resolved Hide resolved

### Packages to release

Expand All @@ -30,6 +31,7 @@
<!--packages-start-->

- @vates/read-chunk major
- @xen-orchestra/xapi minor
- xo-server patch

<!--packages-end-->