Skip to content

Commit eee260e

Browse files
committed
Added IsSuperuser permission
1 parent 6e94c94 commit eee260e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,24 @@ from djangorestframework_ext.permissions import DjangoModelPermissions
4646

4747
## IsCurrentUser
4848

49-
Determine whether it is the current login user.
49+
Determine whether the object is the current login user.
5050

5151
Usage:
5252

5353
```
5454
from djangorestframework_ext.permissions import IsCurrentUser
5555
```
5656

57+
## IsSuperuser
58+
59+
Determine whether the request user is superuser.
60+
61+
Usage:
62+
63+
```
64+
from djangorestframework_ext.permissions import IsSuperuser
65+
```
66+
5767
# Serializers
5868

5969
## RecursiveSerializer

rest_framework_ext/permissions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def has_object_permission(self, request, view, obj):
1313
return obj == request.user
1414

1515

16+
class IsSuperuser(permissions.BasePermission):
17+
def has_permission(self, request, view):
18+
return bool(request.user and request.user.is_superuser)
19+
20+
1621
class ExportPermission(permissions.BasePermission):
1722
def has_permission(self, request, view):
1823
if view.action == 'export':

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='djangorestframework-ext',
11-
version='0.17',
11+
version='0.18',
1212
url='https://github.com/zengqiu/django-rest-framework-ext',
1313
license='MIT',
1414
author='zengqiu',
@@ -34,6 +34,8 @@
3434
'Programming Language :: Python :: 3.8',
3535
'Programming Language :: Python :: 3.9',
3636
'Programming Language :: Python :: 3.10',
37+
'Programming Language :: Python :: 3.11',
38+
'Programming Language :: Python :: 3.12',
3739
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
3840
'Topic :: Software Development :: Libraries :: Python Modules',
3941
]

0 commit comments

Comments
 (0)