mirror of
https://github.com/plausible/analytics.git
synced 2025-01-03 15:17:58 +03:00
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:
parent
b86c2e715f
commit
8b8040edc5
@ -199,6 +199,7 @@ 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)
|
||||
|
||||
site =
|
||||
if :super_admin in roles and Plausible.Auth.is_super_admin?(user.id) do
|
||||
Plausible.Sites.get_by_domain!(domain)
|
||||
else
|
||||
@ -206,6 +207,8 @@ defmodule Plausible.Teams.Adapter.Read.Sites do
|
||||
|> 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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user