Commit 3fe7f0a7 authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

[models] User.get_projects functionality expanded

- added option to also retrieve (merely) managed projects
- added option to filter out the global project
- also exposed the options in the usermanagement controller (user_projects)
parent e3727187
......@@ -381,5 +381,8 @@ class UMAjaxController(AbstractController):
return [grp.name for grp in cherrypy.request.user.get_groups()]
@cherrypy.expose
def user_projects(self):
return [pro.name for pro in cherrypy.request.user.get_projects()]
def user_projects(self, managed=False, no_global_project=False):
return [pro.name for pro in cherrypy.request.user.get_projects(
managed=not not managed,
no_global_project=not not no_global_project
)]
......@@ -366,26 +366,48 @@ Your Vispa-Team!""" % (user.name, link)
return object_session(self).query(Group).filter(Group.id.in_(self.get_group_ids())).all()
def get_projects(self):
def get_projects(self, managed=False, no_global_project=False):
"""
Retrive all projects the user is a member of. Membership does not include being a mere
manager.
:param Boolean managed: Also return projects that are just managed be the user. Defaults to
*False*.
:param Boolean no_global_project: Filter out the global project. Defaults to *False*.
:return: All projects the user is a member of.
:rtype: list[Project]
"""
from vispa.models.project import Project, Project_User_Assoc, Project_Group_Assoc
from vispa.models.project import Project, Project_User_Assoc, Project_Group_Assoc, \
project_manager_association
return object_session(self).query(Project).filter(
Project.status == Project.ACTIVE,
ftemp = [
(
(Project_User_Assoc.project_id == Project.id) &
(Project_User_Assoc.user_id == self.id)
) | (
(Project_Group_Assoc.project_id == Project.id) &
(Project_Group_Assoc.group_id.in_(self.get_group_ids()))
)
).all()
Project_Group_Assoc,
Project_Group_Assoc.group_id.in_(self.get_group_ids())
),
(
Project_User_Assoc,
Project_User_Assoc.user_id == self.id
),
]
if managed:
ftemp.append((
project_manager_association,
project_manager_association.c.user_id == self.id
))
q = object_session(self).query(Project).filter_by(status=Project.ACTIVE)
if no_global_project:
global_project_name = vispa.config("usermanagement", "global_project", None)
if global_project_name is not None:
q = q.filter(Project.name != global_project_name)
q = q.outerjoin(*[t for (t, f) in ftemp])
q = q.filter(reduce(lambda a, b: a | b, (f for (t, f) in ftemp)))
return q.all()
def has_all_permissions(self, project, permissions, ignoreInexistent=False):
"""
......
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