Modify promise message after feedback.

Disable statsd logging in debug as it is more annoying than useful.
parent d6a95650
import datetime
import json
......@@ -13,3 +14,20 @@ class ResultEncoder(json.JSONEncoder):
if value.__cause__:
error['cause'] = self.default(value.__cause__)
return error
else:
return super(ResultEncoder, self).default(value)
class JSEncoder(json.JSONEncoder):
"""JSON encoder to serialize results to be consumed by Javascript web apps."""
def default(self, obj):
# convert python datetime objects into a standard parsable by javascript
if isinstance(obj, datetime.datetime):
return obj.isoformat()
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.timedelta):
return (datetime.datetime.min + obj).time().isoformat()
else:
return super(JSEncoder, self).default(obj)
......@@ -560,7 +560,7 @@ $(document).ready(function () {
mailto: document.head.querySelector("[name=mailto]").getAttribute('content'),
selected: null,
loading: false,
promises: false,
promise: false,
},
filters: {
// you cannot run filters in rawHtml, so this doesn't work.
......@@ -680,7 +680,8 @@ $(document).ready(function () {
vueReport.when = data.when;
vueReport.name = data.name;
vueReport.twitter_handle = data.twitter_handle;
vueReport.promises = data.promises;
vueReport.promise = data.promise;
// include id in anchor to allow url sharing
let newHash = 'report-' + OrganizationID;
$('a#report-anchor').attr('name', newHash)
......@@ -700,6 +701,9 @@ $(document).ready(function () {
return "<a role='button' class='btn btn-xs btn-info' target='_blank' href=\"https://twitter.com/intent/tweet?screen_name=" + twitter_handle + '&text=' + name + ' heeft alles op orde! 🌹&hashtags=' + name + ',win,faalkaart"><img src="/static/images/twitterwhite.png" width="14" /> Tweet!</a>';
}
}
},
formatDate: function(date){
return new Date(date).toISOString().substring(0, 10)
}
}
});
......
......@@ -312,14 +312,18 @@
Dit resultaat delen? {% verbatim %}<span v-html="create_twitter_link(name, twitter_handle, points)"></span>{% endverbatim %}<br />
<br />
{% trans "Data from" %}: {% verbatim %}{{ humanize(when) }}{% endverbatim %}<br />
{% trans "Points" %}: {% verbatim %}{{ points }}{% endverbatim %}<span v-if="promises">*</span>, {% trans "congratulations" %}!
{% trans "Points" %}: {% verbatim %}{{ points }}{% endverbatim %}<span v-if="promise"><strong>*</strong></span>, {% trans "congratulations" %}!
<br />
<br />
Gaat faalkaart niet ver genoeg? <a v-bind:href="'mailto:' + mailto + '?subject=Pentest%20aanvraag%20voor%20'+name+'&body=Beste Faalkaart,%0D%0A%0D%0AWij hebben interesse in een pentest op de outward-facing IT van onze organisatie. Kunnen jullie daar bij helpen?%0D%0A%0D%0AMet vriendelijke groet,%0D%0A%0D%0A'">Vraag hier een echte pentest aan.</a><br/>
Ontbreken er domeinen? <a v-bind:href="'mailto:' + mailto + '?subject=Nieuwe%20domeinen%20voor%20'+name+'&body=Beste Faalkaart,%0D%0A%0D%0AGraag de volgende domeinen toevoegen aan de kaart:%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0ATip: stuur een zonefile mee met alle domeinen.%0D%0A%0D%0AMet vriendelijke groet,%0D%0A%0D%0A'">Stuur hier domeinen in.</a><br/>
<br />
<div v-if="promises" id="promise">* Deze orgranisatie heeft contact opgenomen met Faalkaart en toegezegd om op korte termijn verandering door te voeren om de score te verbeteren. Faalkaart draait dagelijks nieuwe scans op alle organsaties en domeinen, de resultaten van deze veranderingen zullen dus binnenkort zichtbaar zijn.
{% verbatim %}
<div v-if="promise" id="promise"><strong>*</strong> Deze organisatie heeft op {{formatDate(promise.created_on)}} laten weten dat veranderingen zijn doorgevoerd.
De resultaten van deze verandering zullen uiterlijk {{formatDate(promise.expires_on)}} zichtbaar zijn. Faalkaart draait continu
geautomatiseerd scans. Elke cyclus bevat tienduizenden scans en kost daarom enkele dagen.
</div>
{% endverbatim %}
<br/>
{% verbatim %}
<div v-for="url in urls" class="perurl" v-bind:style="'background: linear-gradient(' + colorizebg(url.points) + ', white);'">
......
......@@ -16,6 +16,7 @@ from failmap_admin.map.models import OrganizationRating, UrlRating
from failmap_admin.organizations.models import Organization, Promise, Url
from .. import __version__
from ..app.common import JSEncoder
one_minute = 60
one_hour = 60 * 60
......@@ -92,7 +93,12 @@ def organization_report(request, organization_id, weeks_back=0):
'pk',
'twitter_handle').latest('organizationrating__when')
# latest replaced: order_by('-organizationrating__when')[:1].get()
promises = bool(Promise.objects.filter(organization_id=organization_id, expires_on__gt=datetime.now()).count())
# get the most recent non-expired 'promise'
promise = Promise.objects.filter(organization_id=organization_id, expires_on__gt=datetime.now())
promise = promise.order_by('-expires_on')
promise = promise.values('created_on', 'expires_on')
promise = promise.first()
report_json = """
{
......@@ -102,7 +108,7 @@ def organization_report(request, organization_id, weeks_back=0):
"rating": %s,
"when": "%s",
"calculation": %s,
"promises": %s
"promise": %s
}
"""
report_json = report_json % (
......@@ -112,7 +118,7 @@ def organization_report(request, organization_id, weeks_back=0):
r['organizationrating__rating'],
r['organizationrating__when'].isoformat(),
r['organizationrating__calculation'],
promises,
json.dumps(promise, cls=JSEncoder),
)
# print(report_json)
except Organization.DoesNotExist:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-12 11:49
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('organizations', '0019_promise'),
]
operations = [
migrations.AlterField(
model_name='promise',
name='created_on',
field=models.DateTimeField(blank=True, default=datetime.datetime.now, null=True),
),
migrations.AlterField(
model_name='promise',
name='expires_on',
field=models.DateTimeField(blank=True, help_text='When in the future this promise is expected to be fulfilled.', null=True),
),
migrations.AlterField(
model_name='promise',
name='notes',
field=models.TextField(blank=True, help_text='Context information about the promise (eg: ticket reference).', null=True),
),
]
......@@ -169,7 +169,10 @@ class Promise(models.Model):
"""Allow recording of organisation promises for improvement."""
organization = models.ForeignKey(Organization, on_delete=models.PROTECT)
notes = models.TextField(help_text="Context information about the promise (eg: ticket reference).")
notes = models.TextField(
blank=True,
null=True,
help_text="Context information about the promise (eg: ticket reference).")
created_on = models.DateTimeField(default=datetime.now, blank=True, null=True)
expires_on = models.DateTimeField(
......
......@@ -469,8 +469,7 @@ if DEBUG:
# send statsd metrics to debug_toolbar
STATSD_CLIENT = 'django_statsd.clients.toolbar'
except ImportError:
# send statsd metrics to logging
STATSD_CLIENT = 'django_statsd.clients.log'
pass
# is administrative backend enabled on this instance
ADMIN = bool(APPNAME == 'failmap-admin')
......
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