mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 05:04:31 +03:00
added guardian as optional requirement, stubbed out object-level permission class
This commit is contained in:
parent
551fe92078
commit
4a9dcfa760
|
@ -42,6 +42,7 @@ The following packages are optional:
|
|||
* [django-filter][django-filter] (0.5.4+) - Filtering support.
|
||||
* [django-oauth-plus][django-oauth-plus] (2.0+) and [oauth2][oauth2] (1.5.211+) - OAuth 1.0a support.
|
||||
* [django-oauth2-provider][django-oauth2-provider] (0.2.3+) - OAuth 2.0 support.
|
||||
* [django-guardian][django-guardian] (1.1.1+) - Object level permissions support.
|
||||
|
||||
**Note**: The `oauth2` Python package is badly misnamed, and actually provides OAuth 1.0a support. Also note that packages required for both OAuth 1.0a, and OAuth 2.0 are not yet Python 3 compatible.
|
||||
|
||||
|
|
|
@ -47,6 +47,12 @@ try:
|
|||
except ImportError:
|
||||
django_filters = None
|
||||
|
||||
# guardian is optional
|
||||
try:
|
||||
import guardian
|
||||
except ImportError:
|
||||
guardian = None
|
||||
|
||||
|
||||
# cStringIO only if it's available, otherwise StringIO
|
||||
try:
|
||||
|
|
|
@ -7,7 +7,7 @@ import warnings
|
|||
|
||||
SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
|
||||
|
||||
from rest_framework.compat import oauth2_provider_scope, oauth2_constants
|
||||
from rest_framework.compat import oauth2_provider_scope, oauth2_constants, guardian
|
||||
|
||||
|
||||
class BasePermission(object):
|
||||
|
@ -151,6 +151,11 @@ class DjangoModelPermissionsOrAnonReadOnly(DjangoModelPermissions):
|
|||
authenticated_users_only = False
|
||||
|
||||
|
||||
class DjangoObjectLevelModelPermissions(DjangoModelPermissions):
|
||||
def __init__(self):
|
||||
assert guardian, 'Using DjangoObjectLevelModelPermissions, but guardian is not installed'
|
||||
|
||||
|
||||
class TokenHasReadWriteScope(BasePermission):
|
||||
"""
|
||||
The request is authenticated as a user and the token used has the right scope
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.db import models
|
|||
from django.test import TestCase
|
||||
from rest_framework import generics, status, permissions, authentication, HTTP_HEADER_ENCODING
|
||||
from rest_framework.test import APIRequestFactory
|
||||
from rest_framework.compat import guardian
|
||||
import base64
|
||||
|
||||
factory = APIRequestFactory()
|
||||
|
|
Loading…
Reference in New Issue
Block a user