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

Fix 'user' on batch tag operations when viewed via Audit Logs #506

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

davidfurey
Copy link
Member

@davidfurey davidfurey commented Jan 3, 2024

What does this change?

Batch tags were always logged as "default user" because a the logging function expected an implicit User object but the caller was expecting to provide an implicit String username.

This issue highlighted how easy it is for bugs to creep in with implicit parameters that have default values, so I have also removed the default value from all functions that have an implicit user(name): Option[String] parameter. In doing so I identified a few places where we could be logging username but weren't.

The bug report also mentioned duplicated audit log entries. We were logging batch tag operations when the Job was created and when the Step was carried out. I have removed the Step level logging.

Tested in CODE. Old audit entry shows "Default User", newer entry shows david.furey

Screenshot 2024-01-03 at 12 26 00

How to test

  • Deploy to CODE
  • Perform batch tag operation
  • Check that operation is only logged once
  • Check that operation is logged with your username rather than Default user

Batch tags are currently always logged as "default user" because this function never receives an implicit User object.

It feels unpleasant to add another implicit String parameter, since this means the function is effectively saying to its caller "Hey, do you have a string handy that I can pretend is a username?". It would be nicer if this was passed as a User object.

This issue also highlights how easy it is for bugs to creep in with implicit parameters that have default values.
@davidfurey davidfurey requested a review from a team January 3, 2024 11:01
Copy link
Contributor

@twrichards twrichards left a comment

Choose a reason for hiding this comment

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

awesome - thanks for doing this @davidfurey . all the code changes LGTM and I've had a quick look at CODE where you'd already deployed this branch and things seem to look correct (improved) 👏

@@ -34,15 +34,15 @@ object AppAudit extends Logging {
}
}

def reindexTags()(implicit username: Option[String] = None): AppAudit = {
def reindexTags()(implicit username: Option[String]): AppAudit = {
AppAudit("reindexTags", new DateTime(), username.getOrElse("default user"), "tag reindex started");
Copy link
Contributor

Choose a reason for hiding this comment

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

would unknown be better than default user?

This seems like a better label
@davidfurey davidfurey merged commit 615583c into main Jan 10, 2024
1 check passed
@davidfurey davidfurey deleted the batchtag-user-logging branch January 10, 2024 09:21
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