fix(portal): don't use Web functions from Domain (#10546)

Fixes an issue introduced in #10510 where Web functions (like
VerifiedRoutes) cannot be called from Domain because they are not
available in the release.

This happens to work in dev mode because everything is available under
the same dev context.
This commit is contained in:
Jamil
2025-10-13 13:24:46 -07:00
committed by GitHub
parent b61fd20de8
commit d329880ec8
5 changed files with 18 additions and 38 deletions

View File

@@ -93,4 +93,20 @@ defmodule Domain.Mailer do
Email.new()
|> Email.from({"Firezone Notifications", from_email})
end
def url(path, params \\ %{}) do
Domain.Config.fetch_env!(:domain, :web_external_url)
|> URI.parse()
|> URI.append_path(path)
|> maybe_append_query(params)
|> URI.to_string()
end
defp maybe_append_query(uri, params) do
if Enum.empty?(params) do
uri
else
URI.append_query(uri, URI.encode_query(params))
end
end
end

View File

@@ -77,20 +77,4 @@ defmodule Domain.Mailer.AuthEmail do
subject: subject
)
end
def url(path, params \\ %{}) do
Domain.Config.fetch_env!(:domain, :web_external_url)
|> URI.parse()
|> URI.append_path(path)
|> maybe_append_query(params)
|> URI.to_string()
end
def maybe_append_query(uri, params) do
if Enum.empty?(params) do
uri
else
URI.append_query(uri, URI.encode_query(params))
end
end
end

View File

@@ -7,9 +7,8 @@ defmodule Domain.Mailer.Notifications do
embed_templates "notifications/*.text", suffix: "_text"
def outdated_gateway_email(account, gateways, incompatible_client_count, email) do
url_generator = Application.fetch_env!(:domain, :url_generator)
outdated_clients_url = url_generator.outdated_clients_url(account.id)
outdated_clients_url =
url("/#{account.id}/clients", %{clients_order_by: "clients:asc:last_seen_version"})
default_email()
|> subject("Firezone Gateway Upgrade Available")

View File

@@ -1,17 +0,0 @@
defmodule Web.UrlGenerator do
@moduledoc """
Generates URLs for use in emails and other domain-layer notifications.
This breaks the circular dependency between Web and Domain apps.
"""
use Phoenix.VerifiedRoutes,
endpoint: Web.Endpoint,
router: Web.Router
@doc """
Generates URL for the clients page with outdated clients filter.
"""
def outdated_clients_url(account_id) do
url(~p"/#{account_id}/clients?#{[clients_order_by: "clients:asc:last_seen_version"]}")
end
end

View File

@@ -202,8 +202,6 @@ config :domain, outbound_email_adapter_configured?: false
config :domain, web_external_url: "http://localhost:13000"
config :domain, :url_generator, Web.UrlGenerator
###############################
##### Web #####################
###############################