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

Findings dashboard for all organizations #4007

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

Conversation

madelondohmen
Copy link
Contributor

@madelondohmen madelondohmen commented Jan 7, 2025

Changes

This PR adds dashboards to OpenKAT.

In the frontend we've only added the Findings Dashboard to the Crisis Room of all organizations, but the backend is already ready to add all kinds of dashboards to both Crisis Rooms.

This PR adds:

  • DashboardData model
  • Automatically add a findings dashboard to a new organization
    • Including a ReportRecipe, based on a recipe_seeder
    • This ReportRecipe makes sure the Findings Dashboard is updated regularly
  • Use "make dashboard" to add dashboards to all existing organizations
  • Findings Report in Aggregate Report
  • Findings Report visible in Multi Report
  • Make template of Findings Report more generic
  • Only show the 5 most recent reports that have been generated when expanding the Scheduled Reports table

Issue link

Closes #3881

Demo

Opname.2025-01-07.102915.mp4

afbeelding

Aggregate Report:
afbeelding

QA notes

New organization

Create a new organization. Creating a new organization would automatically add this organization to the Findings Dashboard (which is shown in the Crisis Room for all organizations). Besides this, on the Scheduled Reports page there should be a ReportRecipe called "Crisis Room Aggregate Report". This should also create a report, which can be seen on the Report History page (this may take a minute). After the report has been created, the results of the report should be visible on the Crisis Room for all organizations. Please make sure that these two matches.

Existing organizations

Existing organizations also need their own dashboard. This can be done by using the command "make dashboard" in rocky. Please check if this adds the existing organizations to the Findings Dashboard (which is shown in the Crisis Room for all organizations).

Findings Report

The Findings Report should work as expected. Also, it should be possible to create a Aggregate and Multi Findings Report. Please check if this work as expected.


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.

Rieven and others added 30 commits November 25, 2024 17:51
…minvws/nl-kat-coordination into feature/findings-dashboard-for-all-orgs
…minvws/nl-kat-coordination into feature/findings-dashboard-for-all-orgs
…minvws/nl-kat-coordination into feature/findings-dashboard-for-all-orgs
…minvws/nl-kat-coordination into feature/findings-dashboard-for-all-orgs
@Rieven
Copy link
Contributor

Rieven commented Jan 14, 2025

  1. Newly added organisations don't show up on the crisis room page (thus an organisation created after completing the onboarding).

You have to run make dashboards again after adding the new organization. What we did before is that when a new organization is added the dashboard will be created, but just after creating a new dashboard no objects are added yet, the schedule will create empty reports with 0 objects. Then it came to be that the user decides when to create the dashboard.

For already existing organization it will update it:

image

@Rieven
Copy link
Contributor

Rieven commented Jan 14, 2025

  1. Running 'make dashboards' doesn't show the dashboards for the organisations (for a clean install on this PR with 2 already added organisations). (Corresponding logs are below)

Running make dashboards does not ensure that findings data is available for the organization. The recipe and schedule for every hour must have also input objects to generate findings when creating the findings report through the scheduler. We show only findings data that is available for the organization.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
67.4% Coverage on New Code (required ≥ 80%)
8.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@underdarknl underdarknl added this to the OpenKAT v1.19 milestone Jan 27, 2025
@Rieven
Copy link
Contributor

Rieven commented Feb 18, 2025

  1. Newly added organisations don't show up on the crisis room page (thus an organisation created after completing the onboarding).

You have to run make dashboards again after adding the new organization. What we did before is that when a new organization is added the dashboard will be created, but just after creating a new dashboard no objects are added yet, the schedule will create empty reports with 0 objects. Then it came to be that the user decides when to create the dashboard.

For already existing organization it will update it:

image

I have edited this, that both are possible. When a new org is added it creats the dashboard, and also when you already have orgs you can run the command. make dashboards to generate dashboards for existing orgs.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
77.2% Coverage on New Code (required ≥ 80%)
7.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

(
"dashboard",
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.SET_NULL, to="crisis_room.dashboard"
Copy link
Contributor

Choose a reason for hiding this comment

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

This can probably be a cascade, where the dashboarddata gets deleted when the dashboard gets deleted. Not just set to null. Null values are not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that the data can still exist after deleting the dashboard. So they can delete the dashboard and asign the data to another dashboard? i don't know if this was the intention. I see a possibility to re-asign data to another dashboard.



class DashboardData(models.Model):
dashboard = models.ForeignKey(Dashboard, on_delete=models.SET_NULL, null=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

null is not allowed. On_delete from a dashboard, the dashboardData should also be deleted. so cascade.

{% block content %}
{% include "header.html" %}

<main id="main-content" tabindex="-1" class="crisisroom">
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a tabindex on these?

@@ -9,6 +9,7 @@
<main id="main-content">
<section>
<div>
{{ member }}
Copy link
Contributor

Choose a reason for hiding this comment

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

debugging? I dont see it defined anywhere in the contexts?

@@ -25,6 +26,7 @@ <h1>{% translate "Crisis room" %} {{ organization.name }} @ {{ observed_at|date:
<p>
{% translate "An overview of the top 10 most severe findings OpenKAT found. Check the detail section for additional severity information." %}
</p>
{{ recipe_form_fields }}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here?


@register.filter
def get_first_seen(occurrences: dict) -> datetime:
first_seen_list = [datetime.fromisoformat(occurrence["first_seen"]) for occurrence in occurrences]
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets do a min on the occurences first, and Then transform to a date. thats cheaper. Also, we we have the occurrences sorted by the database, we can just take the first or last, and use that instead of looping.

<td>
<a href="{% ooi_url 'ooi_detail' occurrence.finding.ooi organization.code %}">{{ occurrence.finding.ooi|human_readable }}</a>
</td>
<td>{{ occurrence.first_seen|get_datetime }}</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also a template function to print '2 days ago', which we can use in conjunction with a title tag to add the 'raw utc' date for power users.

See for example: https://github.com/minvws/nl-kat-coordination/blob/d72a54acb2779591c009d6f8a97fe392ea20f215/rocky/rocky/templates/oois/ooi_detail_origins_observations.html#L49C32-L49C187

Copy link
Contributor

Choose a reason for hiding this comment

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

oeeh we can use that indeed, let me check

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.

Findings Report for all organizations in Crisis Room
5 participants