Browse Source

Don't use request.project in the pricing page cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
9c3f7101db
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 40 additions and 25 deletions
  1. +15
    -12
      hc/payments/tests/test_pricing.py
  2. +1
    -0
      hc/payments/urls.py
  3. +17
    -8
      hc/payments/views.py
  4. +4
    -0
      templates/base.html
  5. +1
    -3
      templates/payments/pricing.html
  6. +2
    -2
      templates/payments/pricing_not_owner.html

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

@ -8,18 +8,27 @@ class PricingTestCase(BaseTestCase):
def test_anonymous(self): def test_anonymous(self):
r = self.client.get("/pricing/") r = self.client.get("/pricing/")
self.assertContains(r, "Unlimited Team Members", status_code=200) self.assertContains(r, "Unlimited Team Members", status_code=200)
self.assertNotContains(r, "jumbotron")
# A subscription object should have NOT been created # A subscription object should have NOT been created
assert Subscription.objects.count() == 0
self.assertFalse(Subscription.objects.exists())
def test_authenticated(self): def test_authenticated(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/pricing/") r = self.client.get("/pricing/")
self.assertContains(r, "Unlimited Team Members", status_code=200) self.assertContains(r, "Unlimited Team Members", status_code=200)
self.assertContains(r, "jumbotron")
# A subscription object still should have NOT been created # A subscription object still should have NOT been created
assert Subscription.objects.count() == 0
self.assertFalse(Subscription.objects.exists())
def test_authenticated_for_project(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/projects/%s/pricing/" % self.project.code)
self.assertContains(r, "Unlimited Team Members", status_code=200)
self.assertContains(r, "jumbotron")
@override_settings(USE_PAYMENTS=True) @override_settings(USE_PAYMENTS=True)
def test_pricing_is_visible_for_all(self): def test_pricing_is_visible_for_all(self):
@ -32,18 +41,9 @@ class PricingTestCase(BaseTestCase):
def test_it_offers_to_switch(self): def test_it_offers_to_switch(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/pricing/")
r = self.client.get("/projects/%s/pricing/" % self.project.code)
self.assertContains(r, "To manage billing for this project") self.assertContains(r, "To manage billing for this project")
def test_it_handles_null_project(self):
self.profile.current_project = None
self.profile.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/pricing/")
self.assertContains(r, "Unlimited Team Members")
def test_it_shows_active_plan(self): def test_it_shows_active_plan(self):
self.sub = Subscription(user=self.alice) self.sub = Subscription(user=self.alice)
self.sub.subscription_id = "test-id" self.sub.subscription_id = "test-id"
@ -55,3 +55,6 @@ class PricingTestCase(BaseTestCase):
r = self.client.get("/pricing/") r = self.client.get("/pricing/")
self.assertContains(r, "Business ($20 / month)", status_code=200) self.assertContains(r, "Business ($20 / month)", status_code=200)
r = self.client.get("/projects/%s/pricing/" % self.project.code)
self.assertContains(r, "Business ($20 / month)", status_code=200)

+ 1
- 0
hc/payments/urls.py View File

@ -3,6 +3,7 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("projects/<uuid:code>/pricing/", views.pricing, name="hc-p-pricing"),
path("pricing/", views.pricing, name="hc-pricing"), path("pricing/", views.pricing, name="hc-pricing"),
path("accounts/profile/billing/", views.billing, name="hc-billing"), path("accounts/profile/billing/", views.billing, name="hc-billing"),
path( path(


+ 17
- 8
hc/payments/views.py View File

@ -1,10 +1,11 @@
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, JsonResponse
from django.http import Http404, HttpResponseBadRequest, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from hc.api.models import Check from hc.api.models import Check
from hc.front.views import _get_project_for_user
from hc.payments.forms import InvoiceEmailingForm from hc.payments.forms import InvoiceEmailingForm
from hc.payments.models import Subscription from hc.payments.models import Subscription
@ -15,18 +16,26 @@ def token(request):
return JsonResponse({"client_token": sub.get_client_token()}) return JsonResponse({"client_token": sub.get_client_token()})
def pricing(request):
if request.user.is_authenticated:
if request.project and request.project.owner != request.user:
ctx = {"page": "pricing"}
def pricing(request, code=None):
project = None
if code:
if not request.user.is_authenticated:
raise Http404()
project = _get_project_for_user(request, code)
if project.owner != request.user:
ctx = {"page": "pricing", "project": project}
return render(request, "payments/pricing_not_owner.html", ctx) return render(request, "payments/pricing_not_owner.html", ctx)
# Don't use Subscription.objects.for_user method here, so a
# subscription object is not created just by viewing a page.
sub = Subscription.objects.filter(user_id=request.user.id).first()
sub = None
if request.user.is_authenticated:
# Don't use Subscription.objects.for_user method here, so a
# subscription object is not created just by viewing a page.
sub = Subscription.objects.filter(user_id=request.user.id).first()
ctx = { ctx = {
"page": "pricing", "page": "pricing",
"project": project,
"sub": sub, "sub": sub,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP, "enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
} }


+ 4
- 0
templates/base.html View File

@ -119,7 +119,11 @@
<ul id="global-links" class="nav navbar-nav navbar-right"> <ul id="global-links" class="nav navbar-nav navbar-right">
{% if show_pricing %} {% if show_pricing %}
<li {% if page == 'pricing' %} class="active" {% endif %}> <li {% if page == 'pricing' %} class="active" {% endif %}>
{% if project %}
<a href="{% url 'hc-p-pricing' project.code %}">Pricing</a>
{% else %}
<a href="{% url 'hc-pricing' %}">Pricing</a> <a href="{% url 'hc-pricing' %}">Pricing</a>
{% endif %}
</li> </li>
{% endif %} {% endif %}


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

@ -12,9 +12,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<!-- Plans -->
<section id="plans" {% if request.user.is_authenticated %} data- {% endif %}>
<section id="plans">
<div class="container"> <div class="container">
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<div class="row"> <div class="row">


+ 2
- 2
templates/payments/pricing_not_owner.html View File

@ -11,10 +11,10 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="jumbotron"> <div class="jumbotron">
<p> <p>
You are currently viewing project <strong>{{ request.project }}</strong>.
You are currently viewing project <strong>{{ project }}</strong>.
</p> </p>
<p> <p>
To manage billing for this project, please log in as <strong>{{ request.project.owner.email }}</strong>.
To manage billing for this project, please log in as <strong>{{ project.owner.email }}</strong>.
</p> </p>
<br /> <br />


Loading…
Cancel
Save