From 2d2e03835a5a5fa9a9ef66fc574d0b65c01271db Mon Sep 17 00:00:00 2001 From: Nate Shoemaker Date: Mon, 6 Jan 2025 08:19:23 -0800 Subject: [PATCH] Organize code, update flash messages --- lib/nerves_hub/audit_logs/templates.ex | 13 +++++++++++++ lib/nerves_hub_web/live/devices/show.ex | 13 +++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/nerves_hub/audit_logs/templates.ex b/lib/nerves_hub/audit_logs/templates.ex index 29918e0bb..c33077970 100644 --- a/lib/nerves_hub/audit_logs/templates.ex +++ b/lib/nerves_hub/audit_logs/templates.ex @@ -1,5 +1,9 @@ defmodule NervesHub.AuditLogs.Templates do + alias NervesHub.Accounts.User alias NervesHub.AuditLogs + alias NervesHub.AuditLogs.AuditLog + alias NervesHub.Deployments.Deployment + alias NervesHub.Devices.Device require Logger @@ -38,4 +42,13 @@ defmodule NervesHub.AuditLogs.Templates do AuditLogs.audit!(device, device, description) Logger.info("[DeviceChannel] #{description}") end + + @spec audit_device_deployment_update(User.t(), Device.t(), Deployment.t()) :: AuditLog.t() + def audit_device_deployment_update(user, device, deployment) do + AuditLogs.audit!( + user, + device, + "#{user.name} set #{device.identifier}'s deployment to #{deployment.name}" + ) + end end diff --git a/lib/nerves_hub_web/live/devices/show.ex b/lib/nerves_hub_web/live/devices/show.ex index 879757020..54c592cef 100644 --- a/lib/nerves_hub_web/live/devices/show.ex +++ b/lib/nerves_hub_web/live/devices/show.ex @@ -1,10 +1,11 @@ defmodule NervesHubWeb.Live.Devices.Show do - alias NervesHub.Deployments use NervesHubWeb, :updated_live_view require Logger alias NervesHub.AuditLogs + alias NervesHub.AuditLogs.Templates + alias NervesHub.Deployments alias NervesHub.Devices alias NervesHub.Devices.Alarms alias NervesHub.Devices.Connections @@ -266,17 +267,12 @@ defmodule NervesHubWeb.Live.Devices.Show do ) do deployment = Enum.find(eligible_deployments, &(&1.id == String.to_integer(deployment_id))) device = Devices.update_deployment(device, deployment) - - AuditLogs.audit!( - user, - device, - "#{user.name} set #{device.identifier}'s deployment to #{deployment.name}" - ) + _ = Templates.audit_device_deployment_update(user, device, deployment) socket |> assign(:device, device) |> assign(:deployment, deployment) - |> put_flash(:info, "Deployment successfully set") + |> put_flash(:info, "Deployment successfully updated") |> noreply() end @@ -386,6 +382,7 @@ defmodule NervesHubWeb.Live.Devices.Show do socket |> assign(:device, device) |> assign(:deployment, nil) + |> put_flash(:info, "Device successfully removed from the deployment") |> noreply() end