Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PEDASI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Research Software Group
PEDASI
Commits
9a3a2031
Commit
9a3a2031
authored
6 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Simplify API permission validators
parent
f483035d
No related branches found
No related tags found
1 merge request
!60
Merge dev pre-hackday
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/permissions.py
+13
-52
13 additions, 52 deletions
api/permissions.py
with
13 additions
and
52 deletions
api/permissions.py
+
13
−
52
View file @
9a3a2031
...
@@ -3,11 +3,9 @@ from rest_framework import permissions
...
@@ -3,11 +3,9 @@ from rest_framework import permissions
from
datasources
import
models
from
datasources
import
models
# TODO make permission class factory
class
BaseUserPermission
(
permissions
.
BasePermission
):
# TODO write permission tests
class
ViewPermission
(
permissions
.
BasePermission
):
message
=
'
You do not have permission to access this resource.
'
message
=
'
You do not have permission to access this resource.
'
permission_level
=
models
.
UserPermissionLevels
.
NONE
def
has_object_permission
(
self
,
request
,
view
,
obj
):
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
not
obj
.
access_control
:
if
not
obj
.
access_control
:
...
@@ -19,64 +17,27 @@ class ViewPermission(permissions.BasePermission):
...
@@ -19,64 +17,27 @@ class ViewPermission(permissions.BasePermission):
datasource
=
obj
datasource
=
obj
)
)
return
permission
.
granted
>=
models
.
UserP
ermission
L
evel
s
.
VIEW
return
permission
.
granted
>=
self
.
p
ermission
_l
evel
except
models
.
UserPermissionLink
.
DoesNotExist
:
except
models
.
UserPermissionLink
.
DoesNotExist
:
return
False
return
False
class
MetadataPermission
(
permissions
.
BasePermission
):
class
ViewPermission
(
BaseUserPermission
):
message
=
'
You do not have permission to access the metadata of this resource.
'
message
=
'
You do not have permission to access this resource.
'
permission_level
=
models
.
UserPermissionLevels
.
VIEW
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
not
obj
.
access_control
:
return
True
try
:
permission
=
models
.
UserPermissionLink
.
objects
.
get
(
user
=
request
.
user
,
datasource
=
obj
)
return
permission
.
granted
>=
models
.
UserPermissionLevels
.
META
except
models
.
UserPermissionLink
.
DoesNotExist
:
class
MetadataPermission
(
BaseUserPermission
):
return
False
message
=
'
You do not have permission to access the metadata of this resource.
'
permission_level
=
models
.
UserPermissionLevels
.
META
class
DataPermission
(
permissions
.
BasePermission
):
class
DataPermission
(
Base
User
Permission
):
message
=
'
You do not have permission to access the data of this resource.
'
message
=
'
You do not have permission to access the data of this resource.
'
permission_level
=
models
.
UserPermissionLevels
.
DATA
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
not
obj
.
access_control
:
return
True
try
:
permission
=
models
.
UserPermissionLink
.
objects
.
get
(
user
=
request
.
user
,
datasource
=
obj
)
return
permission
.
granted
>=
models
.
UserPermissionLevels
.
DATA
except
models
.
UserPermissionLink
.
DoesNotExist
:
class
ProvPermission
(
BaseUserPermission
):
return
False
class
ProvPermission
(
permissions
.
BasePermission
):
message
=
'
You do not have permission to access the prov data of this resource.
'
message
=
'
You do not have permission to access the prov data of this resource.
'
permission_level
=
models
.
UserPermissionLevels
.
PROV
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
not
obj
.
access_control
:
return
True
try
:
permission
=
models
.
UserPermissionLink
.
objects
.
get
(
user
=
request
.
user
,
datasource
=
obj
)
return
permission
.
granted
>=
models
.
UserPermissionLevels
.
PROV
except
models
.
UserPermissionLink
.
DoesNotExist
:
return
False
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment