Commit 29aaeb66 authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier

fix: anonymous users

parent c89cedc5
Pipeline #7017 passed with stage
in 27 seconds
......@@ -5,15 +5,16 @@ from django.db.models.base import ModelBase
class ProjectPermissions(LDPPermissions):
def user_permissions(self, user, obj_or_model, obj=None):
if isinstance(obj_or_model, ModelBase):
return ['view', 'add']
else:
obj = obj_or_model
if obj.members.filter(user=user).exists():
if obj.members.filter(user=user).get().is_admin:
return ['view', 'add', 'change', 'delete']
else:
return ['view']
if not user.is_anonymous:
if isinstance(obj_or_model, ModelBase):
return ['view', 'add']
else:
obj = obj_or_model
if obj.members.filter(user=user).exists():
if obj.members.filter(user=user).get().is_admin:
return ['view', 'add', 'change', 'delete']
else:
return ['view']
return []
......@@ -21,23 +22,24 @@ class ProjectPermissions(LDPPermissions):
class ProjectMemberPermissions(LDPPermissions):
def user_permissions(self, user, obj_or_model, obj=None):
if isinstance(obj_or_model, ModelBase):
return ['view', 'add']
else:
obj = obj_or_model
if obj.user == user:
if obj.is_admin and obj.project.members.filter(is_admin=True).count() == 1:
return ['view']
else:
return ['view', 'delete']
if not user.is_anonymous:
if isinstance(obj_or_model, ModelBase):
return ['view', 'add']
else:
if obj.project.members.filter(user=user).exists():
if obj.project.members.filter(user=user).get().is_admin:
if obj.is_admin:
return ['view', 'add']
else:
return ['view', 'add', 'delete']
else:
obj = obj_or_model
if obj.user == user:
if obj.is_admin and obj.project.members.filter(is_admin=True).count() == 1:
return ['view']
else:
return ['view', 'delete']
else:
if obj.project.members.filter(user=user).exists():
if obj.project.members.filter(user=user).get().is_admin:
if obj.is_admin:
return ['view', 'add']
else:
return ['view', 'add', 'delete']
else:
return ['view']
return []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment