Skip to content

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

Team provisioning tweaks (#5155)

hq1aa9128915380
diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex
index 7e989ba60e..a1a21509cd 100644
--- a/lib/plausible_web/controllers/auth_controller.ex
+++ b/lib/plausible_web/controllers/auth_controller.ex
@@ -98,10 +98,6 @@ defmodule PlausibleWeb.AuthController do
{:ok, role} when role != :guest ->
conn
|> put_session("current_team_id", team.identifier)
- |> put_flash(
- :success,
- "You have switched to \"#{conn.assigns.current_team.name}\" team"
- )
|> redirect(to: Routes.site_path(conn, :index))
_ ->
diff --git a/lib/plausible_web/live/team_management.ex b/lib/plausible_web/live/team_management.ex
index 0dd1ce1dfc..e377aab0dd 100644
--- a/lib/plausible_web/live/team_management.ex
+++ b/lib/plausible_web/live/team_management.ex
@@ -31,7 +31,6 @@ defmodule PlausibleWeb.Live.TeamManagement do
team_members_limit = Plausible.Teams.Billing.team_member_limit(my_team)
assign(socket,
- attempted_save?: false,
team_members_limit: team_members_limit,
layout: layout,
my_role: my_role,
@@ -47,13 +46,7 @@ defmodule PlausibleWeb.Live.TeamManagement do
<.flash_messages flash={@flash} />
<PlausibleWeb.Components.Billing.Notice.limit_exceeded
- :if={
- (not @team_layout_changed? or @attempted_save?) and
- not Plausible.Billing.Quota.below_limit?(
- Layout.active_count(@layout) - 1,
- @team_members_limit
- )
- }
+ :if={at_limit?(@layout, @team_members_limit)}
current_user={@current_user}
billable_user={@current_user}
current_team={@my_team}
@@ -71,6 +64,7 @@ defmodule PlausibleWeb.Live.TeamManagement do
value={@input_email}
placeholder="Enter e-mail to send invitation to"
phx-debounce={200}
+ readonly={at_limit?(@layout, @team_members_limit)}
mt?={false}
/>
</div>
@@ -115,7 +109,12 @@ defmodule PlausibleWeb.Live.TeamManagement do
</:menu>
</.dropdown>
- <.button id="invite-member" type="submit" mt?={false}>
+ <.button
+ id="invite-member"
+ type="submit"
+ mt?={false}
+ disabled={at_limit?(@layout, @team_members_limit)}
+ >
Invite
</.button>
</div>
@@ -287,8 +286,6 @@ defmodule PlausibleWeb.Live.TeamManagement do
) do
result = Layout.persist(layout, %{current_user: current_user, my_team: my_team})
- socket = assign(socket, attempted_save?: true)
-
case {result, socket.assigns.mode} do
{{:ok, _}, :team_setup} ->
socket
@@ -296,9 +293,7 @@ defmodule PlausibleWeb.Live.TeamManagement do
|> redirect(to: Routes.settings_path(socket, :team_general))
{{:ok, _}, :team_management} ->
- socket
- |> reset()
- |> put_live_flash(:success, "Team layout updated successfully")
+ reset(socket)
{{:error, :only_one_owner}, _} ->
socket
@@ -321,4 +316,11 @@ defmodule PlausibleWeb.Live.TeamManagement do
defp entry_label(%Layout.Entry{type: :invitation_sent}, _), do: "Invitation Sent"
defp entry_label(%Layout.Entry{meta: %{user: %{id: id}}}, %{id: id}), do: "You"
defp entry_label(_, _), do: "Team Member"
+
+ def at_limit?(layout, limit) do
+ not Plausible.Billing.Quota.below_limit?(
+ Layout.active_count(layout) - 1,
+ limit
+ )
+ end
end
diff --git a/test/plausible_web/live/team_setup_test.exs b/test/plausible_web/live/team_setup_test.exs
index f1726b21b7..195a924792 100644
--- a/test/plausible_web/live/team_setup_test.exs
+++ b/test/plausible_web/live/team_setup_test.exs
@@ -151,16 +151,20 @@ defmodule PlausibleWeb.Live.TeamSetupTest do
test "fails to save layout with limits breached", %{conn: conn} do
lv = get_child_lv(conn)
+ html = render(lv)
+ refute attr_defined?(html, ~s|#team-layout-form input[name="input-email"]|, "readonly")
+ refute attr_defined?(html, ~s|#invite-member|, "disabled")
+
add_invite(lv, "[email protected]", "admin")
add_invite(lv, "[email protected]", "admin")
add_invite(lv, "[email protected]", "admin")
add_invite(lv, "[email protected]", "admin")
- refute lv |> render() |> text() =~ "Your account is limited to 3 team members"
-
- save_layout(lv)
+ html = render(lv)
- assert lv |> render() |> text() =~ "Your account is limited to 3 team members"
+ assert attr_defined?(html, ~s|#team-layout-form input[name="input-email"]|, "readonly")
+ assert attr_defined?(html, ~s|#invite-member|, "disabled")
+ assert text(html) =~ "Your account is limited to 3 team members"
end
test "all options are disabled for the sole owner", %{conn: conn} do
diff --git a/test/support/html.ex b/test/support/html.ex
index 313cb128d9..392573681c 100644
--- a/test/support/html.ex
+++ b/test/support/html.ex
@@ -45,6 +45,16 @@ defmodule Plausible.Test.Support.HTML do
|> String.replace(~r/\s+/, " ")
end
+ def attr_defined?(html, element, attr) do
+ empty? =
+ html
+ |> find(element)
+ |> Floki.attribute(attr)
+ |> Enum.empty?()
+
+ not empty?
+ end
+
def class_of_element(html, element) do
html
|> find(element)