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

@ -68,3 +68,12 @@ class MigrationBookkeepingTests(TestCase):
found.refresh_from_db()
self.assertTrue(found.is_template)
self.assertEqual(UserInstance.objects.get(user=owner).instance_id, found.id)
def test_an_owner_of_both_records_keeps_the_rights_of_both(self):
owner = get_user_model().objects.create_user("mb-both")
UserInstance.objects.create(user=owner, instance=self.vm, is_change=True)
found = Instance.objects.create(compute=self.dest, name="vm", uuid="u-mb")
UserInstance.objects.create(user=owner, instance=found, is_vnc=True)
self.migrate()
ui = UserInstance.objects.get(user=owner)
self.assertEqual((ui.instance_id, ui.is_change, ui.is_delete, ui.is_vnc), (found.id, True, False, True))