Skip to content

Commit

Permalink
fix ce_dev warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Dec 23, 2024
1 parent 5a1f36d commit 311d6e9
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 113 deletions.
27 changes: 13 additions & 14 deletions lib/plausible/auth/user_admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(<a href="#{manage_url(team.subscription)}">#{status_str}</a>)}
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(<a href="#{manage_url(team.subscription)}">#{status_str}</a>)}
else
status_str
end
else
if Plausible.Teams.on_trial?(team) do
"On trial"

true ->
else
"Trial expired"
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/goal/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/plausible_web/live/components/verification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<div id="progress-indicator">
<.focus_box>
Expand Down Expand Up @@ -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}>
<b>Need further help with your installation?</b>
<.styled_link href="https://plausible.io/contact">
Contact us
Expand Down
72 changes: 38 additions & 34 deletions lib/plausible_web/live/sites.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
38 changes: 19 additions & 19 deletions lib/plausible_web/plugs/authorize_public_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 13 additions & 12 deletions lib/plausible_web/plugs/authorize_site_access.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 26 additions & 22 deletions lib/plausible_web/templates/layout/_header.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,33 @@
<%= cond do %>
<% @conn.assigns[:current_user] -> %>
<ul class="flex items-center w-full sm:w-auto">
<li :if={
ee?() && @conn.assigns[:site] &&
Plausible.Auth.is_super_admin?(@conn.assigns[:current_user])
}>
<.styled_link
class="text-sm mr-6"
href={PlausibleWeb.Endpoint.url() <> "/crm/sites/site/#{@conn.assigns[:site].id}"}
new_tab={true}
>
CRM
</.styled_link>
</li>
<li
:if={ee?() and Plausible.Teams.on_trial?(@conn.assigns[:my_team])}
class="hidden mr-6 sm:block"
>
<.styled_link
class="text-sm text-yellow-900 dark:text-yellow-900 rounded px-3 py-2 rounded-md bg-yellow-100 dark:bg-yellow-100"
href={Routes.settings_path(@conn, :subscription)}
<%= if ee?() do %>
<li :if={
@conn.assigns[:site] &&
Plausible.Auth.is_super_admin?(@conn.assigns[:current_user])
}>
<.styled_link
class="text-sm mr-6"
href={PlausibleWeb.Endpoint.url() <> "/crm/sites/site/#{@conn.assigns[:site].id}"}
new_tab={true}
>
CRM
</.styled_link>
</li>
<% end %>
<%= if ee?() do %>
<li
:if={Plausible.Teams.on_trial?(@conn.assigns[:my_team])}
class="hidden mr-6 sm:block"
>
<%= trial_notification(@conn.assigns[:my_team]) %>
</.styled_link>
</li>
<.styled_link
class="text-sm text-yellow-900 dark:text-yellow-900 rounded px-3 py-2 rounded-md bg-yellow-100 dark:bg-yellow-100"
href={Routes.settings_path(@conn, :subscription)}
>
<%= trial_notification(@conn.assigns[:my_team]) %>
</.styled_link>
</li>
<% end %>
<li class="w-full sm:w-auto">
<.dropdown>
<:button class="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800">
Expand Down
16 changes: 9 additions & 7 deletions lib/plausible_web/templates/site/settings_people.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
<span class="text-gray-500 dark:text-gray-400">
<%= membership.user.email %>
</span>
<.styled_link
:if={ee?() and Plausible.Auth.is_super_admin?(@current_user)}
new_tab={true}
href={PlausibleWeb.Endpoint.url() <> "/crm/auth/user/#{membership.user.id}"}
>
CRM
</.styled_link>
<%= if ee?() do %>
<.styled_link
:if={Plausible.Auth.is_super_admin?(@current_user)}
new_tab={true}
href={PlausibleWeb.Endpoint.url() <> "/crm/auth/user/#{membership.user.id}"}
>
CRM
</.styled_link>
<% end %>
</p>
</div>

Expand Down
9 changes: 6 additions & 3 deletions lib/plausible_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 311d6e9

Please sign in to comment.