Browse Source

Team Access refinements.

pull/60/head
Pēteris Caune 9 years ago
parent
commit
b725b5c4a5
5 changed files with 33 additions and 3 deletions
  1. +10
    -0
      hc/accounts/tests/test_profile.py
  2. +5
    -0
      hc/accounts/views.py
  3. +8
    -1
      hc/payments/context_processors.py
  4. +8
    -0
      hc/payments/tests/test_pricing.py
  5. +2
    -2
      templates/base.html

+ 10
- 0
hc/accounts/tests/test_profile.py View File

@ -99,3 +99,13 @@ class ProfileTestCase(BaseTestCase):
self.alice.profile.refresh_from_db() self.alice.profile.refresh_from_db()
self.assertEqual(self.alice.profile.team_name, "Alpha Team") self.assertEqual(self.alice.profile.team_name, "Alpha Team")
def test_it_switches_to_own_team(self):
self.client.login(username="[email protected]", 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)

+ 5
- 0
hc/accounts/views.py View File

@ -121,6 +121,11 @@ def check_token(request, username, token):
@login_required @login_required
def profile(request): def profile(request):
profile = request.user.profile 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 show_api_key = False
if request.method == "POST": if request.method == "POST":


+ 8
- 1
hc/payments/context_processors.py View File

@ -2,4 +2,11 @@ from django.conf import settings
def payments(request): 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}

+ 8
- 0
hc/payments/tests/test_pricing.py View File

@ -19,3 +19,11 @@ class PricingTestCase(BaseTestCase):
# A subscription object still should have NOT been created # A subscription object still should have NOT been created
assert Subscription.objects.count() == 0 assert Subscription.objects.count() == 0
def test_pricing_is_hidden_for_team_members(self):
self.client.login(username="[email protected]", 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")

+ 2
- 2
templates/base.html View File

@ -83,7 +83,7 @@
{% endif %} {% endif %}
{% if USE_PAYMENTS %}
{% if show_pricing %}
<li {% if page == 'pricing' %} class="active" {% endif %}> <li {% if page == 'pricing' %} class="active" {% endif %}>
<a href="{% url 'hc-pricing' %}">Pricing</a> <a href="{% url 'hc-pricing' %}">Pricing</a>
</li> </li>
@ -152,7 +152,7 @@
<ul> <ul>
<li>&copy; 2015-2016 Monkey See Monkey Do SIA</li> <li>&copy; 2015-2016 Monkey See Monkey Do SIA</li>
<li><a href="{% url 'hc-privacy' %}">Privacy</a></li> <li><a href="{% url 'hc-privacy' %}">Privacy</a></li>
{% if USE_PAYMENTS %}
{% if show_pricing %}
<li><a href="{% url 'hc-pricing' %}">Pricing</a></li> <li><a href="{% url 'hc-pricing' %}">Pricing</a></li>
{% endif %} {% endif %}
<li><a href="{% url 'hc-about' %}">Contact</a></li> <li><a href="{% url 'hc-about' %}">Contact</a></li>


Loading…
Cancel
Save