mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Fix SiteLocker for case of user without trial expiry date but with active subscription (#3652)
This commit is contained in:
parent
d2270f3c35
commit
66d4b3a966
@ -92,16 +92,13 @@ defmodule Plausible.Billing do
|
||||
@spec check_needs_to_upgrade(User.t()) ::
|
||||
{:needs_to_upgrade, :no_trial | :no_active_subscription | :grace_period_ended}
|
||||
| :no_upgrade_needed
|
||||
def check_needs_to_upgrade(%User{trial_expiry_date: nil}) do
|
||||
{:needs_to_upgrade, :no_trial}
|
||||
end
|
||||
|
||||
def check_needs_to_upgrade(user) do
|
||||
user = Plausible.Users.with_subscription(user)
|
||||
trial_is_over = Timex.before?(user.trial_expiry_date, Timex.today())
|
||||
trial_is_over = user.trial_expiry_date && Timex.before?(user.trial_expiry_date, Timex.today())
|
||||
subscription_active = subscription_is_active?(user.subscription)
|
||||
|
||||
cond do
|
||||
!user.trial_expiry_date && !subscription_active -> {:needs_to_upgrade, :no_trial}
|
||||
trial_is_over && !subscription_active -> {:needs_to_upgrade, :no_active_subscription}
|
||||
Plausible.Auth.GracePeriod.expired?(user) -> {:needs_to_upgrade, :grace_period_ended}
|
||||
true -> :no_upgrade_needed
|
||||
|
@ -58,6 +58,13 @@ defmodule Plausible.BillingTest do
|
||||
assert Billing.check_needs_to_upgrade(user) == {:needs_to_upgrade, :no_trial}
|
||||
end
|
||||
|
||||
test "is false for user with empty trial expiry date but with an active subscription" do
|
||||
user = insert(:user, trial_expiry_date: nil)
|
||||
insert(:subscription, user: user)
|
||||
|
||||
assert Billing.check_needs_to_upgrade(user) == :no_upgrade_needed
|
||||
end
|
||||
|
||||
test "is false for a user with an expired trial but an active subscription" do
|
||||
user = insert(:user, trial_expiry_date: Timex.shift(Timex.today(), days: -1))
|
||||
insert(:subscription, user: user)
|
||||
|
Loading…
Reference in New Issue
Block a user