Skip to content

Commit

Permalink
Refactor Task List and filters with error handlers for Scheduler (#1957)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Klopper <[email protected]>
Co-authored-by: ammar92 <[email protected]>
Co-authored-by: JP Bruins Slot <[email protected]>
Co-authored-by: Jeroen Dekkers <[email protected]>
  • Loading branch information
5 people authored Jul 11, 2024
1 parent d77491e commit 0d6389a
Show file tree
Hide file tree
Showing 54 changed files with 1,383 additions and 1,320 deletions.
15 changes: 9 additions & 6 deletions docs/source/developer_documentation/rocky.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,18 @@ classDiagram
direction RL
class OrganizationView
class OctopoesView
class BoefjeMixin
class SchedulerView
class TaskListView
OctopoesView <|-- OrganizationView
BoefjeMixin <|-- OctopoesView
BoefjeDetailView <|-- BoefjeMixin
OOIDetailView <|-- BoefjeMixin
SchedulerView <|-- OctopoesView
TaskListView <|-- SchedulerView
BoefjeDetailView <|-- TaskListView
OOIDetailView <|-- TaskListView
OOIDetailView <|-- OOIRelatedObjectAddView
OOIDetailView <|-- OOIFindingManager
ChangeClearanceLevel <|-- BoefjeMixin
ChangeClearanceLevel <|-- SchedulerView
SingleOOIMixin <|-- OctopoesView
SingleOOITreeMixin <|-- SingleOOIMixin
Expand Down Expand Up @@ -300,13 +302,14 @@ direction RL
class PluginSettingsDeleteView
class BoefjeDetailView
class TaskListView
KATalogusView <|-- OrganizationView
KATalogusView <|-- FormView
SinglePluginView <|-- OrganizationView
SingleSettingView <|-- SinglePluginView
BoefjeDetailView <|-- PluginSettingsListView
BoefjeDetailView <|-- BoefjeMixin
BoefjeDetailView <|-- TaskListView
PluginEnableDisableView <|-- SinglePluginView
PluginSettingsAddView <|-- FormView
PluginSettingsAddView <|-- SinglePluginView
Expand Down
6 changes: 6 additions & 0 deletions rocky/account/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def get_context_data(self, **kwargs):
context["perms"] = OrganizationPermWrapper(self.organization_member)
return context

def indemnification_error(self):
return messages.error(
self.request,
f"Indemnification not present at organization {self.organization}.",
)

@property
def may_update_clearance_level(self) -> bool:
if not self.indemnification_present:
Expand Down
28 changes: 28 additions & 0 deletions rocky/assets/css/components/table-state-icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ table td .icon {
}
}

&.completed {
&::before {
content: "\ea67"; // $ti-icon-circle-check
color: var(--color-alert-positive);
}
}

&.negative {
&::before {
content: "\ea6a"; // $ti-icon-circle-x
color: var(--color-alert-negative);
}
}

&.failed {
&::before {
content: "\ea6a"; // $ti-icon-circle-x
color: var(--color-alert-negative);
}
}

