@@ -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
15181542class WhatLinksWhereTests (TestCase ):
15191543 def test_what_links_here (self ):
0 commit comments