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

This commit is contained in:
Pēteris Caune 2017-10-18 18:00:45 +03:00
parent 888d7a1f9c
commit 6a57bcfdf3
5 changed files with 52 additions and 22 deletions

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}

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 ("alice@example.org", "bob@example.org"):
self.client.login(username=email, password="password")
r = self.client.get("/about/")
self.assertContains(r, "Pricing")
def test_it_offers_to_switch(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")
@override_settings(USE_PAYMENTS=True)
def test_pricing_is_visible_for_team_owners(self):
self.client.login(username="alice@example.org", password="password")
r = self.client.get("/about/")
self.assertContains(r, "Pricing")
r = self.client.get("/pricing/")
self.assertContains(r, "To manage this team")

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

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>

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 %}