Commit 6f333cfd authored by Johannes Schilling's avatar Johannes Schilling

web: check for internal-only flag for pdf files

this means pdfs are no longer served via SharedDataMiddleware, instead using a
regular route where we can check in the handler
parent 4f2fc667
......@@ -18,7 +18,6 @@ class Eva(object):
local.application = self
self.dispatch = SharedDataMiddleware(self.dispatch, {
'/static': config.staticdir,
'/public_pdf': config.pdfdir,
'/moderation/files': config.moddir
})
......
{% extends 'base.xml' %}
{% set title = 'Error' %}
{% block content %}
<h2>Fehler</h2>
Please register or sign in to reply
{{ error_text }}
{% endblock %}
......@@ -7,6 +7,8 @@ import json
from werkzeug import redirect
from werkzeug.exceptions import NotFound, BadRequest
from werkzeug.utils import redirect
from werkzeug.wrappers import Response
from werkzeug.wsgi import wrap_file
from backend.db import moderation_queue_db, public_pdf_db, deleted_db
......@@ -19,7 +21,9 @@ import config
from pprint import pprint
import datetime
from util.web import expose, render_template, profify, completion_hints, update_meta_from_request, theme_for_url, local
from util.web import expose, render_template, profify, completion_hints, \
update_meta_from_request, theme_for_url, local, get_remote_addr, \
remote_is_internal_network
from util.readMetaData import readMeta
from util.general import canonicalize_title, trim_pdf, empty_metadata
from util.univis import get_univis_metadata
......@@ -129,6 +133,27 @@ def show(request, document):
entry = entry,
theme = local.theme)
@expose('/public_pdf/<pdffile>')
def send_pdf_file(request, pdffile):
meta = public_pdf_db[pdffile.rstrip('.pdf')].metadata
is_internal = remote_is_internal_network(request)
## this uses a => b == !a v b, so what it wants to say is
## "if meta['internal_net_only'], _then_ we need is_internal to be true"
if not meta.get('internal_net_only', False) or is_internal:
return Response(wrap_file(request.environ, file(os.path.join(config.pdfdir, pdffile))),
mimetype='application/pdf',
direct_passthrough=True)
else:
return redirect('/internal_only')
@expose('/internal_only')
def error_internal_only(request):
return render_template('error.xml',
error_text='this file is available from the FAU internal network only',
Please register or sign in to reply
theme=local.theme)
@expose('/moderation/edit/')
def edit(request):
return overview(request, True)
......
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