Skip to content

Commit 52d248b

Browse files
authored
Merge pull request #7329 from escattone/fix-wiki-json-view-2890
fix wiki.json view
2 parents f1e91bb + 2dc3493 commit 52d248b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

kitsune/wiki/tests/test_views.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,30 @@ def test_json_view_404(self):
15141514
resp = self.client.get(url, {"title": "an article title ok."})
15151515
self.assertEqual(404, resp.status_code)
15161516

1517+
def test_json_view_restricted_document(self):
1518+
"""Restricted documents should not be visible to users outside the group."""
1519+
group = GroupFactory()
1520+
d = DocumentFactory(title="restricted article", restrict_to_groups=[group])
1521+
RevisionFactory(document=d, is_approved=True)
1522+
url = reverse("wiki.json")
1523+
1524+
# Anonymous user should get 404.
1525+
resp = self.client.get(url, {"title": "restricted article"})
1526+
self.assertEqual(404, resp.status_code)
1527+
1528+
# Logged-in user not in the group should get 404.
1529+
user = UserFactory()
1530+
self.client.login(username=user.username, password="testpass")
1531+
resp = self.client.get(url, {"title": "restricted article"})
1532+
self.assertEqual(404, resp.status_code)
1533+
1534+
# User in the group should get 200.
1535+
user.groups.add(group)
1536+
resp = self.client.get(url, {"title": "restricted article"})
1537+
self.assertEqual(200, resp.status_code)
1538+
data = json.loads(resp.content)
1539+
self.assertEqual("restricted article", data["title"])
1540+
15171541

15181542
class WhatLinksWhereTests(TestCase):
15191543
def test_what_links_here(self):

kitsune/wiki/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ def json_view(request):
12721272
else:
12731273
return HttpResponseBadRequest()
12741274

1275-
document = get_object_or_404(Document, **kwargs)
1275+
document = get_visible_document_or_404(request.user, **kwargs)
12761276
data = json.dumps(
12771277
{
12781278
"id": document.id,

0 commit comments

Comments
 (0)