Skip to content

Commit

Permalink
Fix move_to_entity on data object
Browse files Browse the repository at this point in the history
When entity is in collection also assign collection to the data object.
  • Loading branch information
gregorjerse committed Nov 8, 2023
1 parent 790e451 commit e5a4dd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Fixed
- Create history object for ``Collection`` if none exists
- Use the same postfix for all kubernetes volumes for the given data object
- Fix ``handle_progress`` handler in the listener
- Fix moving data to entity in collection also sets collection on the data
object



===================
Expand Down
7 changes: 5 additions & 2 deletions resolwe/flow/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,11 @@ def move_to_entity(self, entity):
raise ValidationError("Data object must not be removed from container.")
self.entity = entity
if entity:
self.permission_group = entity.permission_group
self.tags = entity.tags
if entity.collection:
self.move_to_collection(entity.collection)
else:
self.permission_group = entity.permission_group
self.tags = entity.tags
self.save(update_fields=["permission_group", "entity", "tags"])

def validate_change_collection(self, collection):
Expand Down
14 changes: 14 additions & 0 deletions resolwe/flow/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ def test_delete_chunked(self):
Data.objects.all().delete_chunked(chunk_size=10)
self.assertFalse(Data.objects.exists())

def test_move_to_entity(self):
# Create data outside container and move it to the entity in the collection.
process = Process.objects.create(contributor=self.contributor)
data = Data.objects.create(contributor=self.contributor, process=process)
self.assertIsNone(data.entity)
self.assertIsNone(data.collection)
collection = Collection.objects.create(contributor=self.contributor)
entity = Entity.objects.create(
contributor=self.contributor, collection=collection
)
data.move_to_entity(entity)
self.assertEqual(data.entity, entity)
self.assertEqual(data.collection, collection)

def test_trim_name(self):
process = Process.objects.create(
contributor=self.contributor, data_name="test" * 50
Expand Down

0 comments on commit e5a4dd9

Please sign in to comment.