diff --git a/README.md b/README.md index 2681b79..662107a 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,6 @@ GET https://api.example.org/accounts/?page=4&limit=100 # Permissions -## DjangoModelPermissions - -Add ``view`` permission control. - -Usage: - -``` -from djangorestframework_ext.permissions import DjangoModelPermissions -``` - ## IsCurrentUser Determine whether the object is the current login user. diff --git a/rest_framework_ext/permissions.py b/rest_framework_ext/permissions.py index 4164825..668a173 100644 --- a/rest_framework_ext/permissions.py +++ b/rest_framework_ext/permissions.py @@ -1,24 +1,17 @@ -from rest_framework import permissions +from rest_framework.permissions import BasePermission -class DjangoModelPermissions(permissions.DjangoModelPermissions): - def __init__(self): - self.perms_map['GET'] = ['%(app_label)s.view_%(model_name)s'] - self.perms_map['OPTIONS'] = ['%(app_label)s.view_%(model_name)s'] - self.perms_map['HEAD'] = ['%(app_label)s.view_%(model_name)s'] - - -class IsCurrentUser(permissions.BasePermission): +class IsCurrentUser(BasePermission): def has_object_permission(self, request, view, obj): return obj == request.user -class IsSuperuser(permissions.BasePermission): +class IsSuperuser(BasePermission): def has_permission(self, request, view): return bool(request.user and request.user.is_superuser) -class ExportPermission(permissions.BasePermission): +class ExportPermission(BasePermission): def has_permission(self, request, view): if view.action == 'export': model = view.get_queryset().model diff --git a/setup.py b/setup.py index b0bcbc5..2ddaf31 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='djangorestframework-ext', - version='0.19', + version='0.20', url='https://github.com/zengqiu/django-rest-framework-ext', license='MIT', author='zengqiu', @@ -18,7 +18,7 @@ long_description_content_type='text/markdown', packages=find_packages(), platforms='any', - install_requires=['django>=3.2', 'djangorestframework>=3.10.0'], + install_requires=['django>=3.2', 'djangorestframework>=3.15'], python_requires='>=3.5', classifiers=[ 'Development Status :: 5 - Production/Stable',