mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
feat(instances): a protected VM is not deleted nor restored over
A superuser turns a VM's protection on or off on its Settings tab, not while a job holds the VM (a deletion or a restore over it that runs would not stop). While it is on, its deletion (page, API, a queued job at its start) and a restore of a backup over it are refused; the Destroy tab, the destroy page and the restore page say so. A VM moved outside the panel keeps it. The API shows the flag read-only.
This commit is contained in:
parent
57e90e0d27
commit
adb4231db7
21 changed files with 706 additions and 491 deletions
|
|
@ -87,7 +87,8 @@ def _log(inst, what):
|
|||
|
||||
|
||||
def move_ownership(source, target):
|
||||
"""Give target the owners, tags, template flag, backups and schedules of source; a user's rights are merged."""
|
||||
"""Give target the owners, tags, template and protected flags, backups and schedules of source; a user's rights
|
||||
are merged."""
|
||||
target.tags.add(*source.tags.all())
|
||||
Backup.objects.filter(instance=source).update(instance=target)
|
||||
for policy in source.backup_policies.all():
|
||||
|
|
@ -106,9 +107,11 @@ def move_ownership(source, target):
|
|||
if getattr(ui, flag):
|
||||
setattr(existing, flag, True)
|
||||
existing.save()
|
||||
if source.is_template and not target.is_template:
|
||||
target.is_template = True
|
||||
target.save(update_fields=["is_template"])
|
||||
flags = [flag for flag in ("is_template", "protected") if getattr(source, flag) and not getattr(target, flag)]
|
||||
for flag in flags:
|
||||
setattr(target, flag, True)
|
||||
if flags:
|
||||
target.save(update_fields=flags)
|
||||
|
||||
|
||||
def forget(inst):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue