Skip to content

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

fix bug (#6808)

RobertJoonasbd53ef9ad5da
diff --git a/lib/plausible_web/live/components/team.ex b/lib/plausible_web/live/components/team.ex
index 442743da61..4cddbc3c4c 100644
--- a/lib/plausible_web/live/components/team.ex
+++ b/lib/plausible_web/live/components/team.ex
@@ -111,11 +111,26 @@ defmodule PlausibleWeb.Live.Components.Team do
attr(:me?, :boolean, default: false)
attr(:disabled, :boolean, default: false)
+ @doc """
+ Component for updating the role of a team member, invitation, or guest.
+ Wraps a PrimaListbox inside its own `<form>`. Submission works via
+ phx-change instead of a regular submit.
+
+ Hence the `phx-auto-recover="ignore"` on the wrapper form -- there's no
+ state to recover, and without explicitly ignoring auto-recover, we would
+ end up triggering a `handle_event("update-role")` even for disabled
+ listboxes and flashing success messages about having updated all roles
+ when the LiveView reconnects.
+ """
def role_switcher(assigns) do
assigns = assign(assigns, :change, role_change(assigns.user, assigns.role))
~H"""
- <form id={"role-form-#{:erlang.phash2(@user.email)}"} phx-change={@change}>
+ <form
+ id={"role-form-#{:erlang.phash2(@user.email)}"}
+ phx-change={@change}
+ phx-auto-recover="ignore"
+ >
<input type="hidden" name="email" value={@user.email} />
<PrimaListbox.listbox id={@id} name="role" value={@role} disabled={@disabled}>
diff --git a/test/plausible_web/live/team_management_test.exs b/test/plausible_web/live/team_management_test.exs
index b82f63c43d..902c8871f2 100644
--- a/test/plausible_web/live/team_management_test.exs
+++ b/test/plausible_web/live/team_management_test.exs
@@ -37,6 +37,24 @@ defmodule PlausibleWeb.Live.TeamMangementTest do
assert find(resp, "#{guest_el()}:first-of-type") |> text() =~ "[email protected]"
end
+ test "role switcher forms opt out of automatic recovery after a reconnect", %{
+ conn: conn,
+ team: team,
+ user: user
+ } do
+ site = new_site(team: team)
+ add_member(team, role: :viewer)
+ invite_member(team, "[email protected]", role: :editor, inviter: user)
+ add_guest(site, role: :viewer, user: new_user(email: "[email protected]"))
+
+ resp =
+ conn
+ |> get(team_general_path())
+ |> html_response(200)
+
+ assert elem_count(resp, ~s|form[id^="role-form-"][phx-auto-recover="ignore"]|) == 4
+ end
+
test "disables changing the role of a pending guest invitation, but not removing it", %{
conn: conn,
team: team,