From 73a5b865c4cf269023a69f69e2dbdc6573a693dd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 16 2015 12:24:47 +0000 Subject: Adjust the search_issues to allow showing None, Some or All private tickets - Admins can view all the private tickets: private set as None - Users can view their own private tickets: private set to their username - Everybody else cannot view any private tickets: private set to False --- diff --git a/progit/lib/__init__.py b/progit/lib/__init__.py index 4eaec71..d0a3bb6 100644 --- a/progit/lib/__init__.py +++ b/progit/lib/__init__.py @@ -604,7 +604,7 @@ def get_project(session, name, user=None): def search_issues( session, repo, issueid=None, status=None, closed=False, tags=None, - assignee=None, author=None): + assignee=None, author=None, private=None): ''' Retrieve one or more issues associated to a project with the given criterias. @@ -634,6 +634,13 @@ def search_issues( :type assignee: str or None :kwarg author: the name of the user who created the issues to search :type author: str or None + :kwarg private: boolean or string to use to include or exclude private + tickets. Defaults to False. + If False: private tickets are excluded + If None: private tickets are included + If user name is specified: private tickets reported by that user + are included. + :type private: False, None or str :return: A single Issue object if issueid is specified, a list of Project objects otherwise. @@ -692,6 +699,22 @@ def search_issues( model.User.user == author ) + if private is False: + query = query.filter( + model.Issue.private == False + ) + elif isinstance(private, basestring): + query = query.filter( + or_( + model.Issue.private == False, + and_( + model.Issue.private == True, + model.Issue.user_id == model.User.id, + model.User.user == private, + ) + ) + ) + if issueid is not None: output = query.first() else: