diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 9ef12cd1..62f1a1f3 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -99,3 +99,13 @@ class ProfileTestCase(BaseTestCase): self.alice.profile.refresh_from_db() self.assertEqual(self.alice.profile.team_name, "Alpha Team") + + def test_it_switches_to_own_team(self): + self.client.login(username="bob@example.org", password="password") + + self.client.get("/accounts/profile/") + + # After visiting the profile page, team should be switched back + # to user's default team. + self.bobs_profile.refresh_from_db() + self.assertEqual(self.bobs_profile.current_team, self.bobs_profile) diff --git a/hc/accounts/views.py b/hc/accounts/views.py index 0135043c..90bb3c56 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -121,6 +121,11 @@ def check_token(request, username, token): @login_required def profile(request): profile = request.user.profile + # Switch user back to its default team + if profile.current_team_id != profile.id: + request.team = profile + profile.current_team_id = profile.id + profile.save() show_api_key = False if request.method == "POST": diff --git a/hc/payments/context_processors.py b/hc/payments/context_processors.py index a6a428eb..e9e67a1f 100644 --- a/hc/payments/context_processors.py +++ b/hc/payments/context_processors.py @@ -2,4 +2,11 @@ from django.conf import settings def payments(request): - return {'USE_PAYMENTS': settings.USE_PAYMENTS} + + show_pricing = settings.USE_PAYMENTS + if show_pricing and request.user.is_authenticated(): + profile = request.user.profile + if profile.id != profile.current_team_id: + show_pricing = False + + return {'show_pricing': show_pricing} diff --git a/hc/payments/tests/test_pricing.py b/hc/payments/tests/test_pricing.py index 7a695ea4..5d17dded 100644 --- a/hc/payments/tests/test_pricing.py +++ b/hc/payments/tests/test_pricing.py @@ -19,3 +19,11 @@ class PricingTestCase(BaseTestCase): # A subscription object still should have NOT been created assert Subscription.objects.count() == 0 + + def test_pricing_is_hidden_for_team_members(self): + self.client.login(username="bob@example.org", password="password") + + r = self.client.get("/about/") + # Bob should not see pricing tab, as bob is currently on + # Alice's team, but is not its owner. + self.assertNotContains(r, "Pricing") diff --git a/templates/base.html b/templates/base.html index 0df5a352..488631de 100644 --- a/templates/base.html +++ b/templates/base.html @@ -83,7 +83,7 @@ {% endif %} - {% if USE_PAYMENTS %} + {% if show_pricing %}