Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Unlock team right after trial dates are saved in CS admin (#6757)

Marko Saric03b318a97c7b
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/overview.ex b/extra/lib/plausible_web/live/customer_support/team/components/overview.ex
index 98a738c95c..2b61ce988c 100644
--- a/extra/lib/plausible_web/live/customer_support/team/components/overview.ex
+++ b/extra/lib/plausible_web/live/customer_support/team/components/overview.ex
@@ -154,8 +154,10 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Overview do
case Plausible.Repo.update(changeset) do
{:ok, team} ->
# Prolonging trial_expiry_date (or otherwise making the team
- # eligible again) cancels any pending deletion schedule.
+ # eligible again) cancels any pending deletion schedule and
+ # unlocks the team without waiting for the nightly lock check.
TeamDeletionSchedules.cancel_for_team(team)
+ Plausible.Billing.SiteLocker.update_for(team)
schedule = TeamDeletionSchedules.active_schedule_for_team(team)
success("Team saved")
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index ea6cdb8672..8216d120c2 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -172,9 +172,11 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
assert text(html) =~ "Deletion scheduled"
+ future_date = Date.utc_today() |> Date.add(30) |> Date.to_iso8601()
+
lv
|> element(~s|form[phx-submit="save-team"]|)
- |> render_submit(%{"team" => %{"trial_expiry_date" => "2029-01-01"}})
+ |> render_submit(%{"team" => %{"trial_expiry_date" => future_date}})
html = render(lv)
refute text(html) =~ "Deletion scheduled"
@@ -182,6 +184,27 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
assert Plausible.Repo.reload!(schedule).status == :cancelled
end
+ test "prolonging an expired trial unlocks the team straight away", %{conn: conn, user: user} do
+ team =
+ user
+ |> team_of()
+ |> Ecto.Changeset.change(trial_expiry_date: Date.shift(Date.utc_today(), day: -10))
+ |> Plausible.Repo.update!()
+
+ Plausible.Billing.SiteLocker.update_for(team, send_email?: false)
+ assert Plausible.Repo.reload!(team).locked
+
+ {:ok, lv, _html} = live(conn, open_team(team.id))
+
+ future_date = Date.utc_today() |> Date.add(30) |> Date.to_iso8601()
+
+ lv
+ |> element(~s|form[phx-submit="save-team"]|)
+ |> render_submit(%{"team" => %{"trial_expiry_date" => future_date}})
+
+ refute Plausible.Repo.reload!(team).locked
+ end
+
test "404", %{conn: conn} do
assert_raise Ecto.NoResultsError, fn ->
{:ok, _lv, _html} = live(conn, open_team(9999))