&.incomplete {
&::before {
content: "\ea6a"; // $ti-icon-circle-x
Expand All @@ -68,13 +82,27 @@ table td .icon {
}
}

&.dispatched {
&::before {
content: "\ed27"; // $ti-icon-circle-dashed (should become ti-icon-progress, when we have it)
color: var(--color-alert-informative);
}
}

&.queued {
&::before {
content: "\ea70"; // $ti-icon-clock
color: var(--color-alert-warning);
}
}

&.pending {
&::before {
content: "\ea70"; // $ti-icon-clock
color: var(--color-alert-warning);
}
}

&.cancelled {
&::before {
content: "\ea05"; // $ti-icon-alert-circle
Expand Down
1 change: 1 addition & 0 deletions rocky/katalogus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_plugins(self, **params):
def get_plugin(self, plugin_id: str) -> Plugin:
response = self.session.get(f"{self.organization_uri}/plugins/{plugin_id}")
response.raise_for_status()

return parse_plugin(response.json())

def get_plugin_schema(self, plugin_id) -> dict | None:
Expand Down
4 changes: 2 additions & 2 deletions rocky/katalogus/templates/boefje_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1>{{ plugin.name }}</h1>
</div>
</section>
{% if perms.tools.can_view_katalogus_settings %}
{% include "plugin_settings_list.html" with object_list=object_list plugin=plugin %}
{% include "plugin_settings_list.html" with object_list=plugin_settings plugin=plugin %}

{% endif %}
<section>
Expand Down Expand Up @@ -73,7 +73,7 @@ <h2>{% translate "Produces" %}</h2>
</ul>
</p>
<p>
{% include "tasks/partials/boefje_task_history.html" %}
{% include "tasks/plugin_detail_task_list.html" %}

</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions rocky/katalogus/templates/normalizer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>{{ plugin.name }}</h1>
</div>
</section>
{% if perms.tools.can_view_katalogus_settings %}
{% include "plugin_settings_list.html" with object_list=object_list plugin=plugin %}
{% include "plugin_settings_list.html" with object_list=plugin_settings plugin=plugin %}

{% endif %}
<section>
Expand Down Expand Up @@ -74,7 +74,7 @@ <h2>{% translate "Produces" %}</h2>
{% endif %}
</p>
<p>
{% include "tasks/partials/normalizer_task_history.html" %}
{% include "tasks/plugin_detail_task_list.html" %}

</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion rocky/katalogus/templates/partials/objects_to_scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>{{ form_title }}</h2>
</p>
{% endif %}
{% if select_oois_form.fields.ooi.choices %}
{% include "partials/form/checkbox_group_table_form.html" with checkbox_group_table_form=select_oois_form btn_text="Start scan" plugin_enabled=plugin.enabled key="boefje_id" value=plugin.id action="scan" checkbox_group_table_filter_form=select_ooi_filter_form unique_id="" %}
{% include "partials/form/checkbox_group_table_form.html" with checkbox_group_table_form=select_oois_form btn_text="Start scan" plugin_enabled=plugin.enabled key="boefje_id" value=plugin.id action="scan_oois" checkbox_group_table_filter_form=select_ooi_filter_form unique_id="" %}

{% elif has_consumable_oois %}
{% blocktranslate trimmed with name=plugin.name %}
Expand Down
2 changes: 0 additions & 2 deletions rocky/katalogus/templates/plugin_settings_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ <h1>{{ plugin.type|title }}{% translate " Details" %}</h1>
{% csrf_token %}
<button type="submit">{% translate "Delete" %}</button>
</form>
{% include "partials/pagination.html" %}

</div>
</div>
</section>
Expand Down
5 changes: 3 additions & 2 deletions rocky/katalogus/views/change_clearance_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from katalogus.views.mixins import BoefjeMixin, SinglePluginView
from katalogus.views.mixins import SinglePluginView
from rocky.views.scheduler import SchedulerView


class ChangeClearanceLevel(OrganizationPermissionRequiredMixin, BoefjeMixin, SinglePluginView, TemplateView):
class ChangeClearanceLevel(OrganizationPermissionRequiredMixin, SchedulerView, SinglePluginView, TemplateView):
template_name = "change_clearance_level.html"
permission_required = "tools.can_set_clearance_level"

Expand Down
54 changes: 2 additions & 52 deletions rocky/katalogus/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@
from django.utils.translation import gettext_lazy as _
from httpx import HTTPError, HTTPStatusError
from rest_framework.status import HTTP_404_NOT_FOUND
from tools.view_helpers import schedule_task

from katalogus.client import Boefje as KATalogusBoefje
from katalogus.client import KATalogusClientV1, get_katalogus
from katalogus.client import Normalizer as KATalogusNormalizer
from octopoes.models import OOI
from rocky.scheduler import Boefje, BoefjeTask, Normalizer, NormalizerTask, PrioritizedItem, RawData
from rocky.views.mixins import OctopoesView
from katalogus.client import KATalogusClientV1, Plugin, get_katalogus

logger = getLogger(__name__)


class SinglePluginView(OrganizationView):
katalogus_client: KATalogusClientV1
plugin: KATalogusBoefje | KATalogusNormalizer
plugin: Plugin

def setup(self, request, *args, plugin_id: str, **kwargs):
"""
Expand Down Expand Up @@ -57,47 +51,3 @@ def is_required_field(self, field: str) -> bool:
def is_secret_field(self, field: str) -> bool:
"""Check whether this field should be secret, defaults to False."""
return bool(self.plugin_schema and field in self.plugin_schema.get("secret", []))


class NormalizerMixin(OctopoesView):
"""
When a user wants to run a normalizer on a given set of raw data,
this mixin provides the method to construct the normalizer task for that data and run it.
"""

def run_normalizer(self, normalizer: KATalogusNormalizer, raw_data: RawData) -> None:
normalizer_task = NormalizerTask(normalizer=Normalizer(id=normalizer.id, version=None), raw_data=raw_data)

task = PrioritizedItem(priority=1, data=normalizer_task)

schedule_task(self.request, self.organization.code, task)


class BoefjeMixin(OctopoesView):
"""
When a user wants to scan one or multiple OOI's,
this mixin provides the methods to construct the boefjes for the OOI's and run them.
"""

def run_boefje(self, katalogus_boefje: KATalogusBoefje, ooi: OOI | None) -> None:
boefje_task = BoefjeTask(
boefje=Boefje.model_validate(katalogus_boefje.model_dump()),
input_ooi=ooi.reference if ooi else None,
organization=self.organization.code,
)

task = PrioritizedItem(priority=1, data=boefje_task)
schedule_task(self.request, self.organization.code, task)

def run_boefje_for_oois(
self,
boefje: KATalogusBoefje,
oois: list[OOI],
) -> None:
if not oois and not boefje.consumes:
self.run_boefje(boefje, None)

for ooi in oois:
if ooi.scan_profile and ooi.scan_profile.level < boefje.scan_level:
self.can_raise_clearance_level(ooi, boefje.scan_level)
self.run_boefje(boefje, ooi)
Loading

0 comments on commit 0d6389a

Please sign in to comment.