Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all audit logging in templates #1709

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

elinol
Copy link
Contributor

@elinol elinol commented Dec 18, 2024

Moves all audit logging to the template module.

One exception is in the function Devices.update_device_with_audit/4 where the audit log description is passed via the updating action (like tag_devicefor example). I don't know if it's worth it adding this to templates, since the templates themselves (the description) are defined outside the templates module. Any input on this is welcomed!

@elinol elinol force-pushed the move-auditlogging-to-templates branch from 86a718e to 751fa5b Compare December 28, 2024 18:25
|> Multi.run(:audit_source, fn _, _ ->
AuditLogs.audit(user, source_product, description)
|> Multi.run(:audit, fn _, _ ->
Templates.audit_device_moved(user, device, product, source_product)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this approach is the best, it gets kind of nested with a Repo.transaction inside Templates.audit_device_moved, but at least the audits are moved to a centralised place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because all of this logic is encapsulated in Device.move/3 I'd argue that keeping the original implementation is fine. Centralizing logic is important when it's reused, but a one-off call, especially when all three audit logs use the same description, feels like an appropriate exception.

@@ -1091,6 +1070,7 @@ defmodule NervesHub.Devices do
{:ok, updated}

err ->
Logger.warning("Could not move device: #{inspect(err)}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be logged to sentry as well? @joshk

@elinol elinol force-pushed the move-auditlogging-to-templates branch from 751fa5b to ca603f7 Compare January 8, 2025 14:02
@elinol elinol marked this pull request as ready for review January 8, 2025 14:10

require Logger

### RESOURCE: DEVICE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module will continue to grow over time, what do you think about splitting this out into submodules organized by resource? NervesHub.AuditLogs.DeviceTemplates, NervesHub.AuditLogs.FirmwareTemplates etc.

|> Multi.run(:audit_source, fn _, _ ->
AuditLogs.audit(user, source_product, description)
|> Multi.run(:audit, fn _, _ ->
Templates.audit_device_moved(user, device, product, source_product)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because all of this logic is encapsulated in Device.move/3 I'd argue that keeping the original implementation is fine. Centralizing logic is important when it's reused, but a one-off call, especially when all three audit logs use the same description, feels like an appropriate exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants