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 [ for grp in cherrypy.request.user.get_groups()]
def user_projects(self):
return [ for pro in cherrypy.request.user.get_projects()]
def user_projects(self, managed=False, no_global_project=False):
return [ 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!""" % (, link)
return object_session(self).query(Group).filter(
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
:param Boolean managed: Also return projects that are just managed be the user. Defaults to
: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, \
return object_session(self).query(Project).filter(
Project.status == Project.ACTIVE,
ftemp = [
(Project_User_Assoc.project_id == &
(Project_User_Assoc.user_id ==
) | (
(Project_Group_Assoc.project_id == &
Project_User_Assoc.user_id ==
if managed:
project_manager_association.c.user_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( != 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