Commit 67071cc5 authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

usermanagement: correctly check membership

parent c3c4d4a8
......@@ -32,7 +32,6 @@ class Rights(int):
"private",
"protected",
"public",
"indirect",
"member",
"manager",
"admin",
......@@ -64,12 +63,7 @@ class Rights(int):
if self > self.member:
return False
if self.has_user(user, getattr(obj, "users", [])):
return True
if self > self.indirect:
return False
if self.has_user(user, getattr(obj, "get_users", list)()):
if getattr(obj, "is_member", lambda user: False)(user):
return True
return self <= {
......
......@@ -366,6 +366,18 @@ class Group(Base):
raise AjaxException('user %s not in group %s' % (user.name, self.name), 409)
session.delete(assoc)
def is_member(self, user):
"""
Check if this user is a member.
:param User user: The user to check.
:return: Whether the user is a member.
:rtype: Boolean
"""
if not isinstance(user, User):
raise TypeError("invalid type of user")
return self.id in user.get_group_ids()
def get_child_groups(self, recursion_depth=-1):
"""
Get child groups of a parent group. This function works as get_users regarding the recursion
......
......@@ -288,6 +288,20 @@ class Project(Base):
raise AjaxException("user %s not in project %s" % (user.name, self.name), 409)
session.delete(assoc)
def is_member(self, user):
"""
Check if this user is a member.
:param User user: The user to check.
:return: Whether the user is a member.
:rtype: Boolean
"""
if not isinstance(user, User):
raise TypeError("invalid type of user")
project_group_ids = set(assoc.group.id for assoc in self.groups)
user_group_ids = set(user.get_group_ids())
return not not (project_group_ids & user_group_ids)
def get_groups(self):
"""
Get groups of project.
......
......@@ -109,6 +109,18 @@ class Workgroup(Base):
"""
return self.users
def is_member(self, user):
"""
Check if this user is a member.
:param User user: The user to check.
:return: Whether the user is a member.
:rtype: Boolean
"""
if not isinstance(user, User):
raise TypeError("invalid type of user")
return user in self.users
def get_managers(self):
"""
Get managers of workgroup.
......
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