Skip to content

Commit

Permalink
Provide site-related team for current team in goal settings LV (plaus…
Browse files Browse the repository at this point in the history
…ible#4870)

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

* Make billing notice components accept nil current_team gracefully
  • Loading branch information
zoldar authored Dec 2, 2024
1 parent b86c2e7 commit 8b8040e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
17 changes: 10 additions & 7 deletions lib/plausible/teams/adapter/read/sites.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/plausible_web/components/billing/notice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/plausible_web/live/goal_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions test/plausible_web/controllers/settings_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 8b8040e

Please sign in to comment.