Skip to content

Commit

Permalink
Organize code, update flash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nshoes committed Jan 6, 2025
1 parent 04553a1 commit 2d2e038
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 13 additions & 0 deletions lib/nerves_hub/audit_logs/templates.ex
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
13 changes: 5 additions & 8 deletions lib/nerves_hub_web/live/devices/show.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2d2e038

Please sign in to comment.