Skip to content

Commit

Permalink
Fix possible inconsistency when moving topics through moderation
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed May 18, 2020
1 parent 09bdcd6 commit 32417b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 0 additions & 2 deletions machina/apps/forum_moderation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def form_valid(self, form):
""" Handles a valid form. """
# Move the topic
topic = self.object
old_forum = topic.forum
new_forum = form.cleaned_data['forum']
topic.forum = new_forum

Expand All @@ -213,7 +212,6 @@ def form_valid(self, form):
topic.status = Topic.TOPIC_MOVED

topic.save()
old_forum.save()

messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url())
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/apps/forum_moderation/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def setup(self):
self.other_forum = create_forum()

# Set up a topic and some posts
self.previous_topic = create_topic(forum=self.top_level_forum, poster=self.user)
self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
self.first_post = PostFactory.create(topic=self.topic, poster=self.user)
self.post = PostFactory.create(topic=self.topic, poster=self.user)
Expand Down Expand Up @@ -293,6 +294,8 @@ def test_can_move_topics(self):
# Check
self.topic.refresh_from_db()
assert self.topic.forum == self.other_forum
self.top_level_forum.refresh_from_db()
assert self.top_level_forum.last_post == self.previous_topic.last_post

def test_can_move_and_lock_topics(self):
# Setup
Expand Down

0 comments on commit 32417b1

Please sign in to comment.