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

Add time to observed_at #4227

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

Add time to observed_at #4227

wants to merge 9 commits into from

Conversation

Rieven
Copy link
Contributor

@Rieven Rieven commented Mar 27, 2025

Changes

  • At time to observed at to be more specific.
  • Now we set the time to end of day, while we need to fetch now time
  • Muted findings are now shown when filtering for muted findings.

Issue link

#4225

Closes #4225

Demo

image

QA notes

Mute a finding and then filter for "show muted findings"
You should see the muted finding in the list. Before this was not possible.


Code Checklist

  • All the commits in this PR are properly PGP-signed and verified.
  • This PR only contains functionality relevant to the issue.
  • I have written unit tests for the changes or fixes I made.
  • I have checked the documentation and made changes where necessary.
  • I have performed a self-review of my code and refactored it to the best of my abilities.
  • Tickets have been created for newly discovered issues.
  • For any non-trivial functionality, I have added integration and/or end-to-end tests.
  • I have informed others of any required .env changes files if required and changed the .env-dist accordingly.
  • I have included comments in the code to elaborate on what is not self-evident from the code itself, including references to issues and discussions online, or implicit behavior of an interface.

Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

Sorry, something went wrong.

@Rieven Rieven requested a review from a team as a code owner March 27, 2025 10:27
@Rieven Rieven self-assigned this Mar 27, 2025
Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

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

Just a few remarks, looks good otherwise

except ValueError:
messages.error(self.request, _("Can not parse date, falling back to show current date."))
return datetime.now(timezone.utc)
observed_at = datetime.fromisoformat(observed_at_string).replace(tzinfo=timezone.utc)
Copy link
Contributor

Choose a reason for hiding this comment

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

A minor optimization, but the problem here is in the case of a missing request parameter, you already have a ISO formatted UTC timestamp (due to line 86). Reparsing the already formatted string seems redundant. Another way to do this is (in pseudocode):

if "observed_at" in self.request.GET:
    observed_at = datetime.fromisoformat(self.request.GET['observed_at']).replace(tzinfo=timezone.utc)
else:
    observed_at = datetime.now(timezone.utc)

Comment on lines +108 to +109
context["observed_at"] = self.observed_at.strftime("%Y-%m-%d %H:%M")
context["observed_at_human_readable"] = self.observed_at.strftime("%B %d, %Y, %H:%M (%Z)")
Copy link
Contributor

@ammar92 ammar92 Mar 29, 2025

Choose a reason for hiding this comment

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

Since datetime formatting can be handled in the template, introducing two new variables for this looks redundant to me. I suggest applying formatting directly in the template instead

Comment on lines +168 to +169
context["observed_at"] = self.observed_at.strftime("%Y-%m-%d %H:%M")
context["observed_at_human_readable"] = self.observed_at.strftime("%B %d, %Y, %H:%M (%Z)")
Copy link
Contributor

Choose a reason for hiding this comment

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

See earlier comment

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.

Add time to observed at
2 participants