more gettext
This commit is contained in:
parent
0d85e85884
commit
3633ff1626
5 changed files with 45 additions and 28 deletions
|
|
@ -1,6 +1,9 @@
|
|||
defmodule ToweropsWeb.AgentLive.Edit do
|
||||
@moduledoc false
|
||||
use ToweropsWeb, :live_view
|
||||
use Gettext, backend: ToweropsWeb.Gettext
|
||||
|
||||
import ToweropsWeb.GettextHelpers
|
||||
|
||||
alias Towerops.Agents
|
||||
alias Towerops.Agents.AgentToken
|
||||
|
|
@ -43,7 +46,7 @@ defmodule ToweropsWeb.AgentLive.Edit do
|
|||
{:ok, agent_token} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Agent updated successfully")
|
||||
|> put_flash(:info, t_equipment("Agent updated successfully"))
|
||||
|> push_navigate(to: ~p"/agents/#{agent_token.id}")}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
defmodule ToweropsWeb.AgentLive.Index do
|
||||
@moduledoc false
|
||||
use ToweropsWeb, :live_view
|
||||
use Gettext, backend: ToweropsWeb.Gettext
|
||||
|
||||
import ToweropsWeb.AgentLive.Helpers
|
||||
import ToweropsWeb.GettextHelpers
|
||||
|
||||
alias Towerops.Accounts.Scope
|
||||
alias Towerops.Agents
|
||||
|
|
@ -86,11 +88,13 @@ defmodule ToweropsWeb.AgentLive.Index do
|
|||
handle_agent_creation_success(socket, agent_token, token, is_cloud_poller)
|
||||
else
|
||||
{:error, :unauthorized} ->
|
||||
{:noreply, put_flash(socket, :error, "Only superadmins can create cloud pollers")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Only superadmins can create cloud pollers"))}
|
||||
|
||||
{:error, _changeset} ->
|
||||
error_message =
|
||||
if is_cloud_poller, do: "Failed to create cloud poller", else: "Failed to create agent"
|
||||
if is_cloud_poller,
|
||||
do: t_equipment("Failed to create cloud poller"),
|
||||
else: t_equipment("Failed to create agent")
|
||||
|
||||
{:noreply, put_flash(socket, :error, error_message)}
|
||||
end
|
||||
|
|
@ -131,14 +135,14 @@ defmodule ToweropsWeb.AgentLive.Index do
|
|||
|> assign(:agent_tokens, agent_tokens)
|
||||
|> assign(:new_token, %{agent_token: new_agent_token, token: token})
|
||||
|> assign(:show_token_modal, true)
|
||||
|> put_flash(:info, "New token generated successfully")}
|
||||
|> put_flash(:info, t_equipment("New token generated successfully"))}
|
||||
|
||||
{:error, _changeset} ->
|
||||
{:noreply, put_flash(socket, :error, "Failed to generate new token")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Failed to generate new token"))}
|
||||
end
|
||||
|
||||
{:error, _} ->
|
||||
{:noreply, put_flash(socket, :error, "Failed to revoke old token")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Failed to revoke old token"))}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -193,10 +197,13 @@ defmodule ToweropsWeb.AgentLive.Index do
|
|||
|> assign(:agent_health_stats, agent_health_stats)
|
||||
|> assign(:assignment_breakdown, assignment_breakdown)
|
||||
|> assign(:offline_agents, offline_agents)
|
||||
|> put_flash(:info, "Agent deleted successfully. Devices now fall back to site/org defaults or cloud polling.")}
|
||||
|> put_flash(
|
||||
:info,
|
||||
t_equipment("Agent deleted successfully. Devices now fall back to site/org defaults or cloud polling.")
|
||||
)}
|
||||
|
||||
{:error, _} ->
|
||||
{:noreply, put_flash(socket, :error, "Failed to delete agent")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Failed to delete agent"))}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -221,13 +228,14 @@ defmodule ToweropsWeb.AgentLive.Index do
|
|||
handle_global_default_success(socket, validated_id)
|
||||
|
||||
{:error, :agent_not_found} ->
|
||||
{:noreply, put_flash(socket, :error, "Selected agent no longer exists. Please choose another agent.")}
|
||||
{:noreply,
|
||||
put_flash(socket, :error, t_equipment("Selected agent no longer exists. Please choose another agent."))}
|
||||
|
||||
{:error, _} ->
|
||||
{:noreply, put_flash(socket, :error, "Failed to update global default cloud poller")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Failed to update global default cloud poller"))}
|
||||
end
|
||||
else
|
||||
{:noreply, put_flash(socket, :error, "Only superadmins can set the global default cloud poller")}
|
||||
{:noreply, put_flash(socket, :error, t_equipment("Only superadmins can set the global default cloud poller"))}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ defmodule ToweropsWeb.UserSettingsLive.ApiTokenManager do
|
|||
@moduledoc """
|
||||
Handles API token management for user settings.
|
||||
"""
|
||||
use Gettext, backend: ToweropsWeb.Gettext
|
||||
|
||||
import ToweropsWeb.GettextHelpers
|
||||
|
||||
alias Towerops.ApiTokens
|
||||
|
||||
|
|
@ -33,10 +36,10 @@ defmodule ToweropsWeb.UserSettingsLive.ApiTokenManager do
|
|||
|> assign_api_tokens()
|
||||
|
||||
{:error, _changeset} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to create API token.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to create API token."))
|
||||
end
|
||||
else
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Name and organization are required.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Name and organization are required."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -60,14 +63,14 @@ defmodule ToweropsWeb.UserSettingsLive.ApiTokenManager do
|
|||
case ApiTokens.delete_api_token(token) do
|
||||
{:ok, _} ->
|
||||
socket
|
||||
|> Phoenix.LiveView.put_flash(:info, "API token deleted successfully.")
|
||||
|> Phoenix.LiveView.put_flash(:info, t_auth("API token deleted successfully."))
|
||||
|> assign_api_tokens()
|
||||
|
||||
{:error, _} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to delete API token.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to delete API token."))
|
||||
end
|
||||
else
|
||||
Phoenix.LiveView.put_flash(socket, :error, "You can only delete your own tokens.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("You can only delete your own tokens."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -53,17 +53,17 @@ defmodule ToweropsWeb.UserSettingsLive.SessionManager do
|
|||
case Accounts.revoke_browser_session(session_id, user.id, current_token_id) do
|
||||
{:ok, _} ->
|
||||
socket
|
||||
|> Phoenix.LiveView.put_flash(:info, "Session revoked successfully.")
|
||||
|> Phoenix.LiveView.put_flash(:info, t_auth("Session revoked successfully."))
|
||||
|> assign_browser_sessions()
|
||||
|
||||
{:error, :self_revoke} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "You cannot revoke your current session.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("You cannot revoke your current session."))
|
||||
|
||||
{:error, :not_found} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Session not found.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Session not found."))
|
||||
|
||||
{:error, _} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to revoke session.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to revoke session."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ defmodule ToweropsWeb.UserSettingsLive.SessionManager do
|
|||
{count, _} = Accounts.revoke_all_other_sessions(user.id, current_token_id)
|
||||
|
||||
socket
|
||||
|> Phoenix.LiveView.put_flash(:info, "Revoked #{count} other session(s) successfully.")
|
||||
|> Phoenix.LiveView.put_flash(:info, t_auth("Revoked %{count} other session(s) successfully.", count: count))
|
||||
|> Phoenix.Component.assign(:show_revoke_all_modal, false)
|
||||
|> assign_browser_sessions()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ defmodule ToweropsWeb.UserSettingsLive.TotpManager do
|
|||
@moduledoc """
|
||||
Handles TOTP (Time-based One-Time Password) device and recovery code management.
|
||||
"""
|
||||
use Gettext, backend: ToweropsWeb.Gettext
|
||||
|
||||
import ToweropsWeb.GettextHelpers
|
||||
|
||||
alias Towerops.Accounts
|
||||
alias Towerops.Accounts.UserTotpDevice
|
||||
|
|
@ -38,7 +41,7 @@ defmodule ToweropsWeb.UserSettingsLive.TotpManager do
|
|||
|> Phoenix.Component.assign(:new_device_qr_code, qr_code)
|
||||
|
||||
{:error, _changeset} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to create device.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to create device."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -58,14 +61,14 @@ defmodule ToweropsWeb.UserSettingsLive.TotpManager do
|
|||
|> Towerops.Repo.update!()
|
||||
|
||||
socket
|
||||
|> Phoenix.LiveView.put_flash(:info, "Device added successfully!")
|
||||
|> Phoenix.LiveView.put_flash(:info, t_auth("Device added successfully!"))
|
||||
|> Phoenix.Component.assign(:show_device_qr_modal, false)
|
||||
|> Phoenix.Component.assign(:new_device_id, nil)
|
||||
|> Phoenix.Component.assign(:new_device_secret, nil)
|
||||
|> Phoenix.Component.assign(:new_device_qr_code, nil)
|
||||
|> assign_totp_devices()
|
||||
else
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Invalid code. Please try again.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Invalid code. Please try again."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -96,18 +99,18 @@ defmodule ToweropsWeb.UserSettingsLive.TotpManager do
|
|||
case Accounts.delete_totp_device(device_id, user.id) do
|
||||
{:ok, _} ->
|
||||
socket
|
||||
|> Phoenix.LiveView.put_flash(:info, "Device removed successfully.")
|
||||
|> Phoenix.LiveView.put_flash(:info, t_auth("Device removed successfully."))
|
||||
|> assign_totp_devices()
|
||||
|
||||
{:error, :last_device} ->
|
||||
Phoenix.LiveView.put_flash(
|
||||
socket,
|
||||
:error,
|
||||
"Cannot remove last device. You must have at least one."
|
||||
t_auth("Cannot remove last device. You must have at least one.")
|
||||
)
|
||||
|
||||
{:error, _} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to remove device.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to remove device."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -125,7 +128,7 @@ defmodule ToweropsWeb.UserSettingsLive.TotpManager do
|
|||
|> assign_recovery_codes_count()
|
||||
|
||||
{:error, _} ->
|
||||
Phoenix.LiveView.put_flash(socket, :error, "Failed to generate recovery codes.")
|
||||
Phoenix.LiveView.put_flash(socket, :error, t_auth("Failed to generate recovery codes."))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue