Skip to content

Commit

Permalink
update form for BBFC admin reporting; openrightsgroup/cmp-issues#215
Browse files Browse the repository at this point in the history
  • Loading branch information
dantheta committed Aug 24, 2019
1 parent 1a7fdd8 commit 868d0ff
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 29 deletions.
60 changes: 41 additions & 19 deletions BlockedFrontend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,34 +355,55 @@ def ispreports_escalate(id):
report = ISPReport(g.conn, id)
urlobj = report.get_url()

status = g.api.status_url(urlobj['url'])

results = [x for x in status['results'] if x['isp_active']]

blocks = [ block for block in results if results['status'] == 'blocked' ]
pastblocks = [ block for block in results if results['status'] == 'ok' and results['last_blocked_timestamp'] ]

email_text = render_template('bbfc_email.txt',
blocks=blocks,
url=urlobj['url'],
title=urlobj['title'],
pastblocks=pastblocks,
username=report['name'],
comment=report['message'])


g.conn.commit()
if report['status'] != 'rejected':
return "Cannot escalate report unless report has been rejected by ISP", 400
return render_template('ispreports_escalate.html',
report=report,
emailreply=report.get_final_reply(),
url=urlobj,
email_text=email_text
)

@admin_pages.route('/control/ispreports/escalate/<int:id>', methods=['POST'])
@check_admin
def ispreports_escalate_post(id):
pass
emailtext = request.form['emailtext']
report = ISPReport(g.conn, id)
urlobj = report.get_url()

req = {
'url': urlobj['url'],
'reporter': {
'name': "Blocked admin",
'email': "blocked@localhost",
},
'original_network': report['network_name'],
'message': emailtext,
'previous': request.form['previous'],
'additional_contact': request.form['additional_contact'],
'report_type': "unblock",
'date': get_timestamp(),
'send_updates': 0,
'allow_publish': 1,
'allow_contact': 1,
'networks': ["BBFC"],
'auth': {
'email': g.api.username,
'signature': '',
}
}

req['auth']['signature'] = g.api.sign(req, ['url','date'])
if current_app.config['DUMMY']:
# demo mode - don't really submit
logging.warn("Dummy mode: not really submitting")
data = {'verification_required': False, 'success': True}
else:
data = g.api.POST_JSON('ispreport/submit', req)

logging.info("Submission: %s", data)

return redirect(url_for('.ispreports'))


@admin_pages.route('/control/ispreports/unblocked/<int:id>')
Expand Down Expand Up @@ -458,7 +479,8 @@ def ispreports_view(url, network_name, msgid=None):
damage_categories=damage_categories,
report_damage_categories=urlobj.get_report_categories('damage'),
reporter_category=urlobj.get_reporter_category(),
verified= contact and contact['verified']
verified= contact and contact['verified'],
bbfc_report=ispreport.get_report_for("BBFC")
)


Expand Down
16 changes: 16 additions & 0 deletions BlockedFrontend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,22 @@ def get_contact(self):
q.close()
return row

def get_related(self):
"""Get all reports for the same URL"""
return ISPReport.select(self.conn, urlid=self['urllid'])

def get_reported_networks(self):
return [x['network_name'] for x in self.get_related()]

def get_report_for(self, network_name):
try:
return ISPReport.select_one(self.conn, urlid=self['urlid'], network_name=network_name)
except ObjectNotFound:
return None

def get_final_reply(self):
return ISPReportEmail(self.conn, self['resolved_email_id'])

class ISPReportEmail(DBObject):
TABLE = 'public.isp_report_emails'
FIELDS = [
Expand Down
22 changes: 14 additions & 8 deletions BlockedFrontend/templates/admin/bbfc_email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ Dear BBFC Content Administrator,

Please could you review:

{{ url }}
{{title}}
{{ url }}{% if title %}
{{ title }}
{%- endif %}

on behalf of {{ username }}.
on behalf of {{ username|trim }}.

This site is currently blocked on:

Network | Last checked | Category
---------------+----------------+----------------
{% for siteblock in blocks %}
{{ siteblock.network_name|lpad(14) }} | {{ siteblock.last_checked }} | {{ siteblock.category }}
Network | Last checked | Category
---------------+---------------------+----------------
{%- for siteblock in blocks %}
{{ siteblock.network_name|lpad(14) }} | {{ siteblock.status_timestamp }} | {{ siteblock.category }}
{% endfor %}

{{ username }} comments:

{{ comment }}

Reviewers notes:

<< add your comments here >>

Kind regards,

Blocked.org.uk administrators, on behalf of {{ username }}.
Blocked.org.uk administrators
on behalf of {{ username|trim }}.
6 changes: 6 additions & 0 deletions BlockedFrontend/templates/admin/ispreports_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ <h2>
</div>

{% if report.status == 'rejected' %}
{% if bbfc_report == None %}
<div style="margin-top: 2em">
<a class="btn btn-default btn-lg" href="{{ url_for('.ispreports_escalate', id=report.id) }}">Escalate to BBFC</a>
</div>
{% else %}
<div style=margin-top: 2em">
Request sent to BBFC on {{ bbfc_report.created }}
</div>
{% endif %}
{% endif %}

</div>
Expand Down
36 changes: 34 additions & 2 deletions BlockedFrontend/templates/admin/ispreports_escalate.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

{% set pagetitle = "ISP Report Admin: " + url.url + " on " + report.network_name %}

{% macro show_message(message) %}
{%- if message.is_multipart() -%}
{{ show_message(message.get_payload()[0]) }}
{%- else %}
{%- if message['content-transfer-encoding'] == 'base64' %}
{%- set msg=message.get_payload().decode('base64').decode('utf8','replace') %}
{%- elif message['content-transfer-encoding'] == 'quoted-printable' %}
{%- set msg=message.get_payload().decode('quoted-printable').decode('utf8','replace') %}
{%- else %}
{%- set msg=message.get_payload() %}
{%- endif %}
{%- for line in (msg|stripstyletag).splitlines() %}
{%- if (line|striptags).strip() %}
{{ line|striptags }}
{% endif %}
{%- endfor %}
{%- endif %}
{%- endmacro %}

{% block body %}

Expand All @@ -15,8 +33,22 @@ <h2>Escalate to BBFC</h2>
<div class="col-md-12">

<form method="POST" action="{{ url_for('.ispreports_escalate_post', id=report.id) }}">

<textarea rows="14" style="width: 100%; font-family: mono" name="emailtext">{{ email_text }}</textarea>
{{ forms.static_field('Mobile network operator', 'network_name', report.network_name) }}
{{ forms.static_field('Mobile network contacted', 'created', report.created|fmtime) }}
<h3>Mobile network response</h3>
{{ forms.static_field('Date', 'reply_created', emailreply.created|fmtime) }}

{{ forms.textarea_field('Reply','previous', show_message(emailreply.decode()), rows=8) }}

<h3>Additional contact information</h3>
{{ forms.textarea_field('Submitted by', 'additional_contact', "Request originally submitted by " + report.name + " (" + report.email) }}

<h3>Site details</h3>
{{ forms.static_field('URL','url', url.url) }}

<h3>Nature of complaint</h3>

<textarea rows="8" style="width: 100%; font-family: mono" name="emailtext">{{ email_text }}</textarea>
<div><input type="submit" value="Send" class="btn btn-default btn-lg" /></div>
</form>

Expand Down

0 comments on commit 868d0ff

Please sign in to comment.