Provide site-related team for current team in goal settings LV (#4870)

* Provide site-related team for current team in goal settings LV

* Make billing notice components accept nil current_team gracefully
This commit is contained in:
Adrian Gruntkowski 2024-12-02 16:30:59 +01:00 committed by GitHub
parent b86c2e715f
commit 8b8040edc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 11 deletions

View File

@ -199,13 +199,16 @@ defmodule Plausible.Teams.Adapter.Read.Sites do
def get_for_user!(user, domain, roles \\ [:owner, :admin, :viewer]) do
{query_fn, roles} = for_user_query_and_roles(user, roles)
if :super_admin in roles and Plausible.Auth.is_super_admin?(user.id) do
Plausible.Sites.get_by_domain!(domain)
else
user.id
|> query_fn.(domain, List.delete(roles, :super_admin))
|> Repo.one!()
end
site =
if :super_admin in roles and Plausible.Auth.is_super_admin?(user.id) do
Plausible.Sites.get_by_domain!(domain)
else
user.id
|> query_fn.(domain, List.delete(roles, :super_admin))
|> Repo.one!()
end
Repo.preload(site, :team)
end
def get_for_user(user, domain, roles \\ [:owner, :admin, :viewer]) do

View File

@ -63,7 +63,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do
attr(:billable_user, User, required: true)
attr(:current_user, User, required: true)
attr(:current_team, Plausible.Teams.Team, required: true)
attr(:current_team, :any, required: true)
attr(:feature_mod, :atom, required: true, values: Feature.list())
attr(:grandfathered?, :boolean, default: false)
attr(:rest, :global)
@ -88,7 +88,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do
attr(:billable_user, User, required: true)
attr(:current_user, User, required: true)
attr(:current_team, Plausible.Teams.Team, required: true)
attr(:current_team, :any, required: true)
attr(:limit, :integer, required: true)
attr(:resource, :string, required: true)
attr(:rest, :global)
@ -307,14 +307,14 @@ defmodule PlausibleWeb.Components.Billing.Notice do
end
attr(:current_user, :map)
attr(:current_team, :map)
attr(:current_team, :any)
attr(:billable_user, :map)
defp upgrade_call_to_action(assigns) do
team = Plausible.Teams.with_subscription(assigns.current_team)
upgrade_assistance_required? =
case Plans.get_subscription_plan(team.subscription) do
case Plans.get_subscription_plan(team && team.subscription) do
%Plausible.Billing.Plan{kind: :business} -> true
%Plausible.Billing.EnterprisePlan{} -> true
_ -> false

View File

@ -36,6 +36,7 @@ defmodule PlausibleWeb.Live.GoalSettings do
{:ok,
assign(socket,
current_team: socket.assigns.site.team,
site_id: site_id,
domain: domain,
displayed_goals: socket.assigns.all_goals,

View File

@ -1004,6 +1004,20 @@ defmodule PlausibleWeb.SettingsControllerTest do
end
end
describe "GET /settings/api-keys" do
setup [:create_user, :log_in]
test "handles user without a team gracefully", %{conn: conn, user: user} do
user
|> team_of()
|> Repo.delete!()
conn = get(conn, Routes.settings_path(conn, :api_keys))
assert html_response(conn, 200)
end
end
describe "POST /settings/api-keys" do
setup [:create_user, :log_in]