Skip to content

Commit

Permalink
Fix #155 -- Ensure users cannot reply to locked topics
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Apr 4, 2019
1 parent 5f4ba84 commit 4bc73d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions machina/apps/forum_conversation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ class PostCreateView(PermissionRequiredMixin, PostFormView):
""" Allows users to create forum posts. """

model = Post
permission_required = ['can_reply_to_topics', ]
template_name = 'forum_conversation/post_create.html'

def get(self, request, *args, **kwargs):
Expand Down Expand Up @@ -664,7 +663,7 @@ def get_context_data(self, **kwargs):

def get_controlled_object(self):
""" Returns the controlled object. """
return self.get_forum()
return self.get_topic()

def get_success_url(self):
""" Returns the URL to redirect the user to upon valid form processing. """
Expand All @@ -681,6 +680,10 @@ def get_success_url(self):
self.forum_post.pk,
)

def perform_permissions_check(self, user, obj, perms):
""" Performs the permission check. """
return self.request.forum_permission_handler.can_add_post(obj, user)


class PostUpdateView(PermissionRequiredMixin, PostFormView):
""" Allows users to update forum topics. """
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/apps/forum_conversation/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,24 @@ def test_cannot_be_browsed_by_users_who_cannot_reply_to_topics(self):
# Check
assert response.status_code == 403

def test_cannot_be_browsed_by_users_when_the_topic_is_locked(self):
# Setup
self.topic.status = Topic.TOPIC_LOCKED
self.topic.save()
correct_url = reverse(
'forum_conversation:post_create',
kwargs={
'forum_slug': self.top_level_forum.slug,
'forum_pk': self.top_level_forum.pk,
'topic_slug': self.topic.slug,
'topic_pk': self.topic.pk,
}
)
# Run
response = self.client.get(correct_url, follow=True)
# Check
assert response.status_code == 403

def test_embed_the_current_topic_into_the_context(self):
# Setup
correct_url = reverse(
Expand Down

0 comments on commit 4bc73d8

Please sign in to comment.