@@ -827,6 +827,46 @@ def testChangeView(self):
827827 self .assertContains (request , 'login-form' )
828828 self .client .get ('/test_admin/admin/logout/' )
829829
830+ def testHistoryView (self ):
831+ """History view should restrict access."""
832+
833+ # add user shoud not be able to view the list of article or change any of them
834+ self .client .get ('/test_admin/admin/' )
835+ self .client .post ('/test_admin/admin/' , self .adduser_login )
836+ response = self .client .get ('/test_admin/admin/admin_views/article/1/history/' )
837+ self .assertEqual (response .status_code , 403 )
838+ self .client .get ('/test_admin/admin/logout/' )
839+
840+ # change user can view all items and edit them
841+ self .client .get ('/test_admin/admin/' )
842+ self .client .post ('/test_admin/admin/' , self .changeuser_login )
843+ response = self .client .get ('/test_admin/admin/admin_views/article/1/history/' )
844+ self .assertEqual (response .status_code , 200 )
845+
846+ # Test redirection when using row-level change permissions. Refs #11513.
847+ RowLevelChangePermissionModel .objects .create (id = 1 , name = "odd id" )
848+ RowLevelChangePermissionModel .objects .create (id = 2 , name = "even id" )
849+ for login_dict in [self .super_login , self .changeuser_login , self .adduser_login , self .deleteuser_login ]:
850+ self .client .post ('/test_admin/admin/' , login_dict )
851+ response = self .client .get ('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/history/' )
852+ self .assertEqual (response .status_code , 403 )
853+
854+ response = self .client .get ('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/history/' )
855+ self .assertEqual (response .status_code , 200 )
856+
857+ self .client .get ('/test_admin/admin/logout/' )
858+
859+ for login_dict in [self .joepublic_login , self .no_username_login ]:
860+ self .client .post ('/test_admin/admin/' , login_dict )
861+ response = self .client .get ('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/history/' )
862+ self .assertEqual (response .status_code , 200 )
863+ self .assertContains (response , 'login-form' )
864+ response = self .client .get ('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/history/' )
865+ self .assertEqual (response .status_code , 200 )
866+ self .assertContains (response , 'login-form' )
867+
868+ self .client .get ('/test_admin/admin/logout/' )
869+
830870 def testConditionallyShowAddSectionLink (self ):
831871 """
832872 The foreign key widget should only show the "add related" button if the
0 commit comments