Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try Elixir v1.18 #4930

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
erlang 27.0
elixir 1.17.1-otp-27
erlang 27.2
elixir 1.18.1-otp-27
nodejs 21.7.3
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# platform specific, it makes sense to build it in the docker

#### Builder
FROM hexpm/elixir:1.17.1-erlang-27.0-alpine-3.20.1 AS buildcontainer
FROM hexpm/elixir:1.18.1-erlang-27.2-alpine-3.20.1 AS buildcontainer

ARG MIX_ENV=ce

Expand Down
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
4 changes: 3 additions & 1 deletion lib/plausible/crm_extensions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ defmodule Plausible.CrmExtensions do
]
end

def javascripts(%{assigns: %{context: "billing", resource: "enterprise_plan", changeset: %{}}}) do
def javascripts(%{
assigns: %{context: "billing", resource: "enterprise_plan", changeset: %{}}
}) do
[
Phoenix.HTML.raw("""
<script type="text/javascript">
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've dropped the check entirely here?

Copy link
Contributor Author

@ruslandoga ruslandoga Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It can (probably) be left as is in the newer Elixir version. I dropped it here while fixing 1.18 warnings since it wasn't really doing anything.

if get_field(changeset, :page_path) do
delete_change(changeset, :currency)
else
changeset
Expand Down
6 changes: 2 additions & 4 deletions lib/plausible_release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ defmodule Plausible.Release do
]

def should_be_first_launch? do
on_ee do
false
else
not (_has_users? = Repo.exists?(Plausible.Auth.User))
if Plausible.ce?() do
not Repo.exists?(Plausible.Auth.User)
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/plausible_web/controllers/api/external_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ defmodule PlausibleWeb.Api.ExternalController do
conn
|> put_resp_header("x-plausible-dropped", "#{Enum.count(dropped)}")
|> put_status(400)
|> json(%{errors: Plausible.ChangesetHelpers.traverse_errors(first_invalid_changeset)})
|> json(%{
errors: Plausible.ChangesetHelpers.traverse_errors(first_invalid_changeset)
})
else
conn
|> put_resp_header("x-plausible-dropped", "#{Enum.count(dropped)}")
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
6 changes: 4 additions & 2 deletions lib/plausible_web/live/register_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ defmodule PlausibleWeb.Live.RegisterForm do
end

def render(assigns) do
assigns = assign(assigns, :ce?, ce?())

~H"""
<div class="mx-auto text-center dark:text-gray-300">
<h1 class="text-3xl font-black">
<%= if ce?() or @live_action == :register_from_invitation_form do %>
<%= if @ce? or @live_action == :register_from_invitation_form do %>
Register your <%= Plausible.product_name() %> account
<% else %>
Register your 30-day free trial
Expand Down Expand Up @@ -170,7 +172,7 @@ defmodule PlausibleWeb.Live.RegisterForm do
<% end %>

<% submit_text =
if ce?() or @invitation do
if @ce? or @invitation do
"Create my account"
else
"Start my free trial"
Expand Down
66 changes: 32 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,9 +715,20 @@ 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
end

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
29 changes: 18 additions & 11 deletions lib/plausible_web/plugs/maybe_disable_registration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ defmodule PlausibleWeb.Plugs.MaybeDisableRegistration do
end

def call(conn, _opts) do
disabled_for = List.wrap(conn.assigns.disable_registration_for)
cond do
Release.should_be_first_launch?() ->
conn

selfhost_config = Application.get_env(:plausible, :selfhost)
disable_registration = Keyword.fetch!(selfhost_config, :disable_registration)
first_launch? = Release.should_be_first_launch?()
disable_registration?() ->
conn
|> put_flash(:error, "Registration is disabled on this instance")
|> redirect(to: Routes.auth_path(conn, :login_form))
|> halt()

if not first_launch? and disable_registration in disabled_for do
conn
|> put_flash(:error, "Registration is disabled on this instance")
|> redirect(to: Routes.auth_path(conn, :login_form))
|> halt()
else
conn
true ->
conn
end
end

defp disable_registration? do
if Plausible.ce?() do
config = Application.get_env(:plausible, :selfhost)
disable_registration = Keyword.fetch!(config, :disable_registration)
disable_registration in [:invite_only, true]
end
end
end
25 changes: 11 additions & 14 deletions lib/plausible_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ defmodule PlausibleWeb.Router do
get("/swagger-ui", OpenApiSpex.Plug.SwaggerUI, path: "/api/plugins/spec/openapi")
end

scope "/v1/capabilities", PlausibleWeb.Plugins.API.Controllers, assigns: %{plugins_api: true} do
scope "/v1/capabilities", PlausibleWeb.Plugins.API.Controllers,
assigns: %{plugins_api: true} do
pipe_through([:plugins_api])
get("/", Capabilities, :index)
end
Expand Down Expand Up @@ -217,7 +218,8 @@ defmodule PlausibleWeb.Router do
get "/timeseries", ExternalStatsController, :timeseries
end

scope "/api/v2", PlausibleWeb.Api, assigns: %{api_scope: "stats:read:*", schema_type: :public} do
scope "/api/v2", PlausibleWeb.Api,
assigns: %{api_scope: "stats:read:*", schema_type: :public} do
pipe_through [:public_api, PlausibleWeb.Plugs.AuthorizePublicAPI]

post "/query", ExternalQueryApiController, :query
Expand Down Expand Up @@ -289,20 +291,15 @@ defmodule PlausibleWeb.Router do
pipe_through [:browser, :csrf]

scope alias: Live, assigns: %{connect_live_socket: true} do
pipe_through [PlausibleWeb.RequireLoggedOutPlug, :app_layout]

scope assigns: %{disable_registration_for: [:invite_only, true]} do
pipe_through PlausibleWeb.Plugs.MaybeDisableRegistration

live "/register", RegisterForm, :register_form, as: :auth
end
pipe_through [
PlausibleWeb.RequireLoggedOutPlug,
:app_layout,
PlausibleWeb.Plugs.MaybeDisableRegistration
]

scope assigns: %{
disable_registration_for: true,
dogfood_page_path: "/register/invitation/:invitation_id"
} do
pipe_through PlausibleWeb.Plugs.MaybeDisableRegistration
live "/register", RegisterForm, :register_form, as: :auth

scope assigns: %{dogfood_page_path: "/register/invitation/:invitation_id"} do
live "/register/invitation/:invitation_id", RegisterForm, :register_from_invitation_form,
as: :auth
end
Expand Down
Loading
Loading