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
Get rid of `billable_user` in favour of `current_team_role` (or `site_role` if need be) (#5180)
hq1629902cdbc7d
diff --git a/lib/plausible_web/components/billing/notice.ex b/lib/plausible_web/components/billing/notice.exindex dcfcdb9c8e..4e4e8e1c04 100644--- a/lib/plausible_web/components/billing/notice.ex+++ b/lib/plausible_web/components/billing/notice.ex@@ -4,7 +4,6 @@ defmodule PlausibleWeb.Components.Billing.Notice douse PlausibleWeb, :componentrequire Plausible.Billing.Subscription.Status- alias Plausible.Auth.Useralias Plausible.Billing.{Subscription, Plans, Subscriptions, Feature}def active_grace_period(assigns) do@@ -61,8 +60,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do"""end- attr(:billable_user, User, required: true)- attr(:current_user, User, required: true)+ attr(:current_role, :atom, required: true)attr(:current_team, :any, required: true)attr(:feature_mod, :atom, required: true, values: Feature.list())attr(:grandfathered?, :boolean, default: false)@@ -76,19 +74,14 @@ defmodule PlausibleWeb.Components.Billing.Notice dotitle="Notice"{@rest}>- {account_label(@current_user, @billable_user)} does not have access to {@feature_mod.display_name()}. To get access to this feature,- <.upgrade_call_to_action- current_team={@current_team}- current_user={@current_user}- billable_user={@billable_user}- />.+ {account_label(@current_role)} does not have access to {@feature_mod.display_name()}. To get access to this feature,+ <.upgrade_call_to_action current_role={@current_role} current_team={@current_team} />.</.notice>"""end- attr(:billable_user, User, required: true)- attr(:current_user, User, required: true)attr(:current_team, :any, required: true)+ attr(:current_role, :atom, required: true)attr(:limit, :integer, required: true)attr(:resource, :string, required: true)attr(:rest, :global)@@ -96,12 +89,8 @@ defmodule PlausibleWeb.Components.Billing.Notice dodef limit_exceeded(assigns) do~H"""<.notice {@rest} title="Notice">- {account_label(@current_user, @billable_user)} is limited to {@limit} {@resource}. To increase this limit,- <.upgrade_call_to_action- current_team={@current_team}- current_user={@current_user}- billable_user={@billable_user}- />.+ {account_label(@current_role)} is limited to {@limit} {@resource}. To increase this limit,+ <.upgrade_call_to_action current_team={@current_team} current_role={@current_role} />.</.notice>"""end@@ -306,9 +295,8 @@ defmodule PlausibleWeb.Components.Billing.Notice do"""end- attr(:current_user, :map)+ attr(:current_role, :atom)attr(:current_team, :any)- attr(:billable_user, :map)defp upgrade_call_to_action(assigns) doteam = Plausible.Teams.with_subscription(assigns.current_team)@@ -321,7 +309,7 @@ defmodule PlausibleWeb.Components.Billing.Notice doendcond do- assigns.billable_user.id !== assigns.current_user.id ->+ assigns.current_role not in [:owner, :billing] ->~H"please reach out to the site owner to upgrade their subscription"upgrade_assistance_required? ->@@ -343,8 +331,8 @@ defmodule PlausibleWeb.Components.Billing.Notice doendend- defp account_label(current_user, billable_user) do- if current_user.id == billable_user.id do+ defp account_label(current_role) do+ if current_role in [:owner, :billing] do"Your account"else"The owner of this site"diff --git a/lib/plausible_web/live/auth_context.ex b/lib/plausible_web/live/auth_context.exindex 4f5bf137a9..cac8d7ff6b 100644--- a/lib/plausible_web/live/auth_context.ex+++ b/lib/plausible_web/live/auth_context.ex@@ -65,7 +65,7 @@ defmodule PlausibleWeb.Live.AuthContext donilend)|> assign_new(- :current_role,+ :current_team_role,fn%{current_user: user = %{}, current_team: current_team = %{}} ->Enum.find_value(user.team_memberships, fn team_membership ->diff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex c0328dde23..bc3ee54773 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -18,6 +18,10 @@ defmodule PlausibleWeb.Live.GoalSettings docurrent_user|> 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+ end)|> assign_new(:all_goals, fn %{site: site} ->Goals.for_site(site, preload_funnels?: true)end)@@ -60,6 +64,7 @@ defmodule PlausibleWeb.Live.GoalSettings dodomain={@domain}site={@site}current_user={@current_user}+ site_role={@site_role}site_team={@site_team}existing_goals={@all_goals}goal={@form_goal}diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.exindex 1c4dcd8022..5f6375290c 100644--- a/lib/plausible_web/live/goal_settings/form.ex+++ b/lib/plausible_web/live/goal_settings/form.ex@@ -35,6 +35,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,+ site_role: assigns.site_role,site_team: assigns.site_team,domain: assigns.domain,selected_tab: selected_tab,@@ -71,7 +72,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do:if={@selected_tab == "custom_events"}f={f}suffix={@context_unique_id}- current_user={@current_user}+ site_role={@site_role}site_team={@site_team}site={@site}goal={@goal}@@ -121,7 +122,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form dox-show="!tabSelectionInProgress"f={f}suffix={suffix(@context_unique_id, @tab_sequence_id)}- current_user={@current_user}+ site_role={@site_role}site_team={@site_team}site={@site}existing_goals={@existing_goals}@@ -314,7 +315,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form doattr(:f, Phoenix.HTML.Form)attr(:site, Plausible.Site)- attr(:current_user, Plausible.Auth.User)+ attr(:site_role, :atom)attr(:site_team, Plausible.Teams.Team)attr(:suffix, :string)attr(:existing_goals, :list)@@ -375,7 +376,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do:if={ee?()}f={@f}site={@site}- current_user={@current_user}+ site_role={@site_role}site_team={@site_team}has_access_to_revenue_goals?={@has_access_to_revenue_goals?}goal={@goal}@@ -398,8 +399,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do~H"""<div class="mt-6 space-y-3" x-data={@js_data}><PlausibleWeb.Components.Billing.Notice.premium_feature- billable_user={List.first(@site.owners)}- current_user={@current_user}+ current_role={@site_role}current_team={@site_team}feature_mod={Plausible.Billing.Feature.RevenueGoals}class="rounded-b-md"diff --git a/lib/plausible_web/live/team_management.ex b/lib/plausible_web/live/team_management.exindex 4dd9a2da04..9b24057f13 100644--- a/lib/plausible_web/live/team_management.ex+++ b/lib/plausible_web/live/team_management.ex@@ -43,8 +43,7 @@ defmodule PlausibleWeb.Live.TeamManagement do<PlausibleWeb.Components.Billing.Notice.limit_exceeded:if={at_limit?(@layout, @team_members_limit)}- current_user={@current_user}- billable_user={@current_user}+ current_role={@current_team_role}current_team={@current_team}limit={@team_members_limit}resource="team members"diff --git a/lib/plausible_web/plugs/auth_plug.ex b/lib/plausible_web/plugs/auth_plug.exindex 08d9afaa3f..27f6d5455a 100644--- a/lib/plausible_web/plugs/auth_plug.ex+++ b/lib/plausible_web/plugs/auth_plug.ex@@ -22,7 +22,7 @@ defmodule PlausibleWeb.AuthPlug docurrent_team_id_from_session = Plug.Conn.get_session(conn, "current_team_id")current_team_id = conn.params["__team"] || current_team_id_from_session- {current_team, current_role} =+ {current_team, current_team_role} =if current_team_id doteam_membership =Enum.find(user.team_memberships, %{}, &(&1.team.identifier == current_team_id))@@ -66,7 +66,7 @@ defmodule PlausibleWeb.AuthPlug do|> assign(:current_user_session, user_session)|> assign(:my_team, my_team)|> assign(:current_team, current_team || my_team)- |> assign(:current_role, current_role || (my_team && :owner))+ |> assign(:current_team_role, current_team_role || (my_team && :owner))|> assign(:teams_count, teams_count)|> assign(:teams, teams)|> assign(:more_teams?, teams_count > 3)diff --git a/lib/plausible_web/plugs/authorize_site_access.ex b/lib/plausible_web/plugs/authorize_site_access.exindex 2ffc99e71d..03549558a4 100644--- a/lib/plausible_web/plugs/authorize_site_access.ex+++ b/lib/plausible_web/plugs/authorize_site_access.ex@@ -38,7 +38,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccess doimport Plug.Connimport Phoenix.Controller, only: [get_format: 1]- @all_roles [:public, :viewer, :admin, :editor, :super_admin, :owner]+ @all_roles [:public, :viewer, :admin, :editor, :super_admin, :owner, :billing]def init([]), do: {@all_roles, nil}diff --git a/lib/plausible_web/plugs/authorize_team_access.ex b/lib/plausible_web/plugs/authorize_team_access.exindex ff81f69684..7ec4257033 100644--- a/lib/plausible_web/plugs/authorize_team_access.ex+++ b/lib/plausible_web/plugs/authorize_team_access.ex@@ -1,7 +1,7 @@defmodule Plausible.Plugs.AuthorizeTeamAccess do@moduledoc """Enforce team role to be within the declared set.- `:current_role` is assumed to be populated by `PlausibleWeb.AuthPlug`.+ `:current_team_role` is assumed to be populated by `PlausibleWeb.AuthPlug`.For cases where no `:current_team` exists, the plug is permissive,so that existing notices can be displayed still.@@ -24,9 +24,9 @@ defmodule Plausible.Plugs.AuthorizeTeamAccess docurrent_team = conn.assigns[:current_team]if current_team && Plausible.Teams.enabled?(current_team) do- current_role = conn.assigns[:current_role]+ current_team_role = conn.assigns[:current_team_role]- if current_role in roles do+ if current_team_role in roles doconnelseconndiff --git a/lib/plausible_web/templates/settings/api_keys.html.heex b/lib/plausible_web/templates/settings/api_keys.html.heexindex 3a28fa1e96..0b23c1b6cf 100644--- a/lib/plausible_web/templates/settings/api_keys.html.heex+++ b/lib/plausible_web/templates/settings/api_keys.html.heex@@ -8,8 +8,7 @@</:subtitle><PlausibleWeb.Components.Billing.Notice.premium_feature- billable_user={@current_user}- current_user={@current_user}+ current_role={@current_team_role}current_team={@current_team}feature_mod={Plausible.Billing.Feature.StatsAPI}/>diff --git a/lib/plausible_web/templates/settings/team_general.html.heex b/lib/plausible_web/templates/settings/team_general.html.heexindex 73ba1089a6..b7066d9582 100644--- a/lib/plausible_web/templates/settings/team_general.html.heex+++ b/lib/plausible_web/templates/settings/team_general.html.heex@@ -21,14 +21,14 @@/></div><.input- readonly={@current_role not in [:owner, :admin]}+ readonly={@current_team_role not in [:owner, :admin]}type="text"field={f[:name]}label="Name"width="w-1/2"/>- <.button type="submit" disabled={@current_role not in [:owner, :admin]}>+ <.button type="submit" disabled={@current_team_role not in [:owner, :admin]}>Change Name</.button></.form>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 d9cb6cd423..a4af638702 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@@ -11,8 +11,7 @@<.form :let={f} for={@conn} action={Routes.membership_path(@conn, :invite_member, @site.domain)}><PlausibleWeb.Components.Billing.Notice.limit_exceeded:if={Map.get(assigns, :is_at_limit, false)}- current_user={@current_user}- billable_user={List.first(@site.owners)}+ current_role={@current_team_role}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 57f9bd12c0..6b373c3779 100644--- a/lib/plausible_web/templates/site/new.html.heex+++ b/lib/plausible_web/templates/site/new.html.heex@@ -8,9 +8,8 @@<.form :let={f} for={@changeset} action={@form_submit_url}><PlausibleWeb.Components.Billing.Notice.limit_exceeded:if={@site_limit_exceeded?}- current_user={@current_user}+ current_role={@current_team_role}current_team={@current_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 3aa2a19591..e0e3863467 100644--- a/lib/plausible_web/templates/site/settings_funnels.html.heex+++ b/lib/plausible_web/templates/site/settings_funnels.html.heex@@ -13,8 +13,7 @@</:subtitle><PlausibleWeb.Components.Billing.Notice.premium_feature- billable_user={List.first(@site.owners)}- current_user={@current_user}+ current_role={@site_role}current_team={@site_team}feature_mod={Plausible.Billing.Feature.Funnels}/>diff --git a/lib/plausible_web/templates/site/settings_props.html.heex b/lib/plausible_web/templates/site/settings_props.html.heexindex 28b4e1757a..39f888b43f 100644--- a/lib/plausible_web/templates/site/settings_props.html.heex+++ b/lib/plausible_web/templates/site/settings_props.html.heex@@ -14,8 +14,7 @@</:subtitle><PlausibleWeb.Components.Billing.Notice.premium_feature- billable_user={List.first(@site.owners)}- current_user={@current_user}+ current_role={@site_role}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 a94eef734b..440132f2e8 100644--- a/lib/plausible_web/templates/stats/site_locked.html.heex+++ b/lib/plausible_web/templates/stats/site_locked.html.heex@@ -21,7 +21,7 @@</h3><%= case @conn.assigns[:site_role] do %>- <% :owner -> %>+ <% role when role in [:owner, :billing] -> %><div class="mt-3 text-gray-600 dark:text-gray-300 text-center"><p>This dashboard is locked because you don't have a valid subscription.@@ -43,24 +43,8 @@<% role when role in [:admin, :viewer, :editor] -> %><div class="mt-3 text-gray-600 dark:text-gray-300 text-center"><p>- This dashboard is currently locked and cannot be accessed. The site owner- <b>{List.first(@site.owners).email}</b>- must upgrade their subscription plan in order to- unlock the stats.+ Owner of this site must upgrade their subscription plan in order to unlock the stats.</p>- <div- :if={not Plausible.Teams.enabled?(@conn.assigns[:current_team])}- class="mt-6 text-sm text-gray-500"- >- <p>Want to pay for this site with the account you're logged in with?</p>- <p class="mt-1">- Contact {List.first(@site.owners).email} and ask them to- <.styled_link href="https://plausible.io/docs/transfer-ownership" new_tab={true}>- transfer the ownership- </.styled_link>- of the site over to you.- </p>- </div></div><div class="mt-6 w-full text-center"><.button_link href={Routes.site_path(@conn, :index)}>Back to my sites</.button_link>diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex 1e79db9844..6f1009e4f0 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -97,7 +97,7 @@ defmodule PlausibleWeb.LayoutView dodef account_settings_sidebar(conn) docurrent_team = conn.assigns[:current_team]- current_role = conn.assigns[:current_role]+ current_team_role = conn.assigns[:current_team_role]options = %{"Account Settings" =>@@ -123,7 +123,7 @@ defmodule PlausibleWeb.LayoutView do[%{key: "General", value: "team/general", icon: :adjustments_horizontal},%{key: "Subscription", value: "billing/subscription", icon: :circle_stack},- if(current_role in [:owner, :admin, :billing],+ if(current_team_role in [:owner, :admin, :billing],do: %{key: "Invoices", value: "billing/invoices", icon: :banknotes})]diff --git a/lib/workers/notify_annual_renewal.ex b/lib/workers/notify_annual_renewal.exindex 5013253bcc..59b56305ab 100644--- a/lib/workers/notify_annual_renewal.ex+++ b/lib/workers/notify_annual_renewal.ex@@ -57,8 +57,7 @@ defmodule Plausible.Workers.NotifyAnnualRenewal do_ ->Sentry.capture_message("Invalid subscription for renewal",- team: team,- user: List.first(team.owner)+ team: team)enddiff --git a/test/plausible_web/components/billing/notice_test.exs b/test/plausible_web/components/billing/notice_test.exsindex 8484839309..cda94570e1 100644--- a/test/plausible_web/components/billing/notice_test.exs+++ b/test/plausible_web/components/billing/notice_test.exs@@ -4,12 +4,11 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doimport Phoenix.LiveViewTest, only: [render_component: 2]alias PlausibleWeb.Components.Billing.Notice- test "premium_feature/1 does not render a notice when user is on trial" do+ test "premium_feature/1 does not render a notice when team is on trial" dome = new_user(trial_expiry_date: Date.utc_today())assert render_component(&Notice.premium_feature/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team_of(me),feature_mod: Plausible.Billing.Feature.Props) == ""@@ -21,8 +20,23 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest dorendered =render_component(&Notice.premium_feature/1,- billable_user: me,- current_user: me,+ current_role: :owner,+ current_team: team,+ feature_mod: Plausible.Billing.Feature.Props+ )++ assert rendered =~ "Your account does not have access to Custom Properties"+ assert rendered =~ "upgrade your subscription"+ assert rendered =~ "/billing/choose-plan"+ end++ test "premium_feature/1 renders an upgrade link when user is the billing role and does not have access to the feature" do+ me = new_user() |> subscribe_to_growth_plan()+ team = team_of(me)++ rendered =+ render_component(&Notice.premium_feature/1,+ current_role: :billing,current_team: team,feature_mod: Plausible.Billing.Feature.Props)@@ -34,12 +48,10 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest dotest "premium_feature/1 does not render an upgrade link when user is not the site owner" dome = new_user() |> subscribe_to_growth_plan()- owner = new_user() |> subscribe_to_growth_plan()rendered =render_component(&Notice.premium_feature/1,- billable_user: owner,- current_user: me,+ current_role: :viewer,current_team: team_of(me),feature_mod: Plausible.Billing.Feature.Funnels)@@ -53,8 +65,7 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest dorendered =render_component(&Notice.premium_feature/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team_of(me),feature_mod: Plausible.Billing.Feature.Funnels)@@ -62,14 +73,13 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doassert rendered == ""end- test "limit_exceeded/1 when billable user is on growth displays upgrade link" do+ test "limit_exceeded/1 when team is on growth displays upgrade link" dome = new_user() |> subscribe_to_growth_plan()team = team_of(me)rendered =render_component(&Notice.limit_exceeded/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team,limit: 10,resource: "users"@@ -80,13 +90,12 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doassert rendered =~ "/billing/choose-plan"end- test "limit_exceeded/1 when billable user is on growth but is not current user does not display upgrade link" do+ test "limit_exceeded/1 when current role is non-owner" dome = new_user() |> subscribe_to_growth_plan()rendered =render_component(&Notice.limit_exceeded/1,- billable_user: me,- current_user: insert(:user),+ current_role: :editor,current_team: team_of(me),limit: 10,resource: "users"@@ -97,13 +106,12 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doend@tag :ee_only- test "limit_exceeded/1 when billable user is on trial displays upgrade link" do+ test "limit_exceeded/1 when team is on trial displays upgrade link" dome = new_user(trial_expiry_date: Date.utc_today())rendered =render_component(&Notice.limit_exceeded/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team_of(me),limit: 10,resource: "users"@@ -115,13 +123,12 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doend@tag :ee_only- test "limit_exceeded/1 when billable user is on an enterprise plan displays support email" do+ test "limit_exceeded/1 when team is on an enterprise plan displays support email" dome = new_user() |> subscribe_to_enterprise_plan()rendered =render_component(&Notice.limit_exceeded/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team_of(me),limit: 10,resource: "users"@@ -134,14 +141,13 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doend@tag :ee_only- test "limit_exceeded/1 when billable user is on a business plan displays support email" do+ test "limit_exceeded/1 when team is on a business plan displays support email" dome = new_user() |> subscribe_to_business_plan()team = team_of(me)rendered =render_component(&Notice.limit_exceeded/1,- billable_user: me,- current_user: me,+ current_role: :owner,current_team: team,limit: 10,resource: "users"diff --git a/test/plausible_web/controllers/stats_controller_test.exs b/test/plausible_web/controllers/stats_controller_test.exsindex b51028184b..821eeb7c39 100644--- a/test/plausible_web/controllers/stats_controller_test.exs+++ b/test/plausible_web/controllers/stats_controller_test.exs@@ -138,10 +138,43 @@ defmodule PlausibleWeb.StatsControllerTest doassert text_of_attr(resp, @react_container, "data-logged-in") == "true"end- test "shows locked page if page is locked", %{conn: conn, user: user} do+ test "shows locked page if site is locked", %{conn: conn, user: user} dolocked_site = new_site(locked: true, owner: user)conn = get(conn, "/" <> locked_site.domain)- assert html_response(conn, 200) =~ "Dashboard locked"+ resp = html_response(conn, 200)+ assert resp =~ "Dashboard locked"+ assert resp =~ "Please subscribe to the appropriate tier with the link below"+ end++ test "shows locked page if site is locked for billing role", %{conn: conn, user: user} do+ other_user = new_user()+ locked_site = new_site(locked: true, owner: other_user)+ add_member(team_of(other_user), user: user, role: :billing)++ conn = get(conn, "/" <> locked_site.domain)+ resp = html_response(conn, 200)+ assert resp =~ "Dashboard locked"+ assert resp =~ "Please subscribe to the appropriate tier with the link below"+ end++ test "shows locked page if site is locked for viewer role", %{conn: conn, user: user} do+ other_user = new_user()+ locked_site = new_site(locked: true, owner: other_user)+ add_member(team_of(other_user), user: user, role: :viewer)++ conn = get(conn, "/" <> locked_site.domain)+ resp = html_response(conn, 200)+ assert resp =~ "Dashboard locked"+ refute resp =~ "Please subscribe to the appropriate tier with the link below"+ assert resp =~ "Owner of this site must upgrade their subscription plan"+ end++ test "shows locked page for anonymous" do+ locked_site = new_site(locked: true, public: true)+ conn = get(build_conn(), "/" <> locked_site.domain)+ resp = html_response(conn, 200)+ assert resp =~ "Dashboard locked"+ assert resp =~ "You can check back later or contact the site owner"endtest "can not view stats of someone else's website", %{conn: conn} dodiff --git a/test/plausible_web/plugs/auth_plug_test.exs b/test/plausible_web/plugs/auth_plug_test.exsindex bf71d7189f..055cd51523 100644--- a/test/plausible_web/plugs/auth_plug_test.exs+++ b/test/plausible_web/plugs/auth_plug_test.exs@@ -25,7 +25,7 @@ defmodule PlausibleWeb.AuthPlugTest doassert conn.assigns[:current_user].id == user.idassert conn.assigns[:my_team].subscription.paddle_plan_id == "123"- assert conn.assigns[:current_role] == :owner+ assert conn.assigns[:current_team_role] == :ownerendtest "looks up the latest subscription", %{conn: conn, user: user} do@@ -61,7 +61,7 @@ defmodule PlausibleWeb.AuthPlugTest do|> AuthPlug.call(%{})assert conn.assigns[:current_team].id == team.id- assert conn.assigns[:current_role] == :owner+ assert conn.assigns[:current_team_role] == :ownerassert get_session(conn, "current_team_id") == team.identifierend@@ -121,6 +121,6 @@ defmodule PlausibleWeb.AuthPlugTest do|> AuthPlug.call(%{})assert conn.assigns[:current_team].id == team.id- assert conn.assigns[:current_role] == :editor+ assert conn.assigns[:current_team_role] == :editorendenddiff --git a/test/plausible_web/plugs/authorize_site_access_test.exs b/test/plausible_web/plugs/authorize_site_access_test.exsindex 05593d3158..6c1494c4b8 100644--- a/test/plausible_web/plugs/authorize_site_access_test.exs+++ b/test/plausible_web/plugs/authorize_site_access_test.exs@@ -15,10 +15,10 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do[],:all_roles,{:all_roles, nil},- {[:public, :viewer, :admin, :editor, :super_admin, :owner], nil}+ {[:public, :viewer, :admin, :editor, :super_admin, :owner, :billing], nil}] dotest "init resolves to expected options with argument #{inspect(init_argument)}" do- assert {[:public, :viewer, :admin, :editor, :super_admin, :owner], nil} ==+ assert {[:public, :viewer, :admin, :editor, :super_admin, :owner, :billing], nil} ==AuthorizeSiteAccess.init(unquote(init_argument))endenddiff --git a/test/plausible_web/plugs/authorize_team_access_test.exs b/test/plausible_web/plugs/authorize_team_access_test.exsindex 5801ca33bc..227a8a0f73 100644--- a/test/plausible_web/plugs/authorize_team_access_test.exs+++ b/test/plausible_web/plugs/authorize_team_access_test.exs@@ -9,7 +9,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeTeamAccessTest dotest "passes when valid current role: #{role}" doconn =build_conn()- |> assign(:current_role, unquote(role))+ |> assign(:current_team_role, unquote(role))|> AuthorizeTeamAccess.call()refute conn.halted@@ -36,7 +36,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeTeamAccessTest doconn =build_conn()|> assign(:current_team, :some)- |> assign(:current_role, :admin)+ |> assign(:current_team_role, :admin)|> AuthorizeTeamAccess.call([:owner])assert conn.halted@@ -47,7 +47,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeTeamAccessTest doconn =build_conn()|> assign(:current_team, nil)- |> assign(:current_role, :admin)+ |> assign(:current_team_role, :admin)|> AuthorizeTeamAccess.call([:owner])refute conn.halted