Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Show message when grace period is over
Uku Tahtd3311898c59f
diff --git a/assets/package-lock.json b/assets/package-lock.jsonindex 2db912dcb9..11781af6cf 100644--- a/assets/package-lock.json+++ b/assets/package-lock.json@@ -1,9 +1,11 @@{"name": "assets",+ "version": "1.4.0","lockfileVersion": 2,"requires": true,"packages": {"": {+ "version": "1.4.0","license": "MIT","dependencies": {"@babel/core": "^7.14.3",@@ -62,11 +64,11 @@}},"../deps/phoenix": {- "version": "1.4.17",+ "version": "1.5.13","license": "MIT"},"../deps/phoenix_html": {- "version": "2.14.2"+ "version": "2.14.3"},"node_modules/@babel/code-frame": {"version": "7.12.13",diff --git a/lib/plausible_web/templates/layout/_notice.html.eex b/lib/plausible_web/templates/layout/_notice.html.eexindex 069c9d215f..1572644f44 100644--- a/lib/plausible_web/templates/layout/_notice.html.eex+++ b/lib/plausible_web/templates/layout/_notice.html.eex@@ -2,6 +2,55 @@<%= render("_flash.html", assigns) %><% end %>++<%= if on_grace_period?(@conn.assigns[:current_user]) do %>+ <div class="container">+ <div class="rounded-md bg-yellow-100 p-4">+ <div class="flex">+ <div class="flex-shrink-0">+ <svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">+ <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />+ </svg>+ </div>+ <div class="ml-3">+ <h3 class="text-sm font-medium text-yellow-800">+ Please upgrade your account+ </h3>+ <div class="mt-2 text-sm text-yellow-700">+ <p>+ In order to keep your stats running, we require you to upgrade your account. If you do not upgrade your account <%= grace_period_end(@conn.assigns[:current_user]) %>, we will lock your sites and they won't be accessible. <%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>+ </p>+ </div>+ </div>+ </div>+ </div>+ </div>+<% end %>++<%= if grace_period_over?(@conn.assigns[:current_user]) do %>+ <div class="container">+ <div class="rounded-md bg-yellow-100 p-4">+ <div class="flex">+ <div class="flex-shrink-0">+ <svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">+ <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />+ </svg>+ </div>+ <div class="ml-3">+ <h3 class="text-sm font-medium text-yellow-800">+ Dashboard locked+ </h3>+ <div class="mt-2 text-sm text-yellow-700">+ <p>+ As you have outgrown your subscription tier, we kindly ask you to upgrade your subscription to accommodate your new traffic levels. <%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>+ </p>+ </div>+ </div>+ </div>+ </div>+ </div>+<% end %>+<%= if @conn.assigns[:current_user] && @conn.assigns[:current_user].subscription && @conn.assigns[:current_user].subscription.status == "past_due" do %><div class="container"><div class="p-2 bg-yellow-100 rounded-lg sm:p-3">diff --git a/lib/plausible_web/templates/site/index.html.eex b/lib/plausible_web/templates/site/index.html.eexindex 0fab8fbf14..79fd51ffdd 100644--- a/lib/plausible_web/templates/site/index.html.eex+++ b/lib/plausible_web/templates/site/index.html.eex@@ -1,6 +1,6 @@<div x-data="{selectedInvitation: null, invitationOpen: false, invitations: <%= Enum.map(@invitations, &({&1.invitation_id, &1})) |> Enum.into(%{}) |> Jason.encode! %>}" @keydown.escape.window="invitationOpen = false" class="container pt-6">- <%= if @needs_to_upgrade do %>+ <%= if @needs_to_upgrade == {true, :no_active_subscription} do %><div class="rounded-md bg-yellow-100 p-4"><div class="flex"><div class="flex-shrink-0">diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 6cad0c241c..ec2bb57dae 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -55,6 +55,26 @@ defmodule PlausibleWeb.LayoutView doendend+ def on_grace_period?(user) do+ user.grace_period &&+ Timex.diff(user.grace_period.end_date, Timex.today(), :days) >= 0+ end++ def grace_period_over?(user) do+ user.grace_period &&+ Timex.diff(user.grace_period.end_date, Timex.today(), :days) < 0+ end++ def grace_period_end(user) do+ end_date = user.grace_period.end_date++ case Timex.diff(end_date, Timex.today(), :days) do+ 0 -> "today"+ 1 -> "tomorrow"+ n -> "within #{n} days"+ end+ end+@doc "http://blog.plataformatec.com.br/2018/05/nested-layouts-with-phoenix/"def render_layout(layout, assigns, do: content) dorender(layout, Map.put(assigns, :inner_layout, content))diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.exindex ca0193025f..4bdf864b90 100644--- a/lib/workers/check_usage.ex+++ b/lib/workers/check_usage.ex@@ -104,13 +104,13 @@ defmodule Plausible.Workers.CheckUsage doenddefp check_pageview_limit(subscriber, billing_mod) do- allowance = Plausible.Billing.Plans.allowance(subscriber.subscription)+ allowance = Plausible.Billing.Plans.allowance(subscriber.subscription) * 1.1{_, last_cycle} = billing_mod.last_two_billing_cycles(subscriber){last_last_cycle_usage, last_cycle_usage} =billing_mod.last_two_billing_months_usage(subscriber)- if last_last_cycle_usage > allowance && last_cycle_usage > allowance do+ if last_last_cycle_usage >= allowance && last_cycle_usage >= allowance do{:over_limit, {last_cycle, last_cycle_usage}}else{:within_limit, {last_cycle, last_cycle_usage}}diff --git a/test/workers/check_usage_test.exs b/test/workers/check_usage_test.exsindex 3dc6418576..73bdbbf523 100644--- a/test/workers/check_usage_test.exs+++ b/test/workers/check_usage_test.exs@@ -49,6 +49,28 @@ defmodule Plausible.Workers.CheckUsageTest doassert Repo.reload(user).grace_period == nilend+ test "does not send an email if account is over the limit by less than 10%", %{+ user: user+ } do+ billing_stub =+ Plausible.Billing+ |> stub(:last_two_billing_cycles, fn _user ->+ {Date.range(Timex.today(), Timex.today()), Date.range(Timex.today(), Timex.today())}+ end)+ |> stub(:last_two_billing_months_usage, fn _user -> {10_999, 11_000} end)++ insert(:subscription,+ user: user,+ paddle_plan_id: @paddle_id_10k,+ last_bill_date: Timex.shift(Timex.today(), days: -1)+ )++ CheckUsage.perform(nil, billing_stub)++ assert_no_emails_delivered()+ assert Repo.reload(user).grace_period == nil+ end+test "sends an email when an account is over their limit for two consecutive billing months", %{user: user} do