Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
CRM: add ability to deprovision individual users (#5537)
Adam Rutkowski528693889d1b
diff --git a/extra/lib/plausible_web/live/customer_support/live/team.ex b/extra/lib/plausible_web/live/customer_support/live/team.exindex b3ba446607..d86acd5ffa 100644--- a/extra/lib/plausible_web/live/customer_support/live/team.ex+++ b/extra/lib/plausible_web/live/customer_support/live/team.ex@@ -570,7 +570,20 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team do</div></.td><.td>- {member.type}+ <div class="flex items-center gap-x-1">+ <span :if={member.meta.user.type == :sso}>SSO </span>{member.type}++ <.delete_button+ :if={member.meta.user.type == :sso}+ id={"deprovision-user-#{member.id}"}+ phx-click="deprovision-user"+ phx-value-identifier={member.id}+ phx-target={@myself}+ class="text-sm"+ icon={:user_minus}+ data-confirm="Are you sure you want to deprovision SSO user and convert them to a standard user? This will sign them out and force to use regular e-mail/password combination to log in again."+ />+ </div></.td><.td>{member.role}@@ -681,6 +694,16 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team doendend+ def handle_event("deprovision-user", %{"identifier" => user_id}, socket) do+ [id: String.to_integer(user_id)]+ |> Plausible.Auth.find_user_by()+ |> SSO.deprovision_user!()++ team_layout = Layout.init(socket.assigns.team)+ success(socket, "User deprovisioned")+ {:noreply, assign(socket, team_layout: team_layout)}+ end+def handle_event("estimate-cost", %{"enterprise_plan" => params}, socket) doparams = update_features_to_list(params)diff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.exindex 4503f7ba89..d34c6ba8a1 100644--- a/lib/plausible_web/components/generic.ex+++ b/lib/plausible_web/components/generic.ex@@ -804,38 +804,52 @@ defmodule PlausibleWeb.Components.Generic doendattr :href, :string, default: nil+ attr :icon, :atom, default: :pencil_squareattr :rest, :global, include: ~w(method disabled)def edit_button(assigns) doif assigns[:href] do~H"""<.unstyled_link href={@href} {@rest}>- <Heroicons.pencil_square class="w-5 h-5 text-indigo-800 hover:text-indigo-500 dark:text-indigo-500 dark:hover:text-indigo-300" />+ <.dynamic_icon+ name={@icon}+ class="w-5 h-5 text-indigo-800 hover:text-indigo-500 dark:text-indigo-500 dark:hover:text-indigo-300"+ /></.unstyled_link>"""else~H"""<button {@rest}>- <Heroicons.pencil_square class="w-5 h-5 text-indigo-800 hover:text-indigo-500 dark:text-indigo-500 dark:hover:text-indigo-300" />+ <.dynamic_icon+ name={@icon}+ class="w-5 h-5 text-indigo-800 hover:text-indigo-500 dark:text-indigo-500 dark:hover:text-indigo-300"+ /></button>"""endendattr :href, :string, default: nil+ attr :icon, :atom, default: :trashattr :rest, :global, include: ~w(method disabled)def delete_button(assigns) doif assigns[:href] do~H"""<.unstyled_link href={@href} {@rest}>- <Heroicons.trash class="w-5 h-5 text-red-800 hover:text-red-500 dark:text-red-500 dark:hover:text-red-400" />+ <.dynamic_icon+ name={@icon}+ class="w-5 h-5 text-red-800 hover:text-red-500 dark:text-red-500 dark:hover:text-red-400"+ /></.unstyled_link>"""else~H"""<button {@rest}>- <Heroicons.trash class="w-5 h-5 text-red-800 hover:text-red-500 dark:text-red-500 dark:hover:text-red-400" />+ <.dynamic_icon+ name={@icon}+ class="w-5 h-5 text-red-800 hover:text-red-500 dark:text-red-500 dark:hover:text-red-400"+ /></button>"""enddiff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exsindex c77e61432b..f547ce64b8 100644--- a/test/plausible_web/live/customer_support/teams_test.exs+++ b/test/plausible_web/live/customer_support/teams_test.exs@@ -573,6 +573,34 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest dolv |> element("button#remove-domain-#{domain.identifier}") |> render_click()refute render(lv) =~ "sso1.example.com"end++ test "deprovisioning users", %{conn: conn, user: user} do+ team = team_of(user) |> Plausible.Teams.complete_setup()+ integration = SSO.initiate_saml_integration(team)+ {:ok, sso_domain} = SSO.Domains.add(integration, "example.com")++ _sso_domain = SSO.Domains.verify(sso_domain, skip_checks?: true)++ {:ok, :standard, team, user} =+ SSO.provision_user(%SSO.Identity{+ id: Ecto.UUID.generate(),+ name: user.name,+ email: user.email,+ expires_at: NaiveDateTime.add(NaiveDateTime.utc_now(:second), 6, :hour)+ })++ # need to re-authenticate for SSO to take effect+ {:ok, conn: conn} = log_in(%{user: user, conn: conn})++ {:ok, lv, _html} = live(conn, open_team(team.id, tab: :members))++ html = render(lv)++ assert text(html) =~ "SSO membership"+ lv |> element("#deprovision-user-#{user.id}") |> render_click()++ assert Plausible.Repo.reload!(user).type == :standard+ endendendend