mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
Fix site locked email
This commit is contained in:
parent
ecdf04726b
commit
a2d0244315
@ -18,6 +18,8 @@ config :plausible,
|
||||
paddle_api: Plausible.PaddleApi.Mock,
|
||||
google_api: Plausible.Google.Api.Mock
|
||||
|
||||
config :bamboo, :refute_timeout, 10
|
||||
|
||||
config :geolix,
|
||||
databases: [
|
||||
%{
|
||||
|
@ -10,6 +10,7 @@ defmodule Plausible.Auth.GracePeriod do
|
||||
embedded_schema do
|
||||
field :end_date, :date
|
||||
field :allowance_required, :integer
|
||||
field :is_over, :boolean
|
||||
end
|
||||
end
|
||||
|
||||
@ -92,12 +93,17 @@ defmodule Plausible.Auth.User do
|
||||
def start_grace_period(user, allowance_required) do
|
||||
grace_period = %Plausible.Auth.GracePeriod{
|
||||
end_date: Timex.today() |> Timex.shift(days: 7),
|
||||
allowance_required: allowance_required
|
||||
allowance_required: allowance_required,
|
||||
is_over: false
|
||||
}
|
||||
|
||||
change(user, grace_period: grace_period)
|
||||
end
|
||||
|
||||
def end_grace_period(user) do
|
||||
change(user, grace_period: %{is_over: true})
|
||||
end
|
||||
|
||||
def remove_grace_period(user) do
|
||||
change(user, grace_period: nil)
|
||||
end
|
||||
|
@ -5,7 +5,11 @@ defmodule Plausible.Billing.SiteLocker do
|
||||
case Plausible.Billing.needs_to_upgrade?(user) do
|
||||
{true, :grace_period_ended} ->
|
||||
set_lock_status_for(user, true)
|
||||
send_grace_period_end_email(user)
|
||||
|
||||
if !user.grace_period.is_over do
|
||||
send_grace_period_end_email(user)
|
||||
Plausible.Auth.User.end_grace_period(user) |> Repo.update()
|
||||
end
|
||||
|
||||
{true, _} ->
|
||||
set_lock_status_for(user, true)
|
||||
@ -36,7 +40,7 @@ defmodule Plausible.Billing.SiteLocker do
|
||||
defp send_grace_period_end_email(user) do
|
||||
{_, last_cycle} = Plausible.Billing.last_two_billing_cycles(user)
|
||||
{_, last_cycle_usage} = Plausible.Billing.last_two_billing_months_usage(user)
|
||||
suggested_plan = Plausible.Billing.Plans.suggested_plan(user, last_cycle)
|
||||
suggested_plan = Plausible.Billing.Plans.suggested_plan(user, last_cycle_usage)
|
||||
|
||||
template =
|
||||
PlausibleWeb.Email.dashboard_locked(
|
||||
|
@ -124,6 +124,33 @@ defmodule Plausible.Billing.SiteLockerTest do
|
||||
)
|
||||
end
|
||||
|
||||
test "does not send grace period email if site is already locked" do
|
||||
user =
|
||||
insert(:user,
|
||||
grace_period: %Plausible.Auth.GracePeriod{
|
||||
end_date: Timex.shift(Timex.today(), days: -1),
|
||||
allowance_required: 10_000,
|
||||
is_over: false
|
||||
}
|
||||
)
|
||||
|
||||
insert(:subscription, status: "active", user: user)
|
||||
user = Repo.preload(user, :subscription)
|
||||
insert(:site, members: [user])
|
||||
|
||||
SiteLocker.check_sites_for(user)
|
||||
|
||||
assert_email_delivered_with(
|
||||
to: [user],
|
||||
subject: "[Action required] Your Plausible dashboard is now locked"
|
||||
)
|
||||
|
||||
user = Repo.reload!(user) |> Repo.preload(:subscription)
|
||||
SiteLocker.check_sites_for(user)
|
||||
|
||||
assert_no_emails_delivered()
|
||||
end
|
||||
|
||||
test "locks all sites if user has no trial or active subscription" do
|
||||
user =
|
||||
insert(:user, trial_expiry_date: Timex.today() |> Timex.shift(days: -1))
|
||||
|
Loading…
Reference in New Issue
Block a user