Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Djangoldp Project
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Startin blox
djangoldp-packages
Djangoldp Project
Commits
6deb29e7
Commit
6deb29e7
authored
Jan 08, 2020
by
Calum Mackervoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error messages explaining why permission denied
parent
1a18bab0
Pipeline
#6979
passed with stage
in 27 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
+10
-5
djangoldp_project/permissions.py
djangoldp_project/permissions.py
+10
-5
No files found.
djangoldp_project/permissions.py
View file @
6deb29e7
from
djangoldp.permissions
import
LDPPermissions
from
rest_framework.exceptions
import
PermissionDenied
# auxiliary function tests user is an admin for specified project
...
...
@@ -38,10 +39,10 @@ class ProjectPermissions(LDPPermissions):
# other members can perform GET only
if
request
.
method
!=
'GET'
:
r
eturn
False
r
aise
PermissionDenied
(
detail
=
'You must be an admin to perform this action'
)
if
not
Member
.
objects
.
filter
(
user
=
request
.
user
,
project
=
obj
)
.
exists
():
r
eturn
False
r
aise
PermissionDenied
(
detail
=
'You must be a member of this project to perform this action'
)
return
super
()
.
has_object_permission
(
request
,
view
,
obj
)
...
...
@@ -61,7 +62,10 @@ class ProjectMemberPermissions(LDPPermissions):
# only admins can add new members to a project
if
request
.
method
==
'POST'
:
obj
=
Model
.
resolve_id
(
request
.
_request
.
path
)
return
is_user_admin_of_project
(
request
.
user
,
obj
.
project
)
if
is_user_admin_of_project
(
request
.
user
,
obj
.
project
):
return
True
else
:
raise
PermissionDenied
(
detail
=
'You must be an admin to perform this action'
)
return
super
()
.
has_permission
(
request
,
view
)
...
...
@@ -76,11 +80,12 @@ class ProjectMemberPermissions(LDPPermissions):
# I cannot remove myself if I am the last admin
if
obj
.
pk
==
request
.
user
.
pk
:
if
obj
.
project
.
get_admins
()
.
count
()
==
1
:
return
False
raise
PermissionDenied
(
detail
=
'To leave this project, you must first set up a new administrator'
' through the project panel'
)
# I cannot remove another admin
elif
obj
.
is_admin
:
r
eturn
False
r
aise
PermissionDenied
(
detail
=
'You cannot remove another admin'
)
return
True
...
...
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