Skip to content

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

Set site and member limits to unlimited for CE (#5288)

Adrian Gruntkowski1e17d54b5b2f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33ed25ae29..4f77a272a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,7 @@ All notable changes to this project will be documented in this file.
- Make Stats and Sites API keys scoped to teams they are created in
- Remove permissions to manage sites guests and run destructive actions from team editor and guest editor roles in favour of team admin role
- Time-on-page metric has been reworked. It now uses `engagement` events sent by plausible tracker script. We still use the old calculation methods for periods before the self-hosted instance was upgraded. Warnings are shown in the dashboard and API when legacy calculation methods are used.
+- Always set site and team member limits to unlimited for Community Edition
### Fixed
diff --git a/lib/plausible/teams/billing.ex b/lib/plausible/teams/billing.ex
index 4d1721c2e7..a99e3e1ff4 100644
--- a/lib/plausible/teams/billing.ex
+++ b/lib/plausible/teams/billing.ex
@@ -17,9 +17,7 @@ defmodule Plausible.Teams.Billing do
require Plausible.Billing.Subscription.Status
- @team_member_limit_for_trials 3
@limit_sites_since ~D[2021-05-05]
- @site_limit_for_trials 10
@type cycles_usage() :: %{cycle() => usage_cycle()}
@@ -193,16 +191,33 @@ defmodule Plausible.Teams.Billing do
end
end
- def site_limit(nil) do
- @site_limit_for_trials
- end
+ on_ee do
+ @site_limit_for_trials 10
- def site_limit(team) do
- if grandfathered_team?(team) do
- :unlimited
- else
- get_site_limit_from_plan(team)
+ def site_limit(nil) do
+ @site_limit_for_trials
end
+
+ def site_limit(team) do
+ if grandfathered_team?(team) do
+ :unlimited
+ else
+ get_site_limit_from_plan(team)
+ end
+ end
+
+ defp get_site_limit_from_plan(team) do
+ team =
+ Teams.with_subscription(team)
+
+ case Plans.get_subscription_plan(team.subscription) do
+ %{site_limit: site_limit} -> site_limit
+ :free_10k -> 50
+ nil -> @site_limit_for_trials
+ end
+ end
+ else
+ def site_limit(_team), do: :unlimited
end
@doc """
@@ -217,29 +232,24 @@ defmodule Plausible.Teams.Billing do
|> length()
end
- defp get_site_limit_from_plan(team) do
- team =
- Teams.with_subscription(team)
+ on_ee do
+ @team_member_limit_for_trials 3
- case Plans.get_subscription_plan(team.subscription) do
- %{site_limit: site_limit} -> site_limit
- :free_10k -> 50
- nil -> @site_limit_for_trials
+ def team_member_limit(nil) do
+ @team_member_limit_for_trials
end
- end
-
- def team_member_limit(nil) do
- @team_member_limit_for_trials
- end
- def team_member_limit(team) do
- team = Teams.with_subscription(team)
+ def team_member_limit(team) do
+ team = Teams.with_subscription(team)
- case Plans.get_subscription_plan(team.subscription) do
- %{team_member_limit: limit} -> limit
- :free_10k -> :unlimited
- nil -> @team_member_limit_for_trials
+ case Plans.get_subscription_plan(team.subscription) do
+ %{team_member_limit: limit} -> limit
+ :free_10k -> :unlimited
+ nil -> @team_member_limit_for_trials
+ end
end
+ else
+ def team_member_limit(_team), do: :unlimited
end
@doc """
diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exs
index a2e709769a..e455f521b9 100644
--- a/test/plausible/billing/quota_test.exs
+++ b/test/plausible/billing/quota_test.exs
@@ -16,7 +16,6 @@ defmodule Plausible.Billing.QuotaTest do
@v1_plan_id "558018"
@v2_plan_id "654177"
@v3_plan_id "749342"
- @v3_business_plan_id "857481"
@v4_1m_plan_id "857101"
@v4_10m_growth_plan_id "857104"
@v4_10m_business_plan_id "857112"
@@ -24,68 +23,70 @@ defmodule Plausible.Billing.QuotaTest do
@highest_growth_plan Plausible.Billing.Plans.find(@v4_10m_growth_plan_id)
@highest_business_plan Plausible.Billing.Plans.find(@v4_10m_business_plan_id)
- describe "site_limit/1" do
- @describetag :ee_only
+ on_ee do
+ @v3_business_plan_id "857481"
- test "returns 50 when user is on an old plan" do
- team_on_v1 = new_user() |> subscribe_to_plan(@v1_plan_id) |> team_of()
- team_on_v2 = new_user() |> subscribe_to_plan(@v2_plan_id) |> team_of()
- team_on_v3 = new_user() |> subscribe_to_plan(@v3_plan_id) |> team_of()
+ describe "site_limit/1" do
+ test "returns 50 when user is on an old plan" do
+ team_on_v1 = new_user() |> subscribe_to_plan(@v1_plan_id) |> team_of()
+ team_on_v2 = new_user() |> subscribe_to_plan(@v2_plan_id) |> team_of()
+ team_on_v3 = new_user() |> subscribe_to_plan(@v3_plan_id) |> team_of()
- assert 50 == Plausible.Teams.Billing.site_limit(team_on_v1)
- assert 50 == Plausible.Teams.Billing.site_limit(team_on_v2)
- assert 50 == Plausible.Teams.Billing.site_limit(team_on_v3)
- end
+ assert 50 == Plausible.Teams.Billing.site_limit(team_on_v1)
+ assert 50 == Plausible.Teams.Billing.site_limit(team_on_v2)
+ assert 50 == Plausible.Teams.Billing.site_limit(team_on_v3)
+ end
- test "returns 50 when user is on free_10k plan" do
- team = new_user() |> subscribe_to_plan("free_10k") |> team_of()
- assert 50 == Plausible.Teams.Billing.site_limit(team)
- end
+ test "returns 50 when user is on free_10k plan" do
+ team = new_user() |> subscribe_to_plan("free_10k") |> team_of()
+ assert 50 == Plausible.Teams.Billing.site_limit(team)
+ end
- test "returns the configured site limit for enterprise plan" do
- team = new_user() |> subscribe_to_enterprise_plan(site_limit: 500) |> team_of()
- assert Plausible.Teams.Billing.site_limit(team) == 500
- end
+ test "returns the configured site limit for enterprise plan" do
+ team = new_user() |> subscribe_to_enterprise_plan(site_limit: 500) |> team_of()
+ assert Plausible.Teams.Billing.site_limit(team) == 500
+ end
- test "returns 10 when user in on trial" do
- team = new_user(trial_expiry_date: Date.shift(Date.utc_today(), day: 7)) |> team_of()
- assert Plausible.Teams.Billing.site_limit(team) == 10
- end
+ test "returns 10 when user in on trial" do
+ team = new_user(trial_expiry_date: Date.shift(Date.utc_today(), day: 7)) |> team_of()
+ assert Plausible.Teams.Billing.site_limit(team) == 10
+ end
- test "returns the subscription limit for enterprise users who have not paid yet" do
- team =
- new_user()
- |> subscribe_to_plan(@v1_plan_id)
- |> subscribe_to_enterprise_plan(paddle_plan_id: "123321", subscription?: false)
- |> team_of()
+ test "returns the subscription limit for enterprise users who have not paid yet" do
+ team =
+ new_user()
+ |> subscribe_to_plan(@v1_plan_id)
+ |> subscribe_to_enterprise_plan(paddle_plan_id: "123321", subscription?: false)
+ |> team_of()
- assert Plausible.Teams.Billing.site_limit(team) == 50
- end
+ assert Plausible.Teams.Billing.site_limit(team) == 50
+ end
- test "returns 10 for enterprise users who have not upgraded yet and are on trial" do
- team =
- new_user()
- |> subscribe_to_enterprise_plan(paddle_plan_id: "123321", subscription?: false)
- |> team_of()
+ test "returns 10 for enterprise users who have not upgraded yet and are on trial" do
+ team =
+ new_user()
+ |> subscribe_to_enterprise_plan(paddle_plan_id: "123321", subscription?: false)
+ |> team_of()
- assert Plausible.Teams.Billing.site_limit(team) == 10
- end
+ assert Plausible.Teams.Billing.site_limit(team) == 10
+ end
- test "grandfathered site limit should be unlimited when accepting transfer invitations" do
- # must be before ~D[2021-05-05]
- owner = new_user(team: [inserted_at: ~N[2021-01-01 00:00:00]])
- # plan with site_limit: 10
- subscribe_to_plan(owner, "857097")
- _site = for _ <- 1..10, do: new_site(owner: owner)
+ test "grandfathered site limit should be unlimited when accepting transfer invitations" do
+ # must be before ~D[2021-05-05]
+ owner = new_user(team: [inserted_at: ~N[2021-01-01 00:00:00]])
+ # plan with site_limit: 10
+ subscribe_to_plan(owner, "857097")
+ _site = for _ <- 1..10, do: new_site(owner: owner)
- other_owner = new_user()
- other_site = new_site(owner: other_owner)
- invite_transfer(other_site, owner, inviter: other_owner)
+ other_owner = new_user()
+ other_site = new_site(owner: other_owner)
+ invite_transfer(other_site, owner, inviter: other_owner)
- team = owner |> team_of()
+ team = owner |> team_of()
- assert Plausible.Teams.Billing.site_limit(team) == :unlimited
- assert Plausible.Teams.Invitations.ensure_can_take_ownership(other_site, team) == :ok
+ assert Plausible.Teams.Billing.site_limit(team) == :unlimited
+ assert Plausible.Teams.Invitations.ensure_can_take_ownership(other_site, team) == :ok
+ end
end
end
@@ -419,51 +420,52 @@ defmodule Plausible.Billing.QuotaTest do
end
end
- describe "team_member_limit/1" do
- @describetag :ee_only
- test "returns unlimited when user is on an old plan" do
- team_on_v1 = new_user() |> subscribe_to_plan(@v1_plan_id) |> team_of()
- team_on_v2 = new_user() |> subscribe_to_plan(@v2_plan_id) |> team_of()
- team_on_v3 = new_user() |> subscribe_to_plan(@v3_plan_id) |> team_of()
+ on_ee do
+ describe "team_member_limit/1" do
+ test "returns unlimited when user is on an old plan" do
+ team_on_v1 = new_user() |> subscribe_to_plan(@v1_plan_id) |> team_of()
+ team_on_v2 = new_user() |> subscribe_to_plan(@v2_plan_id) |> team_of()
+ team_on_v3 = new_user() |> subscribe_to_plan(@v3_plan_id) |> team_of()
+
+ assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v1)
+ assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v2)
+ assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v3)
+ end
- assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v1)
- assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v2)
- assert :unlimited == Plausible.Teams.Billing.team_member_limit(team_on_v3)
- end
+ test "returns unlimited when user is on free_10k plan" do
+ user = new_user()
+ subscribe_to_plan(user, "free_10k")
+ team = team_of(user)
+ assert :unlimited == Plausible.Teams.Billing.team_member_limit(team)
+ end
- test "returns unlimited when user is on free_10k plan" do
- user = new_user()
- subscribe_to_plan(user, "free_10k")
- team = team_of(user)
- assert :unlimited == Plausible.Teams.Billing.team_member_limit(team)
- end
+ test "returns 5 when user in on trial" do
+ team = new_user(trial_expiry_date: Date.shift(Date.utc_today(), day: 7)) |> team_of()
- test "returns 5 when user in on trial" do
- team = new_user(trial_expiry_date: Date.shift(Date.utc_today(), day: 7)) |> team_of()
-
- assert 3 == Plausible.Teams.Billing.team_member_limit(team)
- end
+ assert 3 == Plausible.Teams.Billing.team_member_limit(team)
+ end
- test "returns the enterprise plan limit" do
- user = new_user()
- subscribe_to_enterprise_plan(user, team_member_limit: 27)
- team = team_of(user)
+ test "returns the enterprise plan limit" do
+ user = new_user()
+ subscribe_to_enterprise_plan(user, team_member_limit: 27)
+ team = team_of(user)
- assert 27 == Plausible.Teams.Billing.team_member_limit(team)
- end
+ assert 27 == Plausible.Teams.Billing.team_member_limit(team)
+ end
- test "reads from json file when the user is on a v4 plan" do
- team_on_growth = new_user() |> subscribe_to_growth_plan() |> team_of()
- team_on_business = new_user() |> subscribe_to_business_plan() |> team_of()
+ test "reads from json file when the user is on a v4 plan" do
+ team_on_growth = new_user() |> subscribe_to_growth_plan() |> team_of()
+ team_on_business = new_user() |> subscribe_to_business_plan() |> team_of()
- assert 3 == Plausible.Teams.Billing.team_member_limit(team_on_growth)
- assert 10 == Plausible.Teams.Billing.team_member_limit(team_on_business)
- end
+ assert 3 == Plausible.Teams.Billing.team_member_limit(team_on_growth)
+ assert 10 == Plausible.Teams.Billing.team_member_limit(team_on_business)
+ end
- test "returns unlimited when user is on a v3 business plan" do
- team = new_user() |> subscribe_to_plan(@v3_business_plan_id) |> team_of()
+ test "returns unlimited when user is on a v3 business plan" do
+ team = new_user() |> subscribe_to_plan(@v3_business_plan_id) |> team_of()
- assert :unlimited == Plausible.Teams.Billing.team_member_limit(team)
+ assert :unlimited == Plausible.Teams.Billing.team_member_limit(team)
+ end
end
end
diff --git a/test/plausible/teams/management/layout_test.exs b/test/plausible/teams/management/layout_test.exs
index c3599cfc37..982809359e 100644
--- a/test/plausible/teams/management/layout_test.exs
+++ b/test/plausible/teams/management/layout_test.exs
@@ -307,14 +307,16 @@ defmodule Plausible.Teams.Management.LayoutTest do
end
test "limits are checked", %{user: user, team: team} do
- assert {:error, {:over_limit, 3}} =
- team
- |> Layout.init()
- |> Layout.schedule_send("[email protected]", :admin)
- |> Layout.schedule_send("[email protected]", :admin)
- |> Layout.schedule_send("[email protected]", :admin)
- |> Layout.schedule_send("[email protected]", :admin)
- |> Layout.persist(%{current_user: user, current_team: team})
+ on_ee do
+ assert {:error, {:over_limit, 3}} =
+ team
+ |> Layout.init()
+ |> Layout.schedule_send("[email protected]", :admin)
+ |> Layout.schedule_send("[email protected]", :admin)
+ |> Layout.schedule_send("[email protected]", :admin)
+ |> Layout.schedule_send("[email protected]", :admin)
+ |> Layout.persist(%{current_user: user, current_team: team})
+ end
assert {:error, :only_one_owner} =
team
diff --git a/test/plausible_web/live/team_management_test.exs b/test/plausible_web/live/team_management_test.exs
index 8788efd878..d8432800cf 100644
--- a/test/plausible_web/live/team_management_test.exs
+++ b/test/plausible_web/live/team_management_test.exs
@@ -121,6 +121,7 @@ defmodule PlausibleWeb.Live.TeamMangementTest do
refute element_exists?(html, "#guest-list")
end
+ @tag :ee_only
test "fails to save layout with limits breached", %{conn: conn, team: team} do
lv = get_liveview(conn)
add_invite(lv, "[email protected]", "admin")
@@ -143,7 +144,8 @@ defmodule PlausibleWeb.Live.TeamMangementTest do
"Error! Make sure the e-mail is valid and is not taken already"
end
- test "allows removing any type of entry", %{
+ @tag :ee_only
+ test "allows removing any type of entry (EE)", %{
conn: conn,
user: user,
team: team
@@ -214,6 +216,72 @@ defmodule PlausibleWeb.Live.TeamMangementTest do
assert_no_emails_delivered()
end
+ @tag :ce_only
+ test "allows removing any type of entry (CE)", %{
+ conn: conn,
+ user: user,
+ team: team
+ } do
+ member2 = add_member(team, role: :admin)
+ _invitation = invite_member(team, "[email protected]", inviter: user, role: :viewer)
+
+ site = new_site(team: team)
+
+ guest =
+ add_guest(site,
+ role: :viewer,
+ user: new_user(name: "Mr Guest", email: "[email protected]")
+ )
+
+ lv = get_liveview(conn)
+
+ html = render(lv)
+
+ assert html |> find(member_el()) |> Enum.count() == 3
+ assert html |> find(guest_el()) |> Enum.count() == 1
+
+ sent = find(html, "#{member_el()}:nth-of-type(1)") |> text()
+ owner = find(html, "#{member_el()}:nth-of-type(2)") |> text()
+ admin = find(html, "#{member_el()}:nth-of-type(3)") |> text()
+
+ guest_member = find(html, "#{guest_el()}:first-of-type") |> text()
+
+ assert sent =~ "Invitation Sent"
+ assert owner =~ "You"
+ assert admin =~ "Team Member"
+ assert guest_member =~ "Guest"
+
+ remove_member(lv, 1)
+ # last becomes second
+ remove_member(lv, 2)
+
+ # remove guest
+ remove_member(lv, 1, guest_el())
+
+ html = render(lv) |> text()
+
+ refute html =~ "Invitation Sent"
+ refute html =~ "Team Member"
+ refute html =~ "Guest"
+
+ html = render(lv)
+
+ assert html |> find(member_el()) |> Enum.count() == 1
+ refute element_exists?(html, "#guest-list")
+
+ assert_email_delivered_with(
+ to: [nil: member2.email],
+ subject: @subject_prefix <> "Your access to \"#{team.name}\" team has been revoked"
+ )
+
+ assert_email_delivered_with(
+ to: [nil: guest.email],
+ subject: @subject_prefix <> "Your access to \"#{team.name}\" team has been revoked"
+ )
+
+ assert_no_emails_delivered()
+ end
+
test "guest->owner promotion",
%{
conn: conn,
diff --git a/test/plausible_web/live/team_setup_test.exs b/test/plausible_web/live/team_setup_test.exs
index f4492d72d6..0b96ddea5c 100644
--- a/test/plausible_web/live/team_setup_test.exs
+++ b/test/plausible_web/live/team_setup_test.exs
@@ -199,6 +199,7 @@ defmodule PlausibleWeb.Live.TeamSetupTest do
)
end
+ @tag :ee_only
test "fails to save layout with limits breached", %{conn: conn} do
lv = get_child_lv(conn)
html = render(lv)