diff --git a/lib/plausible/auth/user_admin.ex b/lib/plausible/auth/user_admin.ex index 4e24f343ebf2..7c72ae2085fe 100644 --- a/lib/plausible/auth/user_admin.ex +++ b/lib/plausible/auth/user_admin.ex @@ -171,22 +171,21 @@ defmodule Plausible.Auth.UserAdmin do defp subscription_status(user) do team = user.my_team - cond do - team && team.subscription -> - status_str = - PlausibleWeb.SettingsView.present_subscription_status(team.subscription.status) - - if team.subscription.paddle_subscription_id do - {:safe, ~s(#{status_str})} - else - status_str - end - - Plausible.Teams.on_trial?(team) -> + if team && team.subscription do + status_str = + PlausibleWeb.SettingsView.present_subscription_status(team.subscription.status) + + if team.subscription.paddle_subscription_id do + {:safe, ~s(#{status_str})} + else + status_str + end + else + if Plausible.Teams.on_trial?(team) do "On trial" - - true -> + else "Trial expired" + end end end diff --git a/lib/plausible/goal/schema.ex b/lib/plausible/goal/schema.ex index 8f2e29febe01..3479a89aba28 100644 --- a/lib/plausible/goal/schema.ex +++ b/lib/plausible/goal/schema.ex @@ -112,7 +112,7 @@ defmodule Plausible.Goal do end defp maybe_drop_currency(changeset) do - if ee?() and get_field(changeset, :page_path) do + if get_field(changeset, :page_path) do delete_change(changeset, :currency) else changeset diff --git a/lib/plausible_web/live/components/verification.ex b/lib/plausible_web/live/components/verification.ex index 4513aae550d9..2fafc50e0da5 100644 --- a/lib/plausible_web/live/components/verification.ex +++ b/lib/plausible_web/live/components/verification.ex @@ -27,6 +27,8 @@ defmodule PlausibleWeb.Live.Components.Verification do attr(:awaiting_first_pageview?, :boolean, default: false) def render(assigns) do + assigns = assign(assigns, :ee?, Plausible.ee?()) + ~H"""
<.focus_box> @@ -102,7 +104,7 @@ defmodule PlausibleWeb.Live.Components.Verification do <:footer :if={@finished? and not @success?}> <.focus_list> - <:item :if={ee?() and @attempts >= 3}> + <:item :if={@ee? and @attempts >= 3}> Need further help with your installation? <.styled_link href="https://plausible.io/contact"> Contact us diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex index 377f9f711e66..a6afb4e8ea02 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -677,45 +677,32 @@ defmodule PlausibleWeb.Live.Sites do |> Enum.map(&check_limits(&1, user)) end - defp check_limits(%{role: :owner, site: site} = invitation, user) do - team = - case Plausible.Teams.get_by_owner(user) do - {:ok, team} -> team - _ -> nil - end + on_ee do + defp check_limits(%{role: :owner, site: site} = invitation, user) do + team = + case Plausible.Teams.get_by_owner(user) do + {:ok, team} -> team + _ -> nil + end - case ensure_can_take_ownership(site, team) do - :ok -> - check_features(invitation, team) + case ensure_can_take_ownership(site, team) do + :ok -> + check_features(invitation, team) - {:error, :no_plan} -> - %{invitation: invitation, no_plan: true} + {:error, :no_plan} -> + %{invitation: invitation, no_plan: true} - {:error, {:over_plan_limits, limits}} -> - limits = PlausibleWeb.TextHelpers.pretty_list(limits) - %{invitation: invitation, exceeded_limits: limits} + {:error, {:over_plan_limits, limits}} -> + limits = PlausibleWeb.TextHelpers.pretty_list(limits) + %{invitation: invitation, exceeded_limits: limits} + end end + + defdelegate ensure_can_take_ownership(site, team), to: Plausible.Teams.Invitations end defp check_limits(invitation, _), do: %{invitation: invitation} - defdelegate ensure_can_take_ownership(site, team), to: Plausible.Teams.Invitations - - def check_features(%{role: :owner, site: site} = invitation, team) do - case check_feature_access(site, team) do - :ok -> - %{invitation: invitation} - - {:error, {:missing_features, features}} -> - feature_names = - features - |> Enum.map(& &1.display_name()) - |> PlausibleWeb.TextHelpers.pretty_list() - - %{invitation: invitation, missing_features: feature_names} - end - end - on_ee do defp check_feature_access(site, new_team) do missing_features = @@ -728,10 +715,27 @@ defmodule PlausibleWeb.Live.Sites do {:error, {:missing_features, missing_features}} end end - else - defp check_feature_access(_site, _new_team) do - :ok + + defp check_features(%{role: :owner, site: site} = invitation, team) do + case check_feature_access(site, team) do + :ok -> + %{invitation: invitation} + + {:error, {:missing_features, features}} -> + feature_names = + features + |> Enum.map(& &1.display_name()) + |> PlausibleWeb.TextHelpers.pretty_list() + + %{invitation: invitation, missing_features: feature_names} + end end + + defp check_features(invitation, _team) do + %{invitation: invitation} + end + + end defp set_filter_text(socket, filter_text) do diff --git a/lib/plausible_web/plugs/authorize_public_api.ex b/lib/plausible_web/plugs/authorize_public_api.ex index 90f7acd00da1..77754ca9ba5b 100644 --- a/lib/plausible_web/plugs/authorize_public_api.ex +++ b/lib/plausible_web/plugs/authorize_public_api.ex @@ -134,30 +134,30 @@ defmodule PlausibleWeb.Plugs.AuthorizePublicAPI do end defp verify_site_access(api_key, site) do - team = - case Plausible.Teams.get_by_owner(api_key.user) do - {:ok, team} -> team - _ -> nil - end - - is_member? = Plausible.Teams.Memberships.site_member?(site, api_key.user) - is_super_admin? = Auth.is_super_admin?(api_key.user_id) + if Auth.is_super_admin?(api_key.user_id) do + :ok + else + team = + case Plausible.Teams.get_by_owner(api_key.user) do + {:ok, team} -> team + _ -> nil + end - cond do - is_super_admin? -> - :ok + is_member? = Plausible.Teams.Memberships.site_member?(site, api_key.user) - Sites.locked?(site) -> - {:error, :site_locked} + cond do + Sites.locked?(site) -> + {:error, :site_locked} - Plausible.Billing.Feature.StatsAPI.check_availability(team) !== :ok -> - {:error, :upgrade_required} + Plausible.Billing.Feature.StatsAPI.check_availability(team) !== :ok -> + {:error, :upgrade_required} - is_member? -> - :ok + is_member? -> + :ok - true -> - {:error, :invalid_api_key} + true -> + {:error, :invalid_api_key} + end end end diff --git a/lib/plausible_web/plugs/authorize_site_access.ex b/lib/plausible_web/plugs/authorize_site_access.ex index 4019fdfb9a90..d4c3a056c302 100644 --- a/lib/plausible_web/plugs/authorize_site_access.ex +++ b/lib/plausible_web/plugs/authorize_site_access.ex @@ -81,21 +81,22 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccess do get_site_with_role(conn, current_user, domain), {:ok, shared_link} <- maybe_get_shared_link(conn, site) do role = - cond do - membership_role -> - membership_role - - Plausible.Auth.is_super_admin?(current_user) -> - :super_admin + if Plausible.Auth.is_super_admin?(current_user) do + :super_admin + else + cond do + membership_role -> + membership_role - site.public -> - :public + site.public -> + :public - shared_link -> - :public + shared_link -> + :public - true -> - nil + true -> + nil + end end if role in allowed_roles do diff --git a/lib/plausible_web/templates/layout/_header.html.heex b/lib/plausible_web/templates/layout/_header.html.heex index 6ca73f09fe29..67394b917040 100644 --- a/lib/plausible_web/templates/layout/_header.html.heex +++ b/lib/plausible_web/templates/layout/_header.html.heex @@ -31,29 +31,33 @@ <%= cond do %> <% @conn.assigns[:current_user] -> %>
diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex index 33435af9ddbc..11d1a4cb606b 100644 --- a/lib/plausible_web/views/layout_view.ex +++ b/lib/plausible_web/views/layout_view.ex @@ -40,12 +40,15 @@ defmodule PlausibleWeb.LayoutView do end end - def logo_path(filename) do + logo_path = if ee?() do - Path.join("/images/ee/", filename) + "/images/ee/" else - Path.join("/images/ce/", filename) + "/images/ce/" end + + def logo_path(filename) do + Path.join(unquote(logo_path), filename) end def settings_tabs(conn) do