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
Split `current_team` into `site_team` and `my_team` (#4881)
Adrian Gruntkowski76cf87427d99
diff --git a/extra/lib/plausible_web/live/funnel_settings.ex b/extra/lib/plausible_web/live/funnel_settings.exindex d12bfb2a7e..dffe088663 100644--- a/extra/lib/plausible_web/live/funnel_settings.ex+++ b/extra/lib/plausible_web/live/funnel_settings.ex@@ -31,6 +31,7 @@ defmodule PlausibleWeb.Live.FunnelSettings do{:ok,assign(socket,+ site_team: socket.assigns.site.team,domain: domain,displayed_funnels: socket.assigns.all_funnels,setup_funnel?: false,diff --git a/lib/plausible_web/components/billing/plan_box.ex b/lib/plausible_web/components/billing/plan_box.exindex 3ffae1f139..7d5b6aea4b 100644--- a/lib/plausible_web/components/billing/plan_box.ex+++ b/lib/plausible_web/components/billing/plan_box.ex@@ -175,7 +175,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox dochange_plan_link_text = change_plan_link_text(assigns)subscription =- Plausible.Teams.Billing.get_subscription(assigns.current_team)+ Plausible.Teams.Billing.get_subscription(assigns.my_team)billing_details_expired =Subscription.Status.in?(subscription, [@@ -225,14 +225,10 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do|> assign(:confirm_message, losing_features_message(feature_usage_check))~H"""- <%= if @owned_plan && Plausible.Billing.Subscriptions.resumable?(@current_team.subscription) do %>+ <%= if @owned_plan && Plausible.Billing.Subscriptions.resumable?(@my_team.subscription) do %><.change_plan_link {assigns} /><% else %>- <PlausibleWeb.Components.Billing.paddle_button- user={@current_user}- team={@current_team}- {assigns}- >+ <PlausibleWeb.Components.Billing.paddle_button user={@current_user} team={@my_team} {assigns}>Upgrade</PlausibleWeb.Components.Billing.paddle_button><% end %>@@ -264,18 +260,18 @@ defmodule PlausibleWeb.Components.Billing.PlanBox dodefp check_usage_within_plan_limits(%{available: true,usage: usage,- current_team: current_team,+ my_team: my_team,plan_to_render: plan}) do# At this point, the user is *not guaranteed* to have a team,# with ongoing trial.trial_active_or_ended_recently? =- not is_nil(current_team) and not is_nil(current_team.trial_expiry_date) and- Plausible.Teams.trial_days_left(current_team) >= -10+ not is_nil(my_team) and not is_nil(my_team.trial_expiry_date) and+ Plausible.Teams.trial_days_left(my_team) >= -10limit_checking_opts =cond do- current_team && current_team.allow_next_upgrade_override ->+ my_team && my_team.allow_next_upgrade_override ->[ignore_pageview_limit: true]trial_active_or_ended_recently? && plan.volume == "10k" ->diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.exindex 9c05d8f08b..5858bc83cd 100644--- a/lib/plausible_web/controllers/billing_controller.ex+++ b/lib/plausible_web/controllers/billing_controller.ex@@ -9,15 +9,15 @@ defmodule PlausibleWeb.BillingController doplug PlausibleWeb.RequireAccountPlugdef ping_subscription(%Plug.Conn{} = conn, _params) do- subscribed? = Plausible.Teams.Billing.has_active_subscription?(conn.assigns.current_team)+ subscribed? = Plausible.Teams.Billing.has_active_subscription?(conn.assigns.my_team)json(conn, %{is_subscribed: subscribed?})enddef choose_plan(conn, _params) do- current_team = conn.assigns.current_team+ my_team = conn.assigns.my_team- if Plausible.Teams.Billing.enterprise_configured?(current_team) do+ if Plausible.Teams.Billing.enterprise_configured?(my_team) doredirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))elserender(conn, "choose_plan.html",@@ -28,12 +28,12 @@ defmodule PlausibleWeb.BillingController doenddef upgrade_to_enterprise_plan(conn, _params) do- current_team = conn.assigns.current_team- subscription = Plausible.Teams.Billing.get_subscription(current_team)+ my_team = conn.assigns.my_team+ subscription = Plausible.Teams.Billing.get_subscription(my_team){latest_enterprise_plan, price} =Plausible.Teams.Billing.latest_enterprise_plan_with_price(- current_team,+ my_team,PlausibleWeb.RemoteIP.get(conn))@@ -70,9 +70,9 @@ defmodule PlausibleWeb.BillingController doenddef change_plan_preview(conn, %{"plan_id" => new_plan_id}) do- current_team = conn.assigns.current_team+ my_team = conn.assigns.my_teamcurrent_user = conn.assigns.current_user- subscription = Plausible.Teams.Billing.active_subscription_for(current_team)+ subscription = Plausible.Teams.Billing.active_subscription_for(my_team)case preview_subscription(subscription, new_plan_id) do{:ok, {subscription, preview_info}} ->@@ -91,7 +91,7 @@ defmodule PlausibleWeb.BillingController doextra: %{message: msg,new_plan_id: new_plan_id,- current_team: current_team.id,+ team_id: my_team.id,user_id: current_user.id})@@ -103,9 +103,9 @@ defmodule PlausibleWeb.BillingController doenddef change_plan(conn, %{"new_plan_id" => new_plan_id}) do- current_team = conn.assigns.current_team+ my_team = conn.assigns.my_team- case Plausible.Teams.Billing.change_plan(current_team, new_plan_id) do+ case Plausible.Teams.Billing.change_plan(my_team, new_plan_id) do{:ok, _subscription} ->conn|> put_flash(:success, "Plan changed successfully")@@ -133,7 +133,7 @@ defmodule PlausibleWeb.BillingController doerrors: inspect(e),message: msg,new_plan_id: new_plan_id,- current_team: current_team.id,+ team_id: my_team.id,user_id: conn.assigns.current_user.id})diff --git a/lib/plausible_web/controllers/settings_controller.ex b/lib/plausible_web/controllers/settings_controller.exindex 2795db50de..374673a339 100644--- a/lib/plausible_web/controllers/settings_controller.ex+++ b/lib/plausible_web/controllers/settings_controller.ex@@ -21,23 +21,23 @@ defmodule PlausibleWeb.SettingsController doenddef subscription(conn, _params) do- current_team = conn.assigns.current_team- subscription = Teams.Billing.get_subscription(current_team)+ my_team = conn.assigns.my_team+ subscription = Teams.Billing.get_subscription(my_team)render(conn, :subscription,layout: {PlausibleWeb.LayoutView, :settings},subscription: subscription,pageview_limit: Teams.Billing.monthly_pageview_limit(subscription),- pageview_usage: Teams.Billing.monthly_pageview_usage(current_team),- site_usage: Teams.Billing.site_usage(current_team),- site_limit: Teams.Billing.site_limit(current_team),- team_member_limit: Teams.Billing.team_member_limit(current_team),- team_member_usage: Teams.Billing.team_member_usage(current_team)+ pageview_usage: Teams.Billing.monthly_pageview_usage(my_team),+ site_usage: Teams.Billing.site_usage(my_team),+ site_limit: Teams.Billing.site_limit(my_team),+ team_member_limit: Teams.Billing.team_member_limit(my_team),+ team_member_usage: Teams.Billing.team_member_usage(my_team))enddef invoices(conn, _params) do- subscription = Teams.Billing.get_subscription(conn.assigns.current_team)+ subscription = Teams.Billing.get_subscription(conn.assigns.my_team)invoices = Plausible.Billing.paddle_api().get_invoices(subscription)render(conn, :invoices, layout: {PlausibleWeb.LayoutView, :settings}, invoices: invoices)diff --git a/lib/plausible_web/controllers/site/membership_controller.ex b/lib/plausible_web/controllers/site/membership_controller.exindex c95c8e282b..eee18770d1 100644--- a/lib/plausible_web/controllers/site/membership_controller.ex+++ b/lib/plausible_web/controllers/site/membership_controller.ex@@ -155,7 +155,7 @@ defmodule PlausibleWeb.Site.MembershipController do|> Enum.into(%{})def update_role_by_user(conn, %{"id" => user_id, "new_role" => new_role_str}) do- %{site: site, current_user: current_user, current_user_role: current_user_role} = conn.assigns+ %{site: site, current_user: current_user, site_role: site_role} = conn.assignsmembership =Membership |> Repo.get_by!(user_id: user_id, site_id: site.id) |> Repo.preload(:user)@@ -164,9 +164,9 @@ defmodule PlausibleWeb.Site.MembershipController docan_grant_role? =if membership.user.id == current_user.id do- can_grant_role_to_self?(current_user_role, new_role)+ can_grant_role_to_self?(site_role, new_role)else- can_grant_role_to_other?(current_user_role, new_role)+ can_grant_role_to_other?(site_role, new_role)endif can_grant_role? dodiff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex c45ffa7742..f7cffb0d84 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -14,19 +14,19 @@ defmodule PlausibleWeb.SiteController dodef new(conn, params) doflow = params["flow"] || PlausibleWeb.Flows.register()- current_team = conn.assigns.current_team+ my_team = conn.assigns.my_teamrender(conn, "new.html",changeset: Plausible.Site.changeset(%Plausible.Site{}),- site_limit: Plausible.Teams.Billing.site_limit(current_team),- site_limit_exceeded?: Plausible.Teams.Billing.ensure_can_add_new_site(current_team) != :ok,+ site_limit: Plausible.Teams.Billing.site_limit(my_team),+ site_limit_exceeded?: Plausible.Teams.Billing.ensure_can_add_new_site(my_team) != :ok,form_submit_url: "/sites?flow=#{flow}",flow: flow)enddef create_site(conn, %{"site" => site_params}) do- team = conn.assigns.current_team+ team = conn.assigns.my_teamuser = conn.assigns.current_userfirst_site? = Plausible.Teams.Billing.site_usage(team) == 0flow = conn.params["flow"]diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.exindex c040f5c6a7..d194107768 100644--- a/lib/plausible_web/controllers/stats_controller.ex+++ b/lib/plausible_web/controllers/stats_controller.ex@@ -53,7 +53,7 @@ defmodule PlausibleWeb.StatsController dodef stats(%{assigns: %{site: site}} = conn, _params) dosite = Plausible.Repo.preload(site, :owner)stats_start_date = Plausible.Sites.stats_start_date(site)- can_see_stats? = not Sites.locked?(site) or conn.assigns[:current_user_role] == :super_admin+ can_see_stats? = not Sites.locked?(site) or conn.assigns[:site_role] == :super_admindemo = site.domain == PlausibleWeb.Endpoint.host()dogfood_page_path = if demo, do: "/#{site.domain}", else: "/:dashboard"skip_to_dashboard? = conn.params["skip_to_dashboard"] == "true"diff --git a/lib/plausible_web/live/auth_context.ex b/lib/plausible_web/live/auth_context.exindex 1258605d69..9099ed656b 100644--- a/lib/plausible_web/live/auth_context.ex+++ b/lib/plausible_web/live/auth_context.ex@@ -31,7 +31,7 @@ defmodule PlausibleWeb.Live.AuthContext do_ -> nilendend)- |> assign_new(:current_team, fn context ->+ |> assign_new(:my_team, fn context ->case context.current_user donil -> nil%{team_memberships: [%{team: team}]} -> teamdiff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.exindex db48c399fd..54fee15399 100644--- a/lib/plausible_web/live/choose_plan.ex+++ b/lib/plausible_web/live/choose_plan.ex@@ -22,16 +22,16 @@ defmodule PlausibleWeb.Live.ChoosePlan do|> Enum.map(& &1.site_id)end)|> assign_new(:usage, fn %{- current_team: current_team,+ my_team: my_team,pending_ownership_site_ids: pending_ownership_site_ids} ->- Plausible.Teams.Billing.quota_usage(current_team,+ Plausible.Teams.Billing.quota_usage(my_team,with_features: true,pending_ownership_site_ids: pending_ownership_site_ids)end)- |> assign_new(:subscription, fn %{current_team: current_team} ->- Plausible.Teams.Billing.get_subscription(current_team)+ |> assign_new(:subscription, fn %{my_team: my_team} ->+ Plausible.Teams.Billing.get_subscription(my_team)end)|> assign_new(:owned_plan, fn %{subscription: subscription} ->Plans.get_regular_plan(subscription, only_non_expired: true)diff --git a/lib/plausible_web/live/csv_export.ex b/lib/plausible_web/live/csv_export.exindex aeb883c47b..f76741dc74 100644--- a/lib/plausible_web/live/csv_export.ex+++ b/lib/plausible_web/live/csv_export.ex@@ -8,7 +8,7 @@ defmodule PlausibleWeb.Live.CSVExport do# :not_mounted_at_router ensures we have already done auth checks in the controller# if this liveview becomes available from the router, please make sure- # to check that current_user_role is allowed to manage site exports+ # to check that site_role is allowed to manage site exports@impl truedef mount(:not_mounted_at_router, session, socket) do%{diff --git a/lib/plausible_web/live/csv_import.ex b/lib/plausible_web/live/csv_import.exindex e6094e2826..d70625c499 100644--- a/lib/plausible_web/live/csv_import.ex+++ b/lib/plausible_web/live/csv_import.ex@@ -11,7 +11,7 @@ defmodule PlausibleWeb.Live.CSVImport do# :not_mounted_at_router ensures we have already done auth checks in the controller# if this liveview becomes available from the router, please make sure- # to check that current_user_role is allowed to make site imports+ # to check that site_role is allowed to make site imports@impl truedef mount(:not_mounted_at_router, session, socket) do%{"site_id" => site_id, "storage" => storage} = sessiondiff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex e62292e839..bb0ed334d8 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -36,7 +36,7 @@ defmodule PlausibleWeb.Live.GoalSettings do{:ok,assign(socket,- current_team: socket.assigns.site.team,+ site_team: socket.assigns.site.team,site_id: site_id,domain: domain,displayed_goals: socket.assigns.all_goals,@@ -61,7 +61,7 @@ defmodule PlausibleWeb.Live.GoalSettings dodomain={@domain}site={@site}current_user={@current_user}- current_team={@current_team}+ site_team={@site_team}existing_goals={@all_goals}goal={@form_goal}on_save_goal={diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.exindex 3c8484bc78..90371ce98b 100644--- a/lib/plausible_web/live/goal_settings/form.ex+++ b/lib/plausible_web/live/goal_settings/form.ex@@ -37,7 +37,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form doevent_name_options_count: length(assigns.event_name_options),event_name_options: Enum.map(assigns.event_name_options, &{&1, &1}),current_user: assigns.current_user,- current_team: assigns.current_team,+ site_team: assigns.site_team,domain: assigns.domain,selected_tab: selected_tab,tab_sequence_id: 0,@@ -74,7 +74,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form dof={f}suffix={@context_unique_id}current_user={@current_user}- current_team={@current_team}+ site_team={@site_team}site={@site}goal={@goal}existing_goals={@existing_goals}@@ -117,7 +117,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form dof={f}suffix={suffix(@context_unique_id, @tab_sequence_id)}current_user={@current_user}- current_team={@current_team}+ site_team={@site_team}site={@site}existing_goals={@existing_goals}goal_options={@event_name_options}@@ -202,7 +202,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form doattr(:f, Phoenix.HTML.Form)attr(:site, Plausible.Site)attr(:current_user, Plausible.Auth.User)- attr(:current_team, Plausible.Teams.Team)+ attr(:site_team, Plausible.Teams.Team)attr(:suffix, :string)attr(:existing_goals, :list)attr(:goal_options, :list)@@ -263,7 +263,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form dof={@f}site={@site}current_user={@current_user}- current_team={@current_team}+ site_team={@site_team}has_access_to_revenue_goals?={@has_access_to_revenue_goals?}goal={@goal}suffix={@suffix}@@ -287,7 +287,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do<PlausibleWeb.Components.Billing.Notice.premium_featurebillable_user={@site.owner}current_user={@current_user}- current_team={@current_team}+ current_team={@site_team}feature_mod={Plausible.Billing.Feature.RevenueGoals}class="rounded-b-md"/>diff --git a/lib/plausible_web/live/props_settings.ex b/lib/plausible_web/live/props_settings.exindex 5188c62d92..b968754761 100644--- a/lib/plausible_web/live/props_settings.ex+++ b/lib/plausible_web/live/props_settings.ex@@ -26,6 +26,7 @@ defmodule PlausibleWeb.Live.PropsSettings do{:ok,assign(socket,+ site_team: socket.assigns.site.team,site_id: site_id,domain: domain,add_prop?: false,diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.exindex 00c57dfdaf..f398af35b2 100644--- a/lib/plausible_web/live/sites.ex+++ b/lib/plausible_web/live/sites.ex@@ -31,10 +31,10 @@ defmodule PlausibleWeb.Live.Sites doend)|> assign_new(:needs_to_upgrade, fn %{current_user: current_user,- current_team: current_team+ my_team: my_team} ->Plausible.Teams.Users.owns_sites?(current_user, include_pending?: true) &&- Plausible.Teams.Billing.check_needs_to_upgrade(current_team)+ Plausible.Teams.Billing.check_needs_to_upgrade(my_team)end){:noreply, socket}diff --git a/lib/plausible_web/plugs/auth_plug.ex b/lib/plausible_web/plugs/auth_plug.exindex 290a426bea..83bb521fa5 100644--- a/lib/plausible_web/plugs/auth_plug.ex+++ b/lib/plausible_web/plugs/auth_plug.ex@@ -35,7 +35,7 @@ defmodule PlausibleWeb.AuthPlug doconn|> assign(:current_user, user)|> assign(:current_user_session, user_session)- |> assign(:current_team, team)+ |> assign(:my_team, team)_ ->conndiff --git a/lib/plausible_web/plugs/authorize_site_access.ex b/lib/plausible_web/plugs/authorize_site_access.exindex 5a925b8a75..d9722d5bb4 100644--- a/lib/plausible_web/plugs/authorize_site_access.ex+++ b/lib/plausible_web/plugs/authorize_site_access.ex@@ -115,10 +115,10 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccess doowner: [subscription: Plausible.Users.last_subscription_query()])- conn = merge_assigns(conn, site: site, current_user_role: role)+ conn = merge_assigns(conn, site: site, site_role: role)if not is_nil(current_user) and role not in [:public, nil] do- assign(conn, :current_team, site.team)+ assign(conn, :site_team, site.team)elseconnenddiff --git a/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex b/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heexindex 2be8b52b70..3eab3cc241 100644--- a/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex+++ b/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex@@ -67,7 +67,7 @@id="paddle-button"paddle_product_id={@latest_enterprise_plan.paddle_plan_id}user={@current_user}- team={@current_team}+ team={@my_team}><svg fill="currentColor" viewBox="0 0 20 20" class="inline w-4 h-4 mr-2"><pathdiff --git a/lib/plausible_web/templates/layout/_notice.html.heex b/lib/plausible_web/templates/layout/_notice.html.heexindex 24e03f001d..98e5372321 100644--- a/lib/plausible_web/templates/layout/_notice.html.heex+++ b/lib/plausible_web/templates/layout/_notice.html.heex@@ -2,18 +2,18 @@<%= render("_flash.html", assigns) %><% end %>-<div :if={assigns[:current_team]} class="flex flex-col gap-y-2">+<div :if={assigns[:my_team]} class="flex flex-col gap-y-2"><Notice.active_grace_period- :if={Plausible.Auth.GracePeriod.active?(@current_team)}- enterprise?={Plausible.Teams.Billing.enterprise_configured?(@current_team)}- grace_period_end={grace_period_end(@current_team)}+ :if={Plausible.Auth.GracePeriod.active?(@my_team)}+ enterprise?={Plausible.Teams.Billing.enterprise_configured?(@my_team)}+ grace_period_end={grace_period_end(@my_team)}/>- <Notice.dashboard_locked :if={Plausible.Auth.GracePeriod.expired?(@current_team)} />+ <Notice.dashboard_locked :if={Plausible.Auth.GracePeriod.expired?(@my_team)} />- <Notice.subscription_cancelled subscription={@current_team.subscription} />+ <Notice.subscription_cancelled subscription={@my_team.subscription} />- <Notice.subscription_past_due subscription={@current_team.subscription} class="container" />+ <Notice.subscription_past_due subscription={@my_team.subscription} class="container" />- <Notice.subscription_paused subscription={@current_team.subscription} class="container" />+ <Notice.subscription_paused subscription={@my_team.subscription} class="container" /></div>diff --git a/lib/plausible_web/templates/settings/api_keys.html.heex b/lib/plausible_web/templates/settings/api_keys.html.heexindex 2743f54378..c54634b21f 100644--- a/lib/plausible_web/templates/settings/api_keys.html.heex+++ b/lib/plausible_web/templates/settings/api_keys.html.heex@@ -10,13 +10,13 @@<PlausibleWeb.Components.Billing.Notice.premium_featurebillable_user={@current_user}current_user={@current_user}- current_team={@current_team}+ current_team={@my_team}feature_mod={Plausible.Billing.Feature.StatsAPI}/><.filter_bar filtering_enabled?={false}><.button_link- :if={Plausible.Billing.Feature.StatsAPI.check_availability(@current_team) == :ok}+ :if={Plausible.Billing.Feature.StatsAPI.check_availability(@my_team) == :ok}href={Routes.settings_path(@conn, :new_api_key)}>New API Keydiff --git a/lib/plausible_web/templates/settings/danger_zone.html.heex b/lib/plausible_web/templates/settings/danger_zone.html.heexindex ea776d8920..074c5635a5 100644--- a/lib/plausible_web/templates/settings/danger_zone.html.heex+++ b/lib/plausible_web/templates/settings/danger_zone.html.heex@@ -7,7 +7,7 @@<:title>Delete Account</:title><:subtitle>Deleting your account removes all sites and stats you've collected</:subtitle>- <%= if Plausible.Billing.Subscription.Status.active?(@current_team && @current_team.subscription) do %>+ <%= if Plausible.Billing.Subscription.Status.active?(@my_team && @my_team.subscription) do %><.notice theme={:gray} title="Cannot delete account at this time">Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.</.notice>diff --git a/lib/plausible_web/templates/settings/subscription.html.heex b/lib/plausible_web/templates/settings/subscription.html.heexindex ac3483e6df..306ab6fece 100644--- a/lib/plausible_web/templates/settings/subscription.html.heex+++ b/lib/plausible_web/templates/settings/subscription.html.heex@@ -33,7 +33,7 @@<div class="flex flex-col items-center justify-between sm:flex-row sm:items-start"><PlausibleWeb.Components.Billing.monthly_quota_box- team={@current_team}+ team={@my_team}subscription={@subscription}/><div class="w-full md:w-1/3 h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900">diff --git a/lib/plausible_web/templates/site/membership/invite_member_form.html.heex b/lib/plausible_web/templates/site/membership/invite_member_form.html.heexindex e7cca26357..57a759a5df 100644--- a/lib/plausible_web/templates/site/membership/invite_member_form.html.heex+++ b/lib/plausible_web/templates/site/membership/invite_member_form.html.heex@@ -13,7 +13,7 @@:if={Map.get(assigns, :is_at_limit, false)}current_user={@current_user}billable_user={@site.owner}- current_team={@current_team}+ current_team={@site_team}limit={Map.get(assigns, :team_member_limit, 0)}resource="team members"/>diff --git a/lib/plausible_web/templates/site/new.html.heex b/lib/plausible_web/templates/site/new.html.heexindex 5bfe8b7ec0..d0c5c64d67 100644--- a/lib/plausible_web/templates/site/new.html.heex+++ b/lib/plausible_web/templates/site/new.html.heex@@ -9,7 +9,7 @@<PlausibleWeb.Components.Billing.Notice.limit_exceeded:if={@site_limit_exceeded?}current_user={@current_user}- current_team={@current_team}+ current_team={@my_team}billable_user={@current_user}limit={@site_limit}resource="sites"diff --git a/lib/plausible_web/templates/site/settings_funnels.html.heex b/lib/plausible_web/templates/site/settings_funnels.html.heexindex 6cb98b1a92..6c8ea379c3 100644--- a/lib/plausible_web/templates/site/settings_funnels.html.heex+++ b/lib/plausible_web/templates/site/settings_funnels.html.heex@@ -15,7 +15,7 @@<PlausibleWeb.Components.Billing.Notice.premium_featurebillable_user={@site.owner}current_user={@current_user}- current_team={@current_team}+ current_team={@site_team}feature_mod={Plausible.Billing.Feature.Funnels}/>diff --git a/lib/plausible_web/templates/site/settings_people.html.heex b/lib/plausible_web/templates/site/settings_people.html.heexindex fdb43ddbb0..50f7c39c8f 100644--- a/lib/plausible_web/templates/site/settings_people.html.heex+++ b/lib/plausible_web/templates/site/settings_people.html.heex@@ -100,7 +100,7 @@</svg></span></li>- <%= if @conn.assigns[:current_user_role] == :owner do %>+ <%= if @conn.assigns[:site_role] == :owner do %><liclass="select-none hover:bg-gray-100 dark:hover:bg-gray-900 text-red-600"role="option"diff --git a/lib/plausible_web/templates/site/settings_props.html.heex b/lib/plausible_web/templates/site/settings_props.html.heexindex e3b7c1bfe2..a0b233905c 100644--- a/lib/plausible_web/templates/site/settings_props.html.heex+++ b/lib/plausible_web/templates/site/settings_props.html.heex@@ -16,7 +16,7 @@<PlausibleWeb.Components.Billing.Notice.premium_featurebillable_user={@site.owner}current_user={@current_user}- current_team={@current_team}+ current_team={@site_team}feature_mod={Plausible.Billing.Feature.Props}grandfathered?/>diff --git a/lib/plausible_web/templates/stats/site_locked.html.heex b/lib/plausible_web/templates/stats/site_locked.html.heexindex 286deea7a2..3a10fb1569 100644--- a/lib/plausible_web/templates/stats/site_locked.html.heex+++ b/lib/plausible_web/templates/stats/site_locked.html.heex@@ -20,7 +20,7 @@Dashboard locked</h3>- <%= case @conn.assigns[:current_user_role] do %>+ <%= case @conn.assigns[:site_role] do %><% :owner -> %><div class="mt-3 text-gray-600 dark:text-gray-300 text-center"><p>diff --git a/lib/plausible_web/templates/stats/stats.html.heex b/lib/plausible_web/templates/stats/stats.html.heexindex 4a2d69ab5b..f89d4a0068 100644--- a/lib/plausible_web/templates/stats/stats.html.heex+++ b/lib/plausible_web/templates/stats/stats.html.heex@@ -37,7 +37,7 @@data-embedded={to_string(@conn.assigns[:embedded])}data-background={@conn.assigns[:background]}data-is-dbip={to_string(@is_dbip)}- data-current-user-role={@conn.assigns[:current_user_role]}+ data-current-user-role={@conn.assigns[:site_role]}data-flags={Jason.encode!(@flags)}data-valid-intervals-by-period={Plausible.Stats.Interval.valid_by_period(site: @site) |> Jason.encode!()diff --git a/lib/plausible_web/user_auth.ex b/lib/plausible_web/user_auth.exindex 84b36b6c6f..67041d8652 100644--- a/lib/plausible_web/user_auth.ex+++ b/lib/plausible_web/user_auth.ex@@ -131,7 +131,7 @@ defmodule PlausibleWeb.UserAuth doinner_join: u in assoc(us, :user),as: :user,left_join: tm in assoc(u, :team_memberships),- # TODO: whenever current_team.subscription is used to prevent user action, we must check whether the team association is ownership.+ # NOTE: whenever my_team.subscription is used to prevent user action, we must check whether the team association is ownership.# Otherwise regular members will be limited by team owner in cases like deleting their own account.on: tm.role != :guest,left_join: t in assoc(tm, :team),diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 1842117342..ac53f6c69a 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -71,7 +71,7 @@ defmodule PlausibleWeb.LayoutView do]},%{key: "Email Reports", value: "email-reports", icon: :envelope},- if conn.assigns[:current_user_role] == :owner do+ if conn.assigns[:site_role] == :owner do%{key: "Danger Zone", value: "danger-zone", icon: :exclamation_triangle}end]diff --git a/test/plausible_web/plugs/authorize_site_access_test.exs b/test/plausible_web/plugs/authorize_site_access_test.exsindex 9f59bd7439..087b4f7362 100644--- a/test/plausible_web/plugs/authorize_site_access_test.exs+++ b/test/plausible_web/plugs/authorize_site_access_test.exs@@ -230,7 +230,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest dorefute conn.haltedassert conn.assigns.site.id == site.id- assert conn.assigns.current_user_role == :owner+ assert conn.assigns.site_role == :ownerendfor role <- [:viewer, :editor] do@@ -248,7 +248,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest dorefute conn.haltedassert conn.assigns.site.id == site.id- assert conn.assigns.current_user_role == unquote(role)+ assert conn.assigns.site_role == unquote(role)endend@@ -268,7 +268,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest dorefute conn.haltedassert conn.assigns.site.id == site.id- assert conn.assigns.current_user_role == :super_admin+ assert conn.assigns.site_role == :super_adminendtest "allows user based on website visibility (authenticated user)", %{conn: conn} do