Skip to content

Commit

Permalink
fix(xapi/vm): throw forbiddenOperation on blockedOperation (#6290)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRA authored Jun 16, 2022
1 parent 8e0be4e commit 89313de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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] 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

Expand All @@ -31,6 +32,7 @@

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

<!--packages-end-->

0 comments on commit 89313de

Please sign in to comment.