changeset 60:c6e7175ff28c

Unify acknowledgments update/creation from forms
author Benoît Allard <benoit.allard@greenbone.net>
date Wed, 08 Oct 2014 11:58:33 +0200
parents 64403f1b424e
children 55b72057b066
files farol/controller.py farol/document.py farol/vulnerability.py
diffstat 3 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/farol/controller.py	Wed Oct 08 11:38:44 2014 +0200
+++ b/farol/controller.py	Wed Oct 08 11:58:33 2014 +0200
@@ -29,7 +29,7 @@
 
 from flask import request
 
-from farolluz.cvrf import CVRFNote
+from farolluz.cvrf import CVRFNote, CVRFAcknowledgment
 
 def update_note_from_request(note):
     note._type = request.form['type']
@@ -44,3 +44,17 @@
 
     return CVRFNote(request.form['type'], int(request.form['ordinal']),
                     request.form['note'], title, audience)
+
+def update_acknowledgment_from_request(ack):
+    ack._name = request.form['name'] or None
+    ack._organization = request.form['organization'] or None
+    ack._description = request.form['description'] or None
+    ack._url = request.form['url'] or None
+
+def create_acknowledgment_from_request():
+    ack = CVRFAcknowledgment()
+    ack._name = request.form['name'] or None
+    ack._organization = request.form['organization'] or None
+    ack._description = request.form['description'] or None
+    ack._url = request.form['url'] or None
+    return ack
--- a/farol/document.py	Wed Oct 08 11:38:44 2014 +0200
+++ b/farol/document.py	Wed Oct 08 11:58:33 2014 +0200
@@ -31,7 +31,8 @@
     CVRFAggregateSeverity)
 from farolluz.renderer import utcnow
 
-from .controller import update_note_from_request, create_note_from_request
+from .controller import (update_note_from_request, create_note_from_request,
+    update_acknowledgment_from_request, create_acknowledgment_from_request)
 from .session import document_required, get_current
 
 
@@ -243,10 +244,7 @@
     if request.method != 'POST':
         return render_template('document/edit_acknowledgment.j2', name=ack._name, organization=ack._organization, description=ack._description, url=ack._url, action='Update')
 
-    ack._name = request.form['name'] or None
-    ack._organization = request.form['organization'] or None
-    ack._description = request.form['description'] or None
-    ack._url = request.form['url'] or None
+    update_acknowledgment_from_request(ack)
     return redirect(url_for('.view'))
 
 @document.route('/acknowledgment/add', methods=['GET', 'POST'])
@@ -255,10 +253,6 @@
     if request.method != 'POST':
         return render_template('document/edit_acknowledgment.j2', action='Add')
 
-    ack = CVRFAcknowledgment()
-    ack._name = request.form['name'] or None
-    ack._organization = request.form['organization'] or None
-    ack._description = request.form['description'] or None
-    ack._url = request.form['url'] or None
+    ack = create_acknowledgment_from_request()
     get_current().addAcknowledgment(ack)
     return redirect(url_for('.view'))
--- a/farol/vulnerability.py	Wed Oct 08 11:38:44 2014 +0200
+++ b/farol/vulnerability.py	Wed Oct 08 11:58:33 2014 +0200
@@ -31,7 +31,8 @@
     CVRFProductStatus, CVRFCVSSSet, CVRFRemediation)
 from farolluz.renderer import utcnow
 
-from .controller import update_note_from_request, create_note_from_request
+from .controller import (update_note_from_request, create_note_from_request,
+    update_acknowledgment_from_request, create_acknowledgment_from_request)
 from .session import document_required, get_current
 
 
@@ -460,10 +461,7 @@
     if request.method != 'POST':
         return render_template('vulnerability/edit_acknowledgment.j2', ordinal=ordinal, name=ack._name, organization=ack._organization, description=ack._description, url=ack._url, action='Update')
 
-    ack._name = request.form['name'] or None
-    ack._organization = request.form['organization'] or None
-    ack._description = request.form['description'] or None
-    ack._url = request.form['url'] or None
+    update_acknowledgment_from_request(ack)
     return redirect(url_for('.view', ordinal=ordinal))
 
 @vulnerability.route('/<int:ordinal>/acknowledgment/add', methods=['GET', 'POST'])
@@ -472,10 +470,6 @@
     if request.method != 'POST':
         return render_template('vulnerability/edit_acknowledgment.j2', action='Add', ordinal=ordinal)
 
-    ack = CVRFAcknowledgment()
-    ack._name = request.form['name'] or None
-    ack._organization = request.form['organization'] or None
-    ack._description = request.form['description'] or None
-    ack._url = request.form['url'] or None
+    ack = create_acknowledgment_from_request()
     get_vuln(ordinal).addAcknowledgment(ack)
     return redirect(url_for('.view', ordinal=ordinal))

http://farol.wald.intevation.org