Browse Source

Pricing in top nav is visible for team members too, but pricing page says "you are not the team owner".

pull/140/head
Pēteris Caune 7 years ago
parent
commit
6a57bcfdf3
5 changed files with 52 additions and 22 deletions
  1. +1
    -9
      hc/payments/context_processors.py
  2. +9
    -12
      hc/payments/tests/test_pricing.py
  3. +4
    -0
      hc/payments/views.py
  4. +3
    -1
      templates/payments/pricing.html
  5. +35
    -0
      templates/payments/pricing_not_owner.html

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

@ -2,12 +2,4 @@ from django.conf import settings
def payments(request):
show_pricing = settings.USE_PAYMENTS
if show_pricing and request.user.is_authenticated:
if request.profile != request.team:
# Hide "Pricing" tab when user is not working on their
# own team
show_pricing = False
return {'show_pricing': show_pricing}
return {'show_pricing': settings.USE_PAYMENTS}

+ 9
- 12
hc/payments/tests/test_pricing.py View File

@ -23,18 +23,15 @@ class PricingTestCase(BaseTestCase):
assert Subscription.objects.count() == 0
@override_settings(USE_PAYMENTS=True)
def test_pricing_is_hidden_for_team_members(self):
def test_pricing_is_visible_for_all(self):
for email in ("[email protected]", "[email protected]"):
self.client.login(username=email, password="password")
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")
r = self.client.get("/about/")
self.assertContains(r, "Pricing")
@override_settings(USE_PAYMENTS=True)
def test_pricing_is_visible_for_team_owners(self):
self.client.login(username="[email protected]", password="password")
def test_it_offers_to_switch(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/about/")
self.assertContains(r, "Pricing")
r = self.client.get("/pricing/")
self.assertContains(r, "To manage this team")

+ 4
- 0
hc/payments/views.py View File

@ -28,6 +28,10 @@ def get_client_token(request):
def pricing(request):
if request.user.is_authenticated and request.profile != request.team:
ctx = {"page": "pricing"}
return render(request, "payments/pricing_not_owner.html", ctx)
sub = None
if request.user.is_authenticated:
# Don't use Subscription.objects.for_user method here, so a


+ 3
- 1
templates/payments/pricing.html View File

@ -264,7 +264,9 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4>Set Up Subscription</h4>
<h4>Set Up Subscription
<small>for {{ request.user.profile }}</small>
</h4>
</div>
<div class="modal-body">
<div id="payment-form"></div>


+ 35
- 0
templates/payments/pricing_not_owner.html View File

@ -0,0 +1,35 @@
{% extends "base.html" %}
{% load staticfiles compress %}
{% block title %}Pricing - healthchecks.io{% endblock %}
{% block content %}
<section id="plans">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="jumbotron">
<p>
You are currently viewing team <strong>{{ request.team }}</strong>.
</p>
<p>
To manage this team, please log in as <strong>{{ request.team.user.email }}</strong>.
</p>
<br />
<p>
<a class="btn btn-default"
href="{% url 'hc-switch-team' request.user.username %}">
Switch to {{ request.profile }}
</a>
<a class="btn btn-default" href="{% url 'hc-logout' %}">Log Out</a>
</p>
</div>
</div>
</div>
</div>
</section>
{% endblock %}

Loading…
Cancel
Save