feat: migrate admin features to gettext

Migrates all admin-related flash messages to gettext for internationalization:
- Admin.UserLive.Index: user deletion messages
- Admin.OrgLive.Index: organization deletion messages
- UserAuth: impersonation start/stop messages

Adds Gettext backend and helpers import to UserAuth module to support translations.

All admin and auth tests passing (87 tests).
This commit is contained in:
Graham McIntire 2026-02-02 12:45:38 -06:00
parent 89a076fb67
commit a995e6283f
No known key found for this signature in database
4 changed files with 44 additions and 7 deletions

View file

@ -26,11 +26,11 @@ defmodule ToweropsWeb.Admin.OrgLive.Index do
{:ok, _} ->
{:noreply,
socket
|> put_flash(:info, "Organization deleted successfully")
|> put_flash(:info, t_admin("Organization deleted successfully"))
|> assign(:organizations, Admin.list_all_organizations())}
{:error, _} ->
{:noreply, put_flash(socket, :error, "Failed to delete organization")}
{:noreply, put_flash(socket, :error, t_admin("Failed to delete organization"))}
end
end

View file

@ -50,11 +50,11 @@ defmodule ToweropsWeb.Admin.UserLive.Index do
{:ok, _} ->
{:noreply,
socket
|> put_flash(:info, "User deleted successfully")
|> put_flash(:info, t_admin("User deleted successfully"))
|> assign(:users, Admin.list_all_users())}
{:error, _} ->
{:noreply, put_flash(socket, :error, "Failed to delete user")}
{:noreply, put_flash(socket, :error, t_admin("Failed to delete user"))}
end
end

View file

@ -10,9 +10,11 @@ defmodule ToweropsWeb.UserAuth do
- User session lifecycle (login, logout)
"""
use ToweropsWeb, :verified_routes
use Gettext, backend: ToweropsWeb.Gettext
import Phoenix.Controller
import Plug.Conn
import ToweropsWeb.GettextHelpers
alias Phoenix.LiveView
alias Towerops.Accounts
@ -832,7 +834,7 @@ defmodule ToweropsWeb.UserAuth do
# Prevent impersonating self
if target_user.id == superuser.id do
conn
|> put_flash(:error, "You cannot impersonate yourself.")
|> put_flash(:error, t_admin("You cannot impersonate yourself."))
|> redirect(to: ~p"/admin/users")
|> halt()
else
@ -854,7 +856,7 @@ defmodule ToweropsWeb.UserAuth do
|> put_session(:impersonating, true)
|> assign(:current_scope, Scope.for_impersonation(superuser, target_user))
|> maybe_set_default_organization(target_user)
|> put_flash(:info, "Now impersonating #{target_user.email}")
|> put_flash(:info, t_admin("Now impersonating %{email}", email: target_user.email))
|> redirect(to: ~p"/orgs")
end
end
@ -894,7 +896,7 @@ defmodule ToweropsWeb.UserAuth do
|> delete_session(:impersonating)
|> assign(:current_scope, Scope.for_user(superuser))
|> maybe_set_default_organization(superuser)
|> put_flash(:info, "Stopped impersonating")
|> put_flash(:info, t_admin("Stopped impersonating"))
|> redirect(to: redirect_path)
end

View file

@ -13,3 +13,38 @@
msgid ""
msgstr ""
"Language: en\n"
#: lib/towerops_web/live/admin/org_live/index.ex:33
#, elixir-autogen, elixir-format
msgid "Failed to delete organization"
msgstr ""
#: lib/towerops_web/live/admin/user_live/index.ex:57
#, elixir-autogen, elixir-format
msgid "Failed to delete user"
msgstr ""
#: lib/towerops_web/user_auth.ex:859
#, elixir-autogen, elixir-format
msgid "Now impersonating %{email}"
msgstr ""
#: lib/towerops_web/live/admin/org_live/index.ex:29
#, elixir-autogen, elixir-format
msgid "Organization deleted successfully"
msgstr ""
#: lib/towerops_web/user_auth.ex:899
#, elixir-autogen, elixir-format
msgid "Stopped impersonating"
msgstr ""
#: lib/towerops_web/live/admin/user_live/index.ex:53
#, elixir-autogen, elixir-format
msgid "User deleted successfully"
msgstr ""
#: lib/towerops_web/user_auth.ex:837
#, elixir-autogen, elixir-format
msgid "You cannot impersonate yourself."
msgstr ""