Commit d7e4fa59 authored by Elger Jonker's avatar Elger Jonker

determine which map layers can be reported, so a report can be made before it is displayed

Former-commit-id: 4174b6df
parent 8e5bdd5c
......@@ -177,7 +177,8 @@ def add_configuration(country, organization_type):
class ConfigurationAdmin(SortableAdminMixin, ImportExportModelAdmin, admin.ModelAdmin):
list_display = ('country', 'organization_type', 'is_displayed', 'is_the_default_option', 'is_scanned', )
list_display = ('country', 'organization_type', 'is_displayed', 'is_the_default_option', 'is_scanned',
search_fields = (['country', 'organization_type', ])
list_filter = ('country', 'organization_type', 'is_displayed', 'is_the_default_option', 'is_scanned',)
fields = ('country', 'organization_type', 'is_displayed', 'is_the_default_option', 'is_scanned', )
......@@ -220,6 +221,24 @@ class ConfigurationAdmin(SortableAdminMixin, ImportExportModelAdmin, admin.Model
stop_scanning.short_description = '💔 Stop scanning'
def allow_reporting(self, request, queryset):
for configuration in queryset:
configuration.is_reported = True
allow_reporting.short_description = '📄️ Allow Reporting'
def stop_reporting(self, request, queryset):
for configuration in queryset:
configuration.is_reported = False
stop_reporting.short_description = '📄 Stop Reporting'
def set_default(self, request, queryset):
for configuration in queryset:
# Generated by Django 2.1.3 on 2018-11-14 11:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('map', '0029_auto_20181029_0946'),
operations = [
field=models.BooleanField(default=False, help_text='Whether this combination is shown on the map.'),
......@@ -267,6 +267,11 @@ class Configuration(models.Model):
is_reported = models.BooleanField(
help_text="Whether this combination is shown on the map.",
is_the_default_option = models.BooleanField(
help_text="Determines if this is the default view. Only one can be selected to be displayed first. If there "
"are multiple, the first one is used. This can lead to unexpected results.",
......@@ -12,7 +12,7 @@ from django.db.models import Q
from import get_map_data
from failmap.organizations.models import Organization, OrganizationType, Url
from failmap.scanners.models import Endpoint, EndpointGenericScan, TlsQualysScan, UrlGenericScan
from failmap.scanners.scanner.scanner import q_configurations_to_display
from failmap.scanners.scanner.scanner import q_configurations_to_report
from ..celery import Task, app
from .calculate import get_calculation
......@@ -48,11 +48,14 @@ def compose_task(
if endpoints_filter:
raise NotImplementedError('This scanner does not work on a endpoint level.')"Organization filter: %s" % organizations_filter)"Url filter: %s" % urls_filter)
# Only displayed configurations are reported. Because why have reports on things you don't display?
# apply filter to organizations (or if no filter, all organizations)
organizations = Organization.objects.filter(q_configurations_to_display('organization'), **organizations_filter)
organizations = Organization.objects.filter(q_configurations_to_report('organization'), **organizations_filter)
log.debug("Organizations: %s" % len(organizations))
# Create tasks for rebuilding ratings for selected organizations and urls.
# Wheneven a url has been (re)rated the organization for that url need to
......@@ -64,7 +67,7 @@ def compose_task(
tasks = []
for organization in organizations:
urls = Url.objects.filter(q_configurations_to_display(), organization=organization, **urls_filter)
urls = Url.objects.filter(q_configurations_to_report(), organization=organization, **urls_filter)
if not urls:
......@@ -76,8 +79,8 @@ def compose_task(
log.error("Could not rebuild reports, filters resulted in no tasks created.")
log.debug("Organization filter: %s" % organizations_filter)
log.debug("Url filter: %s" % urls_filter)
log.debug("urls to display: %s" % q_configurations_to_display())
log.debug("organizatins to display: %s" % q_configurations_to_display('organization'))
log.debug("urls to display: %s" % q_configurations_to_report())
log.debug("organizatins to display: %s" % q_configurations_to_report('organization'))
raise Exception('Applied filters resulted in no tasks!')
# when trying to report on a specific url or organization (so not everything) also don't rebuild all caches
......@@ -91,6 +94,8 @@ def compose_task(
# the entire database. So this can just be two days as well.
days = 2
log.debug("Number of tasks: %s" % len(tasks))
# finally, rebuild the graphs (which can mis-matchi a bit if the last reports aren't in yet. Will have to do for now
# mainly as we're trying to get away from canvas and it's buggyness.
......@@ -103,6 +103,33 @@ def q_configurations_to_scan(level: str = 'url'):
return qs
def q_configurations_to_report(level: str = 'url'):
Retrieves configurations and makes q-queries for them. You can select if you want to have the q-queries directly
for the organization tables, or with a join from url to organization.
To evaluate: This is a quick fix, the organization might refer to configuration in the future?
An emtpy set means EVERYTHING will be reported.
:param level:
configurations = list(Configuration.objects.all().filter(is_reported=True).values('country', 'organization_type'))
qs = Q()
if level == 'organization':
for configuration in configurations:
qs.add(Q(type=configuration['organization_type'], country=configuration['country']), Q.OR)
if level == 'url':
for configuration in configurations:
organization__country=configuration['country']), Q.OR)
return qs
def q_configurations_to_display(level: str = 'url'):
Retrieves configurations and makes q-queries for them. You can select if you want to have the q-queries directly
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment