Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
99
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
6805cae1
Commit
6805cae1
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
syntax: code format
parent
21fa9793
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!36
Resolve "auto_author gives permission to everybody???"
Pipeline
#837
passed with stage
in 1 minute and 26 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/permissions.py
+8
-5
8 additions, 5 deletions
djangoldp/permissions.py
djangoldp/tests/tests_user_permissions.py
+1
-0
1 addition, 0 deletions
djangoldp/tests/tests_user_permissions.py
with
9 additions
and
5 deletions
djangoldp/permissions.py
+
8
−
5
View file @
6805cae1
from
rest_framework
import
permissions
from
rest_framework
import
filters
from
guardian.shortcuts
import
get_objects_for_user
from
rest_framework
import
filters
from
rest_framework
import
permissions
"""
Liste des actions passées dans views selon le protocole REST :
...
...
@@ -16,6 +16,7 @@ Pour chacune de ces actions, on va définir si on accepte la requête (True) ou
checks have already passed
"""
class
WACPermissions
(
permissions
.
DjangoObjectPermissions
):
perms_map
=
{
'
GET
'
:
[
'
%(app_label)s.view_%(model_name)s
'
],
...
...
@@ -50,6 +51,7 @@ class ObjectFilter(filters.BaseFilterBackend):
objects
=
get_objects_for_user
(
request
.
user
,
perm
,
klass
=
queryset
)
return
objects
class
ObjectPermission
(
WACPermissions
):
filter_class
=
ObjectFilter
...
...
@@ -60,7 +62,7 @@ class InboxPermissions(WACPermissions):
Author can edit
"""
anonymous_perms
=
[
'
view
'
,
'
create
'
]
authenticated_perms
=
[
'
view
'
,
'
create
'
]
authenticated_perms
=
[
'
view
'
,
'
create
'
]
author_perms
=
[
'
view
'
]
def
has_permission
(
self
,
request
,
view
):
...
...
@@ -84,6 +86,7 @@ class InboxPermissions(WACPermissions):
else
:
return
self
.
authenticated_perms
class
AnonymousReadOnly
(
WACPermissions
):
"""
Anonymous users: can read all posts
...
...
@@ -92,7 +95,7 @@ class AnonymousReadOnly(WACPermissions):
"""
anonymous_perms
=
[
'
view
'
]
authenticated_perms
=
[
'
view
'
,
'
add
'
]
authenticated_perms
=
[
'
view
'
,
'
add
'
]
author_perms
=
[
'
view
'
,
'
add
'
,
'
change
'
,
'
control
'
,
'
delete
'
]
def
has_permission
(
self
,
request
,
view
):
...
...
@@ -123,4 +126,4 @@ class AnonymousReadOnly(WACPermissions):
if
hasattr
(
obj
.
_meta
,
'
auto_author
'
)
and
getattr
(
obj
,
obj
.
_meta
.
auto_author
)
==
request
.
user
:
return
self
.
author_perms
else
:
return
self
.
authenticated_perms
\ No newline at end of file
return
self
.
authenticated_perms
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_user_permissions.py
+
1
−
0
View file @
6805cae1
...
...
@@ -7,6 +7,7 @@ from djangoldp.views import LDPViewSet
import
json
class
TestUserPermissions
(
APITestCase
):
def
setUp
(
self
):
...
...
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