diff --git a/gratipay/models/participant/__init__.py b/gratipay/models/participant/__init__.py index 2786ba53e6..c6dd899087 100644 --- a/gratipay/models/participant/__init__.py +++ b/gratipay/models/participant/__init__.py @@ -1077,13 +1077,11 @@ def profile_url(self): return '{base_url}/{username}/'.format(**locals()) - def get_teams(self, only_approved=False, cursor=None): + def get_teams(self, only_approved=False, only_open=False, cursor=None): """Return a list of teams this user is an owner or member of. """ teams = (cursor or self.db).all(""" - SELECT teams.*::teams FROM teams WHERE - owner=%s AND - NOT is_closed + SELECT teams.*::teams FROM teams WHERE owner=%s UNION @@ -1094,6 +1092,8 @@ def get_teams(self, only_approved=False, cursor=None): ) if only_approved: teams = [t for t in teams if t.is_approved] + if only_open: + teams = [t for t in teams if not t.is_closed] return teams diff --git a/templates/team-listing.html b/templates/team-listing.html index 51807d940e..0aca8a9e18 100644 --- a/templates/team-listing.html +++ b/templates/team-listing.html @@ -1,16 +1,16 @@ -{% set approved_teams = participant.get_teams(only_approved=True) %} +{% set approved_open_teams = participant.get_teams(only_approved=True, only_open=True) %} -{% if (user.ADMIN or user.participant == participant) and approved_teams %} +{% if (user.ADMIN or user.participant == participant) and approved_open_teams %}

{{ _("Projects") }}

-{% elif approved_teams %} +{% elif approved_open_teams %}

{{ _("Projects") }}

diff --git a/tests/py/test_participant.py b/tests/py/test_participant.py index bf41ed86d2..524297a663 100644 --- a/tests/py/test_participant.py +++ b/tests/py/test_participant.py @@ -257,11 +257,19 @@ def test_get_teams_can_get_only_approved_teams(self): self.make_team('The Stargazer', owner=picard, is_approved=False) assert [t.slug for t in picard.get_teams(only_approved=True)] == ['TheEnterprise'] + def test_get_teams_can_get_only_open_teams(self): + self.make_team() + picard = P('picard') + self.make_team('The Stargazer', owner=picard, is_closed=False) + assert [t.slug for t in picard.get_teams(only_closed=True)] == ['TheEnterprise'] + def test_get_teams_can_get_all_teams(self): self.make_team(is_approved=True) picard = P('picard') self.make_team('The Stargazer', owner=picard, is_approved=False) - assert [t.slug for t in picard.get_teams()] == ['TheEnterprise', 'TheStargazer'] + self.make_team('The Trident', owner=picard, is_approved=False, is_closed=True) + assert [t.slug for t in picard.get_teams()] == \ + ['TheEnterprise', 'TheStargazer', 'TheTrident'] # giving