Login: the /dev/mailbox notice only where that page exists

01f0c81 · Gabriel Morell · 2026-10-27 17:14

10 files +54 -3
Message
{commit_body(@commit)}

Files changed

modified lib/oh_my_ex_oh_ircd_web/live/user_live/login.ex
+8 −3
@@ -25,7 +25,7 @@ defmodule OhMyExOhIrcdWeb.UserLive.Login do
25 25 </.header>
26 26 </div>
27 27
28 − <div :if={local_mail_adapter?()} class="alert alert-info">
28 + <div :if={dev_mailbox?()} id="dev-mailbox-notice" class="alert alert-info">
29 29 <.icon name="hero-information-circle" class="size-6 shrink-0" />
30 30 <div>
31 31 <p>You are running the local mail adapter.</p>
@@ -128,7 +128,12 @@ defmodule OhMyExOhIrcdWeb.UserLive.Login do
128 128 |> push_navigate(to: ~p"/users/log-in")}
129 129 end
130 130
131 − defp local_mail_adapter? do
132 − Application.get_env(:oh_my_ex_oh_ircd, OhMyExOhIrcd.Mailer)[:adapter] == Swoosh.Adapters.Local
131 + # The notice points at /dev/mailbox, which only exists with dev_routes on
132 + # (the router mounts it then). Prod runs the local adapter too — no mailer
133 + # is configured there — so checking the adapter alone put a dead link on
134 + # the production login page.
135 + defp dev_mailbox? do
136 + Application.get_env(:oh_my_ex_oh_ircd, :dev_routes, false) and
137 + Application.get_env(:oh_my_ex_oh_ircd, OhMyExOhIrcd.Mailer)[:adapter] == Swoosh.Adapters.Local
133 138 end
134 139 end
added test/oh_my_ex_oh_ircd_web/live/user_live/login_mailbox_notice_test.exs
+46 −0
@@ -0,0 +1,46 @@
1 +defmodule OhMyExOhIrcdWeb.UserLive.LoginMailboxNoticeTest do
2 + @moduledoc """
3 + The login page's "see sent emails at /dev/mailbox" notice shows only
4 + where that page exists: the local mail adapter *and* dev routes. Prod
5 + runs the local adapter too, without dev routes, and used to show a link
6 + there that led nowhere.
7 +
8 + Not async: it changes application env the whole node reads.
9 + """
10 + use OhMyExOhIrcdWeb.ConnCase, async: false
11 +
12 + import Phoenix.LiveViewTest
13 +
14 + setup do
15 + mailer = Application.get_env(:oh_my_ex_oh_ircd, OhMyExOhIrcd.Mailer)
16 + dev_routes = Application.get_env(:oh_my_ex_oh_ircd, :dev_routes)
17 +
18 + Application.put_env(
19 + :oh_my_ex_oh_ircd,
20 + OhMyExOhIrcd.Mailer,
21 + Keyword.put(mailer, :adapter, Swoosh.Adapters.Local)
22 + )
23 +
24 + on_exit(fn ->
25 + Application.put_env(:oh_my_ex_oh_ircd, OhMyExOhIrcd.Mailer, mailer)
26 +
27 + if is_nil(dev_routes),
28 + do: Application.delete_env(:oh_my_ex_oh_ircd, :dev_routes),
29 + else: Application.put_env(:oh_my_ex_oh_ircd, :dev_routes, dev_routes)
30 + end)
31 + end
32 +
33 + test "hidden without dev routes, as in prod", %{conn: conn} do
34 + Application.put_env(:oh_my_ex_oh_ircd, :dev_routes, false)
35 + {:ok, lv, _html} = live(conn, ~p"/users/log-in")
36 +
37 + refute has_element?(lv, "#dev-mailbox-notice")
38 + end
39 +
40 + test "shown with dev routes, where /dev/mailbox exists", %{conn: conn} do
41 + Application.put_env(:oh_my_ex_oh_ircd, :dev_routes, true)
42 + {:ok, lv, _html} = live(conn, ~p"/users/log-in")
43 +
44 + assert has_element?(lv, "#dev-mailbox-notice a[href='/dev/mailbox']")
45 + end
46 +end

Parents: ad82ccd