Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
f513db71
Commit
f513db71
authored
Mar 12, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up TokenHasReadWriteScope slightly
parent
e8db504a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
26 deletions
+15
-26
rest_framework/compat.py
+2
-6
rest_framework/permissions.py
+13
-20
No files found.
rest_framework/compat.py
View file @
f513db71
...
@@ -445,19 +445,15 @@ except ImportError:
...
@@ -445,19 +445,15 @@ except ImportError:
# OAuth 2 support is optional
# OAuth 2 support is optional
try
:
try
:
import
provider.oauth2
as
oauth2_provider
import
provider.oauth2
as
oauth2_provider
# # Hack to fix submodule import issues
# submodules = ['backends', 'forms', 'managers', 'models', 'urls', 'views']
# for s in submodules:
# mod = __import__('provider.oauth2.%s.*' % s)
# setattr(oauth2_provider, s, mod)
from
provider.oauth2
import
backends
as
oauth2_provider_backends
from
provider.oauth2
import
backends
as
oauth2_provider_backends
from
provider.oauth2
import
models
as
oauth2_provider_models
from
provider.oauth2
import
models
as
oauth2_provider_models
from
provider.oauth2
import
forms
as
oauth2_provider_forms
from
provider.oauth2
import
forms
as
oauth2_provider_forms
from
provider
import
scope
as
oauth2_provider_scope
from
provider
import
scope
as
oauth2_provider_scope
from
provider
import
constants
as
oauth2_constants
except
ImportError
:
except
ImportError
:
oauth2_provider
=
None
oauth2_provider
=
None
oauth2_provider_backends
=
None
oauth2_provider_backends
=
None
oauth2_provider_models
=
None
oauth2_provider_models
=
None
oauth2_provider_forms
=
None
oauth2_provider_forms
=
None
oauth2_provider_scope
=
None
oauth2_provider_scope
=
None
oauth2_constants
=
None
rest_framework/permissions.py
View file @
f513db71
...
@@ -7,7 +7,7 @@ import warnings
...
@@ -7,7 +7,7 @@ import warnings
SAFE_METHODS
=
[
'GET'
,
'HEAD'
,
'OPTIONS'
]
SAFE_METHODS
=
[
'GET'
,
'HEAD'
,
'OPTIONS'
]
from
rest_framework.compat
import
oauth2_provider_scope
from
rest_framework.compat
import
oauth2_provider_scope
,
oauth2_constants
class
BasePermission
(
object
):
class
BasePermission
(
object
):
...
@@ -142,25 +142,18 @@ class TokenHasReadWriteScope(BasePermission):
...
@@ -142,25 +142,18 @@ class TokenHasReadWriteScope(BasePermission):
"""
"""
def
has_permission
(
self
,
request
,
view
):
def
has_permission
(
self
,
request
,
view
):
if
not
request
.
auth
:
token
=
request
.
auth
return
False
read_only
=
request
.
method
in
SAFE_METHODS
read_only
=
request
.
method
in
SAFE_METHODS
if
hasattr
(
request
.
auth
,
'resource'
):
# oauth 1
if
read_only
:
if
not
token
:
return
True
elif
request
.
auth
.
resource
.
is_readonly
is
False
:
return
True
return
False
elif
hasattr
(
request
.
auth
,
'scope'
):
# oauth 2
scope_valid
=
lambda
scope_wanted_key
,
scope_had
:
oauth2_provider_scope
.
check
(
oauth2_provider_scope
.
SCOPE_NAME_DICT
[
scope_wanted_key
],
scope_had
)
if
read_only
and
scope_valid
(
'read'
,
request
.
auth
.
scope
):
return
True
elif
scope_valid
(
'write'
,
request
.
auth
.
scope
):
return
True
return
False
return
False
if
hasattr
(
token
,
'resource'
):
# OAuth 1
return
read_only
or
not
request
.
auth
.
resource
.
is_readonly
elif
hasattr
(
token
,
'scope'
):
# OAuth 2
required
=
oauth2_constants
.
READ
if
read_only
else
oauth2_constants
.
WRITE
return
oauth2_provider_scope
.
check
(
required
,
request
.
auth
.
scope
)
else
:
else
:
# Improperly configured!
assert
False
,
(
'TokenHasReadWriteScope requires either the'
pass
'`OAuthAuthentication` or `OAuth2Authentication` authentication '
'class to be used.'
)
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