diff --git a/openlobby/core/models.py b/openlobby/core/models.py index 36dca0383b93df41f626de9c39aa267f251c01f7..470de4c2f75960aba1845fb0006b208c7e3d9210 100644 --- a/openlobby/core/models.py +++ b/openlobby/core/models.py @@ -68,6 +68,6 @@ class Report(models.Model): def save(self, *args, **kwargs): super().save(*args, **kwargs) - if not self.author.is_author: + if not self.is_draft and not self.author.is_author: self.author.is_author = True self.author.save() diff --git a/tests/test_models.py b/tests/test_models.py index bccd5d0d178729bcd9a38f5324d4414f9d62b368..2cc7a8c4c64d063d0824ad4bbb8df4b73ed9081d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -18,6 +18,14 @@ def test_report__marks_user_as_author_on_save(): assert user.is_author +def test_report__marks_user_as_author_on_save__not_if_draft(): + author = User.objects.create(id=1, is_author=False) + date = arrow.get(2018, 1, 1).datetime + Report.objects.create(author=author, is_draft=True, date=date, body='Lorem ipsum.') + user = User.objects.get(id=1) + assert not user.is_author + + def test_report__is_saved_in_elasticsearch(): author = User.objects.create(id=6) date = arrow.get(2018, 1, 1).datetime @@ -50,7 +58,7 @@ def test_report__is_saved_in_elasticsearch(): assert doc.our_participants == 'me' assert doc.other_participants == 'them' assert doc.extra == {'a': 3} - assert doc.is_draft is False + assert not doc.is_draft def test_report__save_works_with_no_extra():