1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

refactor(instances): a migration merges owners with move_ownership

record_migration() repeated computes.utils._move_ownership() line by line: owners move to the record the destination already has, a user's rights are merged and the template mark is kept. It now calls that function, renamed move_ownership as it is used from both apps; the owners left on the source record go with it, by cascade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 12:20:17 +03:00
parent 9ec3c09358
commit cc104716e0
3 changed files with 13 additions and 25 deletions

View file

@ -64,7 +64,7 @@ def _log(inst, what):
write("-", inst.compute.name, inst.name, f"VM {inst.name} ({inst.uuid}): {what}", True, uuid=inst.uuid)
def _move_ownership(source, target):
def move_ownership(source, target):
"""Give target the owners and template flag of source; a user's rights are merged."""
for ui in UserInstance.objects.filter(instance=source):
existing = UserInstance.objects.filter(instance=target, user=ui.user).first()
@ -88,7 +88,7 @@ def forget(inst):
comes back."""
elsewhere = Instance.objects.filter(uuid=inst.uuid).exclude(compute_id=inst.compute_id).first()
if elsewhere:
_move_ownership(inst, elsewhere)
move_ownership(inst, elsewhere)
_log(inst, f"owners moved to {elsewhere.compute.name}")
else:
_bury(inst)