Code

Ticket #18038: 18038-2.diff

File 18038-2.diff, 8.2 KB (added by claudep, 2 years ago)

Tests included

Line 
1diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py
2index 3495e16..dd816ce 100644
3--- a/django/contrib/auth/__init__.py
4+++ b/django/contrib/auth/__init__.py
5@@ -1,4 +1,3 @@
6-from warnings import warn
7 from django.core.exceptions import ImproperlyConfigured
8 from django.utils.importlib import import_module
9 from django.contrib.auth.signals import user_logged_in, user_logged_out
10@@ -20,11 +19,6 @@ def load_backend(path):
11         cls = getattr(mod, attr)
12     except AttributeError:
13         raise ImproperlyConfigured('Module "%s" does not define a "%s" authentication backend' % (module, attr))
14-
15-    if not hasattr(cls, 'supports_inactive_user'):
16-        warn("Authentication backends without a `supports_inactive_user` attribute are deprecated. Please define it in %s." % cls,
17-             DeprecationWarning)
18-        cls.supports_inactive_user = False
19     return cls()
20 
21 def get_backends():
22diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
23index 56cdb42..04fbef4 100644
24--- a/django/contrib/auth/backends.py
25+++ b/django/contrib/auth/backends.py
26@@ -5,7 +5,6 @@ class ModelBackend(object):
27     """
28     Authenticates against django.contrib.auth.models.User.
29     """
30-    supports_inactive_user = True
31 
32     # TODO: Model, login attribute name and password attribute name should be
33     # configurable.
34diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
35index 4e15849..042420a 100644
36--- a/django/contrib/auth/models.py
37+++ b/django/contrib/auth/models.py
38@@ -200,14 +200,13 @@ def _user_has_perm(user, perm, obj):
39     anon = user.is_anonymous()
40     active = user.is_active
41     for backend in auth.get_backends():
42-        if anon or active or backend.supports_inactive_user:
43-            if hasattr(backend, "has_perm"):
44-                if obj is not None:
45-                    if backend.has_perm(user, perm, obj):
46-                            return True
47-                else:
48-                    if backend.has_perm(user, perm):
49-                        return True
50+        if hasattr(backend, "has_perm"):
51+            if obj is not None:
52+                if backend.has_perm(user, perm, obj):
53+                    return True
54+            else:
55+                if backend.has_perm(user, perm):
56+                    return True
57     return False
58 
59 
60@@ -215,10 +214,9 @@ def _user_has_module_perms(user, app_label):
61     anon = user.is_anonymous()
62     active = user.is_active
63     for backend in auth.get_backends():
64-        if anon or active or backend.supports_inactive_user:
65-            if hasattr(backend, "has_module_perms"):
66-                if backend.has_module_perms(user, app_label):
67-                    return True
68+        if hasattr(backend, "has_module_perms"):
69+            if backend.has_module_perms(user, app_label):
70+                return True
71     return False
72 
73 
74diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py
75index cc61977..16eaa5c 100644
76--- a/django/contrib/auth/tests/__init__.py
77+++ b/django/contrib/auth/tests/__init__.py
78@@ -1,6 +1,6 @@
79 from django.contrib.auth.tests.auth_backends import (BackendTest,
80     RowlevelBackendTest, AnonymousUserBackendTest, NoBackendsTest,
81-    InActiveUserBackendTest, NoInActiveUserBackendTest)
82+    InActiveUserBackendTest)
83 from django.contrib.auth.tests.basic import BasicTestCase
84 from django.contrib.auth.tests.context_processors import AuthContextProcessorTests
85 from django.contrib.auth.tests.decorators import LoginRequiredTestCase
86diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
87index 0337ef1..106af24 100644
88--- a/django/contrib/auth/tests/auth_backends.py
89+++ b/django/contrib/auth/tests/auth_backends.py
90@@ -103,12 +103,6 @@ class TestObj(object):
91 
92 
93 class SimpleRowlevelBackend(object):
94-    supports_inactive_user = False
95-
96-    # This class also supports tests for anonymous user permissions, and
97-    # inactive user permissions via subclasses which just set the
98-    # 'supports_anonymous_user' or 'supports_inactive_user' attribute.
99-
100     def has_perm(self, user, perm, obj=None):
101         if not obj:
102             return # We only support row level perms
103@@ -195,16 +189,12 @@ class RowlevelBackendTest(TestCase):
104         self.assertEqual(self.user3.get_group_permissions(TestObj()), set(['group_perm']))
105 
106 
107-class AnonymousUserBackend(SimpleRowlevelBackend):
108-    supports_inactive_user = False
109-
110-
111 class AnonymousUserBackendTest(TestCase):
112     """
113     Tests for AnonymousUser delegating to backend.
114     """
115 
116-    backend = 'django.contrib.auth.tests.auth_backends.AnonymousUserBackend'
117+    backend = 'django.contrib.auth.tests.auth_backends.SimpleRowlevelBackend'
118 
119     def setUp(self):
120         self.curr_auth = settings.AUTHENTICATION_BACKENDS
121@@ -231,7 +221,6 @@ class AnonymousUserBackendTest(TestCase):
122 
123 
124 
125-
126 class NoBackendsTest(TestCase):
127     """
128     Tests that an appropriate error is raised if no auth backends are provided.
129@@ -248,20 +237,11 @@ class NoBackendsTest(TestCase):
130         self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', TestObj(),))
131 
132 
133-class InActiveUserBackend(SimpleRowlevelBackend):
134-    supports_inactive_user = True
135-
136-
137-class NoInActiveUserBackend(SimpleRowlevelBackend):
138-    supports_inactive_user = False
139-
140-
141 class InActiveUserBackendTest(TestCase):
142     """
143-    Tests for a inactive user delegating to backend if it has 'supports_inactive_user' = True
144+    Tests for a inactive user
145     """
146-
147-    backend = 'django.contrib.auth.tests.auth_backends.InActiveUserBackend'
148+    backend = 'django.contrib.auth.tests.auth_backends.SimpleRowlevelBackend'
149 
150     def setUp(self):
151         self.curr_auth = settings.AUTHENTICATION_BACKENDS
152@@ -280,29 +260,3 @@ class InActiveUserBackendTest(TestCase):
153     def test_has_module_perms(self):
154         self.assertEqual(self.user1.has_module_perms("app1"), False)
155         self.assertEqual(self.user1.has_module_perms("app2"), False)
156-
157-
158-class NoInActiveUserBackendTest(TestCase):
159-    """
160-    Tests that an inactive user does not delegate to backend if it has 'supports_inactive_user' = False
161-    """
162-    backend = 'django.contrib.auth.tests.auth_backends.NoInActiveUserBackend'
163-
164-    def setUp(self):
165-        self.curr_auth = settings.AUTHENTICATION_BACKENDS
166-        settings.AUTHENTICATION_BACKENDS = tuple(self.curr_auth) + (self.backend,)
167-        self.user1 = User.objects.create_user('test', 'test@example.com', 'test')
168-        self.user1.is_active = False
169-        self.user1.save()
170-
171-    def tearDown(self):
172-        settings.AUTHENTICATION_BACKENDS = self.curr_auth
173-
174-    def test_has_perm(self):
175-        self.assertEqual(self.user1.has_perm('perm', TestObj()), False)
176-        self.assertEqual(self.user1.has_perm('inactive', TestObj()), False)
177-
178-    def test_has_module_perms(self):
179-        self.assertEqual(self.user1.has_module_perms("app1"), False)
180-        self.assertEqual(self.user1.has_module_perms("app2"), False)
181-
182diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
183index 12adda8..69e3b7d 100644
184--- a/docs/topics/auth.txt
185+++ b/docs/topics/auth.txt
186@@ -1838,8 +1838,6 @@ object the first time a user authenticates::
187         ADMIN_PASSWORD = 'sha1$4e987$afbcf42e21bd417fb71db8c66b321e9fc33051de'
188         """
189 
190-        supports_inactive_user = False
191-
192         def authenticate(self, username=None, password=None):
193             login_valid = (settings.ADMIN_LOGIN == username)
194             pwd_valid = check_password(password, settings.ADMIN_PASSWORD)
195@@ -1938,16 +1936,6 @@ The support for anonymous users in the permission system allows for
196 anonymous users to have permissions to do something while inactive
197 authenticated users do not.
198 
199-To enable this on your own backend, you must set the class attribute
200-``supports_inactive_user`` to ``True``.
201-
202-A nonexisting ``supports_inactive_user`` attribute will raise a
203-``PendingDeprecationWarning`` if used in Django 1.3. In Django 1.4, this
204-warning will be updated to a ``DeprecationWarning`` which will be displayed
205-loudly. Additionally ``supports_inactive_user`` will be set to ``False``.
206-Django 1.5 will assume that every backend supports inactive users being
207-passed to the authorization methods.
208-
209 
210 Handling object permissions
211 ---------------------------