mirror of
https://github.com/plausible/analytics.git
synced 2025-01-08 19:17:06 +03:00
Split current_team
into site_team
and my_team
(#4881)
* Change TODO into NOTE * Split `current_team` into `site_team` and `my_team`
This commit is contained in:
parent
bec14ee77c
commit
76cf87427d
@ -31,6 +31,7 @@ defmodule PlausibleWeb.Live.FunnelSettings do
|
|||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
assign(socket,
|
assign(socket,
|
||||||
|
site_team: socket.assigns.site.team,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
displayed_funnels: socket.assigns.all_funnels,
|
displayed_funnels: socket.assigns.all_funnels,
|
||||||
setup_funnel?: false,
|
setup_funnel?: false,
|
||||||
|
@ -175,7 +175,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
|
|||||||
change_plan_link_text = change_plan_link_text(assigns)
|
change_plan_link_text = change_plan_link_text(assigns)
|
||||||
|
|
||||||
subscription =
|
subscription =
|
||||||
Plausible.Teams.Billing.get_subscription(assigns.current_team)
|
Plausible.Teams.Billing.get_subscription(assigns.my_team)
|
||||||
|
|
||||||
billing_details_expired =
|
billing_details_expired =
|
||||||
Subscription.Status.in?(subscription, [
|
Subscription.Status.in?(subscription, [
|
||||||
@ -225,14 +225,10 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
|
|||||||
|> assign(:confirm_message, losing_features_message(feature_usage_check))
|
|> assign(:confirm_message, losing_features_message(feature_usage_check))
|
||||||
|
|
||||||
~H"""
|
~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} />
|
<.change_plan_link {assigns} />
|
||||||
<% else %>
|
<% else %>
|
||||||
<PlausibleWeb.Components.Billing.paddle_button
|
<PlausibleWeb.Components.Billing.paddle_button user={@current_user} team={@my_team} {assigns}>
|
||||||
user={@current_user}
|
|
||||||
team={@current_team}
|
|
||||||
{assigns}
|
|
||||||
>
|
|
||||||
Upgrade
|
Upgrade
|
||||||
</PlausibleWeb.Components.Billing.paddle_button>
|
</PlausibleWeb.Components.Billing.paddle_button>
|
||||||
<% end %>
|
<% end %>
|
||||||
@ -264,18 +260,18 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
|
|||||||
defp check_usage_within_plan_limits(%{
|
defp check_usage_within_plan_limits(%{
|
||||||
available: true,
|
available: true,
|
||||||
usage: usage,
|
usage: usage,
|
||||||
current_team: current_team,
|
my_team: my_team,
|
||||||
plan_to_render: plan
|
plan_to_render: plan
|
||||||
}) do
|
}) do
|
||||||
# At this point, the user is *not guaranteed* to have a team,
|
# At this point, the user is *not guaranteed* to have a team,
|
||||||
# with ongoing trial.
|
# with ongoing trial.
|
||||||
trial_active_or_ended_recently? =
|
trial_active_or_ended_recently? =
|
||||||
not is_nil(current_team) and not is_nil(current_team.trial_expiry_date) and
|
not is_nil(my_team) and not is_nil(my_team.trial_expiry_date) and
|
||||||
Plausible.Teams.trial_days_left(current_team) >= -10
|
Plausible.Teams.trial_days_left(my_team) >= -10
|
||||||
|
|
||||||
limit_checking_opts =
|
limit_checking_opts =
|
||||||
cond do
|
cond do
|
||||||
current_team && current_team.allow_next_upgrade_override ->
|
my_team && my_team.allow_next_upgrade_override ->
|
||||||
[ignore_pageview_limit: true]
|
[ignore_pageview_limit: true]
|
||||||
|
|
||||||
trial_active_or_ended_recently? && plan.volume == "10k" ->
|
trial_active_or_ended_recently? && plan.volume == "10k" ->
|
||||||
|
@ -9,15 +9,15 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
plug PlausibleWeb.RequireAccountPlug
|
plug PlausibleWeb.RequireAccountPlug
|
||||||
|
|
||||||
def ping_subscription(%Plug.Conn{} = conn, _params) do
|
def 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?})
|
json(conn, %{is_subscribed: subscribed?})
|
||||||
end
|
end
|
||||||
|
|
||||||
def choose_plan(conn, _params) do
|
def 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) do
|
||||||
redirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))
|
redirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))
|
||||||
else
|
else
|
||||||
render(conn, "choose_plan.html",
|
render(conn, "choose_plan.html",
|
||||||
@ -28,12 +28,12 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_to_enterprise_plan(conn, _params) do
|
def upgrade_to_enterprise_plan(conn, _params) do
|
||||||
current_team = conn.assigns.current_team
|
my_team = conn.assigns.my_team
|
||||||
subscription = Plausible.Teams.Billing.get_subscription(current_team)
|
subscription = Plausible.Teams.Billing.get_subscription(my_team)
|
||||||
|
|
||||||
{latest_enterprise_plan, price} =
|
{latest_enterprise_plan, price} =
|
||||||
Plausible.Teams.Billing.latest_enterprise_plan_with_price(
|
Plausible.Teams.Billing.latest_enterprise_plan_with_price(
|
||||||
current_team,
|
my_team,
|
||||||
PlausibleWeb.RemoteIP.get(conn)
|
PlausibleWeb.RemoteIP.get(conn)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,9 +70,9 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def change_plan_preview(conn, %{"plan_id" => new_plan_id}) do
|
def change_plan_preview(conn, %{"plan_id" => new_plan_id}) do
|
||||||
current_team = conn.assigns.current_team
|
my_team = conn.assigns.my_team
|
||||||
current_user = conn.assigns.current_user
|
current_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
|
case preview_subscription(subscription, new_plan_id) do
|
||||||
{:ok, {subscription, preview_info}} ->
|
{:ok, {subscription, preview_info}} ->
|
||||||
@ -91,7 +91,7 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
extra: %{
|
extra: %{
|
||||||
message: msg,
|
message: msg,
|
||||||
new_plan_id: new_plan_id,
|
new_plan_id: new_plan_id,
|
||||||
current_team: current_team.id,
|
team_id: my_team.id,
|
||||||
user_id: current_user.id
|
user_id: current_user.id
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -103,9 +103,9 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def change_plan(conn, %{"new_plan_id" => new_plan_id}) do
|
def 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} ->
|
{:ok, _subscription} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(:success, "Plan changed successfully")
|
|> put_flash(:success, "Plan changed successfully")
|
||||||
@ -133,7 +133,7 @@ defmodule PlausibleWeb.BillingController do
|
|||||||
errors: inspect(e),
|
errors: inspect(e),
|
||||||
message: msg,
|
message: msg,
|
||||||
new_plan_id: new_plan_id,
|
new_plan_id: new_plan_id,
|
||||||
current_team: current_team.id,
|
team_id: my_team.id,
|
||||||
user_id: conn.assigns.current_user.id
|
user_id: conn.assigns.current_user.id
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -21,23 +21,23 @@ defmodule PlausibleWeb.SettingsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def subscription(conn, _params) do
|
def subscription(conn, _params) do
|
||||||
current_team = conn.assigns.current_team
|
my_team = conn.assigns.my_team
|
||||||
subscription = Teams.Billing.get_subscription(current_team)
|
subscription = Teams.Billing.get_subscription(my_team)
|
||||||
|
|
||||||
render(conn, :subscription,
|
render(conn, :subscription,
|
||||||
layout: {PlausibleWeb.LayoutView, :settings},
|
layout: {PlausibleWeb.LayoutView, :settings},
|
||||||
subscription: subscription,
|
subscription: subscription,
|
||||||
pageview_limit: Teams.Billing.monthly_pageview_limit(subscription),
|
pageview_limit: Teams.Billing.monthly_pageview_limit(subscription),
|
||||||
pageview_usage: Teams.Billing.monthly_pageview_usage(current_team),
|
pageview_usage: Teams.Billing.monthly_pageview_usage(my_team),
|
||||||
site_usage: Teams.Billing.site_usage(current_team),
|
site_usage: Teams.Billing.site_usage(my_team),
|
||||||
site_limit: Teams.Billing.site_limit(current_team),
|
site_limit: Teams.Billing.site_limit(my_team),
|
||||||
team_member_limit: Teams.Billing.team_member_limit(current_team),
|
team_member_limit: Teams.Billing.team_member_limit(my_team),
|
||||||
team_member_usage: Teams.Billing.team_member_usage(current_team)
|
team_member_usage: Teams.Billing.team_member_usage(my_team)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoices(conn, _params) do
|
def 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)
|
invoices = Plausible.Billing.paddle_api().get_invoices(subscription)
|
||||||
render(conn, :invoices, layout: {PlausibleWeb.LayoutView, :settings}, invoices: invoices)
|
render(conn, :invoices, layout: {PlausibleWeb.LayoutView, :settings}, invoices: invoices)
|
||||||
|
@ -155,7 +155,7 @@ defmodule PlausibleWeb.Site.MembershipController do
|
|||||||
|> Enum.into(%{})
|
|> Enum.into(%{})
|
||||||
|
|
||||||
def update_role_by_user(conn, %{"id" => user_id, "new_role" => new_role_str}) do
|
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.assigns
|
||||||
|
|
||||||
membership =
|
membership =
|
||||||
Membership |> Repo.get_by!(user_id: user_id, site_id: site.id) |> Repo.preload(:user)
|
Membership |> Repo.get_by!(user_id: user_id, site_id: site.id) |> Repo.preload(:user)
|
||||||
@ -164,9 +164,9 @@ defmodule PlausibleWeb.Site.MembershipController do
|
|||||||
|
|
||||||
can_grant_role? =
|
can_grant_role? =
|
||||||
if membership.user.id == current_user.id do
|
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
|
else
|
||||||
can_grant_role_to_other?(current_user_role, new_role)
|
can_grant_role_to_other?(site_role, new_role)
|
||||||
end
|
end
|
||||||
|
|
||||||
if can_grant_role? do
|
if can_grant_role? do
|
||||||
|
@ -14,19 +14,19 @@ defmodule PlausibleWeb.SiteController do
|
|||||||
|
|
||||||
def new(conn, params) do
|
def new(conn, params) do
|
||||||
flow = params["flow"] || PlausibleWeb.Flows.register()
|
flow = params["flow"] || PlausibleWeb.Flows.register()
|
||||||
current_team = conn.assigns.current_team
|
my_team = conn.assigns.my_team
|
||||||
|
|
||||||
render(conn, "new.html",
|
render(conn, "new.html",
|
||||||
changeset: Plausible.Site.changeset(%Plausible.Site{}),
|
changeset: Plausible.Site.changeset(%Plausible.Site{}),
|
||||||
site_limit: Plausible.Teams.Billing.site_limit(current_team),
|
site_limit: Plausible.Teams.Billing.site_limit(my_team),
|
||||||
site_limit_exceeded?: Plausible.Teams.Billing.ensure_can_add_new_site(current_team) != :ok,
|
site_limit_exceeded?: Plausible.Teams.Billing.ensure_can_add_new_site(my_team) != :ok,
|
||||||
form_submit_url: "/sites?flow=#{flow}",
|
form_submit_url: "/sites?flow=#{flow}",
|
||||||
flow: flow
|
flow: flow
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_site(conn, %{"site" => site_params}) do
|
def create_site(conn, %{"site" => site_params}) do
|
||||||
team = conn.assigns.current_team
|
team = conn.assigns.my_team
|
||||||
user = conn.assigns.current_user
|
user = conn.assigns.current_user
|
||||||
first_site? = Plausible.Teams.Billing.site_usage(team) == 0
|
first_site? = Plausible.Teams.Billing.site_usage(team) == 0
|
||||||
flow = conn.params["flow"]
|
flow = conn.params["flow"]
|
||||||
|
@ -53,7 +53,7 @@ defmodule PlausibleWeb.StatsController do
|
|||||||
def stats(%{assigns: %{site: site}} = conn, _params) do
|
def stats(%{assigns: %{site: site}} = conn, _params) do
|
||||||
site = Plausible.Repo.preload(site, :owner)
|
site = Plausible.Repo.preload(site, :owner)
|
||||||
stats_start_date = Plausible.Sites.stats_start_date(site)
|
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_admin
|
||||||
demo = site.domain == PlausibleWeb.Endpoint.host()
|
demo = site.domain == PlausibleWeb.Endpoint.host()
|
||||||
dogfood_page_path = if demo, do: "/#{site.domain}", else: "/:dashboard"
|
dogfood_page_path = if demo, do: "/#{site.domain}", else: "/:dashboard"
|
||||||
skip_to_dashboard? = conn.params["skip_to_dashboard"] == "true"
|
skip_to_dashboard? = conn.params["skip_to_dashboard"] == "true"
|
||||||
|
@ -31,7 +31,7 @@ defmodule PlausibleWeb.Live.AuthContext do
|
|||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> assign_new(:current_team, fn context ->
|
|> assign_new(:my_team, fn context ->
|
||||||
case context.current_user do
|
case context.current_user do
|
||||||
nil -> nil
|
nil -> nil
|
||||||
%{team_memberships: [%{team: team}]} -> team
|
%{team_memberships: [%{team: team}]} -> team
|
||||||
|
@ -22,16 +22,16 @@ defmodule PlausibleWeb.Live.ChoosePlan do
|
|||||||
|> Enum.map(& &1.site_id)
|
|> Enum.map(& &1.site_id)
|
||||||
end)
|
end)
|
||||||
|> assign_new(:usage, fn %{
|
|> assign_new(:usage, fn %{
|
||||||
current_team: current_team,
|
my_team: my_team,
|
||||||
pending_ownership_site_ids: pending_ownership_site_ids
|
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,
|
with_features: true,
|
||||||
pending_ownership_site_ids: pending_ownership_site_ids
|
pending_ownership_site_ids: pending_ownership_site_ids
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|> assign_new(:subscription, fn %{current_team: current_team} ->
|
|> assign_new(:subscription, fn %{my_team: my_team} ->
|
||||||
Plausible.Teams.Billing.get_subscription(current_team)
|
Plausible.Teams.Billing.get_subscription(my_team)
|
||||||
end)
|
end)
|
||||||
|> assign_new(:owned_plan, fn %{subscription: subscription} ->
|
|> assign_new(:owned_plan, fn %{subscription: subscription} ->
|
||||||
Plans.get_regular_plan(subscription, only_non_expired: true)
|
Plans.get_regular_plan(subscription, only_non_expired: true)
|
||||||
|
@ -8,7 +8,7 @@ defmodule PlausibleWeb.Live.CSVExport do
|
|||||||
|
|
||||||
# :not_mounted_at_router ensures we have already done auth checks in the controller
|
# :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
|
# 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 true
|
@impl true
|
||||||
def mount(:not_mounted_at_router, session, socket) do
|
def mount(:not_mounted_at_router, session, socket) do
|
||||||
%{
|
%{
|
||||||
|
@ -11,7 +11,7 @@ defmodule PlausibleWeb.Live.CSVImport do
|
|||||||
|
|
||||||
# :not_mounted_at_router ensures we have already done auth checks in the controller
|
# :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
|
# 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 true
|
@impl true
|
||||||
def mount(:not_mounted_at_router, session, socket) do
|
def mount(:not_mounted_at_router, session, socket) do
|
||||||
%{"site_id" => site_id, "storage" => storage} = session
|
%{"site_id" => site_id, "storage" => storage} = session
|
||||||
|
@ -36,7 +36,7 @@ defmodule PlausibleWeb.Live.GoalSettings do
|
|||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
assign(socket,
|
assign(socket,
|
||||||
current_team: socket.assigns.site.team,
|
site_team: socket.assigns.site.team,
|
||||||
site_id: site_id,
|
site_id: site_id,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
displayed_goals: socket.assigns.all_goals,
|
displayed_goals: socket.assigns.all_goals,
|
||||||
@ -61,7 +61,7 @@ defmodule PlausibleWeb.Live.GoalSettings do
|
|||||||
domain={@domain}
|
domain={@domain}
|
||||||
site={@site}
|
site={@site}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
site_team={@site_team}
|
||||||
existing_goals={@all_goals}
|
existing_goals={@all_goals}
|
||||||
goal={@form_goal}
|
goal={@form_goal}
|
||||||
on_save_goal={
|
on_save_goal={
|
||||||
|
@ -37,7 +37,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
event_name_options_count: length(assigns.event_name_options),
|
event_name_options_count: length(assigns.event_name_options),
|
||||||
event_name_options: Enum.map(assigns.event_name_options, &{&1, &1}),
|
event_name_options: Enum.map(assigns.event_name_options, &{&1, &1}),
|
||||||
current_user: assigns.current_user,
|
current_user: assigns.current_user,
|
||||||
current_team: assigns.current_team,
|
site_team: assigns.site_team,
|
||||||
domain: assigns.domain,
|
domain: assigns.domain,
|
||||||
selected_tab: selected_tab,
|
selected_tab: selected_tab,
|
||||||
tab_sequence_id: 0,
|
tab_sequence_id: 0,
|
||||||
@ -74,7 +74,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
f={f}
|
f={f}
|
||||||
suffix={@context_unique_id}
|
suffix={@context_unique_id}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
site_team={@site_team}
|
||||||
site={@site}
|
site={@site}
|
||||||
goal={@goal}
|
goal={@goal}
|
||||||
existing_goals={@existing_goals}
|
existing_goals={@existing_goals}
|
||||||
@ -117,7 +117,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
f={f}
|
f={f}
|
||||||
suffix={suffix(@context_unique_id, @tab_sequence_id)}
|
suffix={suffix(@context_unique_id, @tab_sequence_id)}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
site_team={@site_team}
|
||||||
site={@site}
|
site={@site}
|
||||||
existing_goals={@existing_goals}
|
existing_goals={@existing_goals}
|
||||||
goal_options={@event_name_options}
|
goal_options={@event_name_options}
|
||||||
@ -202,7 +202,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
attr(:f, Phoenix.HTML.Form)
|
attr(:f, Phoenix.HTML.Form)
|
||||||
attr(:site, Plausible.Site)
|
attr(:site, Plausible.Site)
|
||||||
attr(:current_user, Plausible.Auth.User)
|
attr(:current_user, Plausible.Auth.User)
|
||||||
attr(:current_team, Plausible.Teams.Team)
|
attr(:site_team, Plausible.Teams.Team)
|
||||||
attr(:suffix, :string)
|
attr(:suffix, :string)
|
||||||
attr(:existing_goals, :list)
|
attr(:existing_goals, :list)
|
||||||
attr(:goal_options, :list)
|
attr(:goal_options, :list)
|
||||||
@ -263,7 +263,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
f={@f}
|
f={@f}
|
||||||
site={@site}
|
site={@site}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
site_team={@site_team}
|
||||||
has_access_to_revenue_goals?={@has_access_to_revenue_goals?}
|
has_access_to_revenue_goals?={@has_access_to_revenue_goals?}
|
||||||
goal={@goal}
|
goal={@goal}
|
||||||
suffix={@suffix}
|
suffix={@suffix}
|
||||||
@ -287,7 +287,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
|
|||||||
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
||||||
billable_user={@site.owner}
|
billable_user={@site.owner}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
current_team={@site_team}
|
||||||
feature_mod={Plausible.Billing.Feature.RevenueGoals}
|
feature_mod={Plausible.Billing.Feature.RevenueGoals}
|
||||||
class="rounded-b-md"
|
class="rounded-b-md"
|
||||||
/>
|
/>
|
||||||
|
@ -26,6 +26,7 @@ defmodule PlausibleWeb.Live.PropsSettings do
|
|||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
assign(socket,
|
assign(socket,
|
||||||
|
site_team: socket.assigns.site.team,
|
||||||
site_id: site_id,
|
site_id: site_id,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
add_prop?: false,
|
add_prop?: false,
|
||||||
|
@ -31,10 +31,10 @@ defmodule PlausibleWeb.Live.Sites do
|
|||||||
end)
|
end)
|
||||||
|> assign_new(:needs_to_upgrade, fn %{
|
|> assign_new(:needs_to_upgrade, fn %{
|
||||||
current_user: current_user,
|
current_user: current_user,
|
||||||
current_team: current_team
|
my_team: my_team
|
||||||
} ->
|
} ->
|
||||||
Plausible.Teams.Users.owns_sites?(current_user, include_pending?: true) &&
|
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)
|
end)
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
@ -35,7 +35,7 @@ defmodule PlausibleWeb.AuthPlug do
|
|||||||
conn
|
conn
|
||||||
|> assign(:current_user, user)
|
|> assign(:current_user, user)
|
||||||
|> assign(:current_user_session, user_session)
|
|> assign(:current_user_session, user_session)
|
||||||
|> assign(:current_team, team)
|
|> assign(:my_team, team)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
conn
|
conn
|
||||||
|
@ -115,10 +115,10 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccess do
|
|||||||
owner: [subscription: Plausible.Users.last_subscription_query()]
|
owner: [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
|
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)
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
end
|
end
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
id="paddle-button"
|
id="paddle-button"
|
||||||
paddle_product_id={@latest_enterprise_plan.paddle_plan_id}
|
paddle_product_id={@latest_enterprise_plan.paddle_plan_id}
|
||||||
user={@current_user}
|
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">
|
<svg fill="currentColor" viewBox="0 0 20 20" class="inline w-4 h-4 mr-2">
|
||||||
<path
|
<path
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
<%= render("_flash.html", assigns) %>
|
<%= render("_flash.html", assigns) %>
|
||||||
<% end %>
|
<% 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
|
<Notice.active_grace_period
|
||||||
:if={Plausible.Auth.GracePeriod.active?(@current_team)}
|
:if={Plausible.Auth.GracePeriod.active?(@my_team)}
|
||||||
enterprise?={Plausible.Teams.Billing.enterprise_configured?(@current_team)}
|
enterprise?={Plausible.Teams.Billing.enterprise_configured?(@my_team)}
|
||||||
grace_period_end={grace_period_end(@current_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>
|
</div>
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
||||||
billable_user={@current_user}
|
billable_user={@current_user}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
current_team={@my_team}
|
||||||
feature_mod={Plausible.Billing.Feature.StatsAPI}
|
feature_mod={Plausible.Billing.Feature.StatsAPI}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<.filter_bar filtering_enabled?={false}>
|
<.filter_bar filtering_enabled?={false}>
|
||||||
<.button_link
|
<.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)}
|
href={Routes.settings_path(@conn, :new_api_key)}
|
||||||
>
|
>
|
||||||
New API Key
|
New API Key
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<:title>Delete Account</:title>
|
<:title>Delete Account</:title>
|
||||||
<:subtitle>Deleting your account removes all sites and stats you've collected</:subtitle>
|
<: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">
|
<.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.
|
Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.
|
||||||
</.notice>
|
</.notice>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-col items-center justify-between sm:flex-row sm:items-start">
|
<div class="flex flex-col items-center justify-between sm:flex-row sm:items-start">
|
||||||
<PlausibleWeb.Components.Billing.monthly_quota_box
|
<PlausibleWeb.Components.Billing.monthly_quota_box
|
||||||
team={@current_team}
|
team={@my_team}
|
||||||
subscription={@subscription}
|
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">
|
<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">
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
:if={Map.get(assigns, :is_at_limit, false)}
|
:if={Map.get(assigns, :is_at_limit, false)}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
billable_user={@site.owner}
|
billable_user={@site.owner}
|
||||||
current_team={@current_team}
|
current_team={@site_team}
|
||||||
limit={Map.get(assigns, :team_member_limit, 0)}
|
limit={Map.get(assigns, :team_member_limit, 0)}
|
||||||
resource="team members"
|
resource="team members"
|
||||||
/>
|
/>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<PlausibleWeb.Components.Billing.Notice.limit_exceeded
|
<PlausibleWeb.Components.Billing.Notice.limit_exceeded
|
||||||
:if={@site_limit_exceeded?}
|
:if={@site_limit_exceeded?}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
current_team={@my_team}
|
||||||
billable_user={@current_user}
|
billable_user={@current_user}
|
||||||
limit={@site_limit}
|
limit={@site_limit}
|
||||||
resource="sites"
|
resource="sites"
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
||||||
billable_user={@site.owner}
|
billable_user={@site.owner}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
current_team={@site_team}
|
||||||
feature_mod={Plausible.Billing.Feature.Funnels}
|
feature_mod={Plausible.Billing.Feature.Funnels}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<%= if @conn.assigns[:current_user_role] == :owner do %>
|
<%= if @conn.assigns[:site_role] == :owner do %>
|
||||||
<li
|
<li
|
||||||
class="select-none hover:bg-gray-100 dark:hover:bg-gray-900 text-red-600"
|
class="select-none hover:bg-gray-100 dark:hover:bg-gray-900 text-red-600"
|
||||||
role="option"
|
role="option"
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
<PlausibleWeb.Components.Billing.Notice.premium_feature
|
||||||
billable_user={@site.owner}
|
billable_user={@site.owner}
|
||||||
current_user={@current_user}
|
current_user={@current_user}
|
||||||
current_team={@current_team}
|
current_team={@site_team}
|
||||||
feature_mod={Plausible.Billing.Feature.Props}
|
feature_mod={Plausible.Billing.Feature.Props}
|
||||||
grandfathered?
|
grandfathered?
|
||||||
/>
|
/>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
Dashboard locked
|
Dashboard locked
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<%= case @conn.assigns[:current_user_role] do %>
|
<%= case @conn.assigns[:site_role] do %>
|
||||||
<% :owner -> %>
|
<% :owner -> %>
|
||||||
<div class="mt-3 text-gray-600 dark:text-gray-300 text-center">
|
<div class="mt-3 text-gray-600 dark:text-gray-300 text-center">
|
||||||
<p>
|
<p>
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
data-embedded={to_string(@conn.assigns[:embedded])}
|
data-embedded={to_string(@conn.assigns[:embedded])}
|
||||||
data-background={@conn.assigns[:background]}
|
data-background={@conn.assigns[:background]}
|
||||||
data-is-dbip={to_string(@is_dbip)}
|
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-flags={Jason.encode!(@flags)}
|
||||||
data-valid-intervals-by-period={
|
data-valid-intervals-by-period={
|
||||||
Plausible.Stats.Interval.valid_by_period(site: @site) |> Jason.encode!()
|
Plausible.Stats.Interval.valid_by_period(site: @site) |> Jason.encode!()
|
||||||
|
@ -131,7 +131,7 @@ defmodule PlausibleWeb.UserAuth do
|
|||||||
inner_join: u in assoc(us, :user),
|
inner_join: u in assoc(us, :user),
|
||||||
as: :user,
|
as: :user,
|
||||||
left_join: tm in assoc(u, :team_memberships),
|
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.
|
# Otherwise regular members will be limited by team owner in cases like deleting their own account.
|
||||||
on: tm.role != :guest,
|
on: tm.role != :guest,
|
||||||
left_join: t in assoc(tm, :team),
|
left_join: t in assoc(tm, :team),
|
||||||
|
@ -71,7 +71,7 @@ defmodule PlausibleWeb.LayoutView do
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
%{key: "Email Reports", value: "email-reports", icon: :envelope},
|
%{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}
|
%{key: "Danger Zone", value: "danger-zone", icon: :exclamation_triangle}
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
|
@ -230,7 +230,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do
|
|||||||
|
|
||||||
refute conn.halted
|
refute conn.halted
|
||||||
assert conn.assigns.site.id == site.id
|
assert conn.assigns.site.id == site.id
|
||||||
assert conn.assigns.current_user_role == :owner
|
assert conn.assigns.site_role == :owner
|
||||||
end
|
end
|
||||||
|
|
||||||
for role <- [:viewer, :editor] do
|
for role <- [:viewer, :editor] do
|
||||||
@ -248,7 +248,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do
|
|||||||
|
|
||||||
refute conn.halted
|
refute conn.halted
|
||||||
assert conn.assigns.site.id == site.id
|
assert conn.assigns.site.id == site.id
|
||||||
assert conn.assigns.current_user_role == unquote(role)
|
assert conn.assigns.site_role == unquote(role)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do
|
|||||||
|
|
||||||
refute conn.halted
|
refute conn.halted
|
||||||
assert conn.assigns.site.id == site.id
|
assert conn.assigns.site.id == site.id
|
||||||
assert conn.assigns.current_user_role == :super_admin
|
assert conn.assigns.site_role == :super_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
test "allows user based on website visibility (authenticated user)", %{conn: conn} do
|
test "allows user based on website visibility (authenticated user)", %{conn: conn} do
|
||||||
|
Loading…
Reference in New Issue
Block a user