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
Allow super admin to manage other sites' goals (#5345)
Adrian Gruntkowski1b7fc9c82292
diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex 7734e42cd0..74c26140c6 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -19,8 +19,12 @@ defmodule PlausibleWeb.Live.GoalSettings do|> Plausible.Sites.get_for_user!(domain, [:owner, :admin, :editor, :super_admin])end)|> assign_new(:site_role, fn %{site: site, current_user: current_user} ->- {:ok, {_, role}} = Plausible.Teams.Memberships.site_role(site, current_user)- role+ if Plausible.Auth.is_super_admin?(current_user) do+ :super_admin+ else+ {:ok, {_, role}} = Plausible.Teams.Memberships.site_role(site, current_user)+ role+ endend)|> assign_new(:all_goals, fn %{site: site} ->Goals.for_site(site, preload_funnels?: true)diff --git a/test/plausible_web/live/goal_settings_sync_test.exs b/test/plausible_web/live/goal_settings_sync_test.exsnew file mode 100644index 0000000000..595cdb0c88--- /dev/null+++ b/test/plausible_web/live/goal_settings_sync_test.exs@@ -0,0 +1,28 @@+defmodule PlausibleWeb.Live.GoalSettingsSyncTest do+ use PlausibleWeb.ConnCase, async: false+ use Plausible.Teams.Test++ import Phoenix.LiveViewTest++ describe "GoalSettings live view" do+ setup [:create_user, :log_in]++ @tag :ee_only+ test "lists goals for super admin", %{conn: conn, user: user} do+ patch_env(:super_admin_user_ids, [user.id])++ site = new_site()++ {:ok, g1} = Plausible.Goals.create(site, %{"page_path" => "/go/to/blog/**"})+ {:ok, g2} = Plausible.Goals.create(site, %{"event_name" => "Register"})+ {:ok, g3} = Plausible.Goals.create(site, %{"event_name" => "Purchase", "currency" => "EUR"})++ conn = assign(conn, :live_module, PlausibleWeb.Live.GoalSettings)+ assert {:ok, _lv, html} = live(conn, "/#{site.domain}/settings/goals")++ assert html =~ to_string(g1)+ assert html =~ to_string(g2)+ assert html =~ to_string(g3)+ end+ end+end