Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
39937de7
Kaydet (Commit)
39937de7
authored
Haz 05, 2015
tarafından
Raphael Michel
Kaydeden (comit)
Tim Graham
Haz 08, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24929 -- Allowed permission_required decorator to take any iterable
üst
8b1f39a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
2 deletions
+22
-2
decorators.py
django/contrib/auth/decorators.py
+2
-1
1.9.txt
docs/releases/1.9.txt
+4
-0
default.txt
docs/topics/auth/default.txt
+6
-1
test_decorators.py
tests/auth_tests/test_decorators.py
+10
-0
No files found.
django/contrib/auth/decorators.py
Dosyayı görüntüle @
39937de7
...
@@ -4,6 +4,7 @@ from django.conf import settings
...
@@ -4,6 +4,7 @@ from django.conf import settings
from
django.contrib.auth
import
REDIRECT_FIELD_NAME
from
django.contrib.auth
import
REDIRECT_FIELD_NAME
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.shortcuts
import
resolve_url
from
django.shortcuts
import
resolve_url
from
django.utils
import
six
from
django.utils.decorators
import
available_attrs
from
django.utils.decorators
import
available_attrs
from
django.utils.six.moves.urllib.parse
import
urlparse
from
django.utils.six.moves.urllib.parse
import
urlparse
...
@@ -59,7 +60,7 @@ def permission_required(perm, login_url=None, raise_exception=False):
...
@@ -59,7 +60,7 @@ def permission_required(perm, login_url=None, raise_exception=False):
is raised.
is raised.
"""
"""
def
check_perms
(
user
):
def
check_perms
(
user
):
if
not
isinstance
(
perm
,
(
list
,
tuple
)
):
if
isinstance
(
perm
,
six
.
string_types
):
perms
=
(
perm
,
)
perms
=
(
perm
,
)
else
:
else
:
perms
=
perm
perms
=
perm
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
39937de7
...
@@ -114,6 +114,10 @@ Minor features
...
@@ -114,6 +114,10 @@ Minor features
a deprecation warning in older versions and is no longer supported in
a deprecation warning in older versions and is no longer supported in
Django 1.9).
Django 1.9).
* The permission argument of
:func:`~django.contrib.auth.decorators.permission_required()` accepts all
kinds of iterables, not only list and tuples.
:mod:`django.contrib.gis`
:mod:`django.contrib.gis`
^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
docs/topics/auth/default.txt
Dosyayı görüntüle @
39937de7
...
@@ -580,7 +580,7 @@ The permission_required decorator
...
@@ -580,7 +580,7 @@ The permission_required decorator
(i.e. ``polls.can_vote`` for a permission on a model in the ``polls``
(i.e. ``polls.can_vote`` for a permission on a model in the ``polls``
application).
application).
The decorator may also take a
list
of permissions.
The decorator may also take a
n iterable
of permissions.
Note that :func:`~django.contrib.auth.decorators.permission_required()`
Note that :func:`~django.contrib.auth.decorators.permission_required()`
also takes an optional ``login_url`` parameter. Example::
also takes an optional ``login_url`` parameter. Example::
...
@@ -599,6 +599,11 @@ The permission_required decorator
...
@@ -599,6 +599,11 @@ The permission_required decorator
(HTTP Forbidden) view<http_forbidden_view>` instead of redirecting to the
(HTTP Forbidden) view<http_forbidden_view>` instead of redirecting to the
login page.
login page.
.. versionchanged:: 1.9
In older versions, the ``permission`` parameter only worked with
strings, lists, and tuples instead of strings and any iterable.
.. _applying-permissions-to-generic-views:
.. _applying-permissions-to-generic-views:
Applying permissions to generic views
Applying permissions to generic views
...
...
tests/auth_tests/test_decorators.py
Dosyayı görüntüle @
39937de7
...
@@ -76,6 +76,16 @@ class PermissionsRequiredDecoratorTest(TestCase):
...
@@ -76,6 +76,16 @@ class PermissionsRequiredDecoratorTest(TestCase):
resp
=
a_view
(
request
)
resp
=
a_view
(
request
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
def
test_many_permissions_in_set_pass
(
self
):
@permission_required
({
'auth.add_customuser'
,
'auth.change_customuser'
})
def
a_view
(
request
):
return
HttpResponse
()
request
=
self
.
factory
.
get
(
'/rand'
)
request
.
user
=
self
.
user
resp
=
a_view
(
request
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
def
test_single_permission_pass
(
self
):
def
test_single_permission_pass
(
self
):
@permission_required
(
'auth.add_customuser'
)
@permission_required
(
'auth.add_customuser'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment