Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise Http404 on inaccessible posts #1153

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion posts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def md_show_post(request, post_type, post_slug):
if not post.is_public:
access_denied = check_user_permissions(request, post=post)
if access_denied:
raise ApiAuthRequired()
raise Http404()

post_markdown = f"""# {post.title}\n\n{post.text}"""

Expand Down
9 changes: 9 additions & 0 deletions posts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def test_show_post(self):

self.assertContains(response=response, text='', status_code=200)

def test_404_on_hidden_post(self):
post = self.creator.create_post(
is_visible=True,
is_public=False,
)
client = self._authorized_client(None)
response = client.get(self._post_url(post))
self.assertContains(response=response, text='', status_code=404)

def test_show_draft_post(self):
'''
Is regression test for #545.
Expand Down
2 changes: 1 addition & 1 deletion posts/views/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def show_post(request, post_type, post_slug):
if not post.is_public:
access_denied = check_user_permissions(request, post=post)
if access_denied:
return access_denied
raise Http404()

# record a new view
last_view_at = None
Expand Down
Loading