From b80f9a71bb6b27fe56179b3cde4163965de5c6c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Mon, 26 Feb 2018 00:45:20 +0100
Subject: [PATCH] Save of Report draft does not mark user as author.

---
 openlobby/core/models.py |  2 +-
 tests/test_models.py     | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/openlobby/core/models.py b/openlobby/core/models.py
index 36dca03..470de4c 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 bccd5d0..2cc7a8c 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():
-- 
GitLab