changeset 16:eedf9606ab33

Add more error handling in the caching system
author Benoît Allard <benoit.allard@greenbone.net>
date Tue, 30 Sep 2014 15:12:25 +0200
parents f8d51aaac8bc
children deced0345829
files CHANGES farol/cache.py
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Tue Sep 30 14:45:03 2014 +0200
+++ b/CHANGES	Tue Sep 30 15:12:25 2014 +0200
@@ -4,17 +4,17 @@
 This is the first patch release of Farol 0.1, it fixes various issues, and
 improve usability.
 
-
 Thanks to all the contributors:
 Michael Wiegand and BenoƮt Allard.
 
 Main changes since 0.1:
 -----------------------
-* Ease the import of documents, with various shortcuts
-* Add a Welcome page
-* Add loging of the exceptions to a farol.log file (in the instance dir)
+* Ease the import of documents, with various shortcuts.
+* Add a Welcome page.
+* Add loging of the exceptions to a ``farol.log`` file (in the instance dir).
 * Implement three different kind of 'caching': disableds, global or
   session-based.
+* Various styling improvements.
 
 
 Farol 0.1 (2014-09-24)
--- a/farol/cache.py	Tue Sep 30 14:45:03 2014 +0200
+++ b/farol/cache.py	Tue Sep 30 15:12:25 2014 +0200
@@ -29,7 +29,7 @@
 import os
 
 from flask import (Blueprint, current_app, session, flash, redirect, url_for,
-    render_template, request)
+    render_template, request, abort)
 from werkzeug import secure_filename
 
 from farolluz.parsers.cvrf import parse
@@ -85,6 +85,10 @@
 @mod.route('/save', methods=['GET', 'POST'])
 @document_required
 def save():
+    if caching_type() is None:
+        current_app.logger.warning('Tried to save although caching is disabled.')
+        flash('This version does not allow you to save your document !', 'danger')
+        abort(403)
     if request.method != 'POST':
         return render_template('cache/save.j2',
                                id_=get_current()._tracking._identification._id)
@@ -108,7 +112,17 @@
         # Ouch, GET request changing state of the server ...
 
     dirname = _caching_dir()
+    element = secure_filename(element)
+    if dirname is None:
+        current_app.logger.warning('Tried to load something although no'
+            ' caching dir present: %s' % element)
+        flash('Not able to load %s' % element)
+        abort(404)
     fpath = os.path.join(dirname, element+'.xml')
+    if not os.path.exists(fpath):
+        current_app.logger.warning('Tried to load an unexisting document: %s' % element)
+        flash('Document %s does not exists !' % element)
+        abort(404)
     with open(fpath, 'rt') as f:
         set_current(parse(f))
     os.remove(fpath)

http://farol.wald.intevation.org