Mercurial > farol > farol
annotate farol/document.py @ 127:d49c1ee6bc07
Harden server-side version parsing
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Thu, 23 Oct 2014 16:50:02 +0200 |
parents | 5535ac5fef37 |
children | d2588d88d47a |
rev | line source |
---|---|
0 | 1 # -*- encoding: utf-8 -*- |
2 # Description: | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
3 # The Document Blueprint |
0 | 4 # |
5 # Authors: | |
6 # BenoƮt Allard <benoit.allard@greenbone.net> | |
7 # | |
8 # Copyright: | |
9 # Copyright (C) 2014 Greenbone Networks GmbH | |
10 # | |
11 # This program is free software; you can redistribute it and/or | |
12 # modify it under the terms of the GNU General Public License | |
13 # as published by the Free Software Foundation; either version 2 | |
14 # of the License, or (at your option) any later version. | |
15 # | |
16 # This program is distributed in the hope that it will be useful, | |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 # GNU General Public License for more details. | |
20 # | |
21 # You should have received a copy of the GNU General Public License | |
22 # along with this program; if not, write to the Free Software | |
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
24 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
25 from flask import (Blueprint, render_template, abort, redirect, request, |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
26 url_for, flash) |
0 | 27 |
62
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
28 from farolluz.cvrf import (CVRFNote, CVRFReference, CVRFPublisher, |
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
29 CVRFTracking, CVRFTrackingID, CVRFGenerator, CVRFRevision, |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
30 CVRFAggregateSeverity) |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
31 from farolluz.renderer import utcnow |
0 | 32 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
33 from .controller import (update_note_from_request, create_note_from_request, |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
34 update_reference_from_request, create_reference_from_request, |
63
b4fb652484b4
Define a split_fields function to split fields, and use it
Benoît Allard <benoit.allard@greenbone.net>
parents:
62
diff
changeset
|
35 update_acknowledgment_from_request, create_acknowledgment_from_request, |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
36 split_fields, parseDate, parseVersion) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
37 from .session import document_required, get_current |
0 | 38 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
39 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
40 document = Blueprint('document', __name__) |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
41 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
42 @document.route('/') |
0 | 43 @document_required |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
44 def view(): |
0 | 45 cvrf = get_current() |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
46 return render_template('document/view.j2', cvrf=cvrf) |
0 | 47 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
48 @document.route('/title/edit', methods=['GET', 'POST']) |
0 | 49 @document_required |
50 def edit_title(): | |
51 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
52 return render_template('document/edit_title.j2', title = get_current()._title, _type = get_current()._type) |
0 | 53 |
54 | |
55 get_current()._title = request.form['title'] | |
56 get_current()._type = request.form['type'] | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
57 return redirect(url_for('.view')) |
0 | 58 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
59 @document.route('/publisher/edit', methods=['GET', 'POST']) |
0 | 60 @document_required |
61 def edit_publisher(): | |
62 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
63 return render_template('document/edit_publisher.j2', publisher = get_current()._publisher or CVRFPublisher(''), types=CVRFPublisher.TYPES) |
0 | 64 |
65 publisher = CVRFPublisher(request.form['type'], request.form['vendorid'] or None) | |
66 publisher.setContact(request.form['contact'] or None) | |
67 publisher.setAuthority(request.form['authority'] or None) | |
68 get_current().setPublisher(publisher) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
69 return redirect(url_for('.view')) |
0 | 70 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
71 @document.route('/tracking/edit', methods=['GET', 'POST']) |
0 | 72 @document_required |
73 def edit_tracking(): | |
74 wasNone = False | |
75 tracking = get_current()._tracking | |
76 if tracking is None: | |
77 wasNone = True | |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
78 tracking = CVRFTracking(CVRFTrackingID(''), 'Draft', (0,0), utcnow(), utcnow()) |
0 | 79 generator = tracking._generator |
80 if not tracking._generator: | |
81 generator = CVRFGenerator() | |
82 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
83 return render_template('document/edit_tracking.j2', tracking=tracking, version='.'.join('%s'%v for v in tracking._version), generator=generator, now=utcnow(), statuses=tracking.STATUSES) |
0 | 84 |
85 tracking._identification._id = request.form['id'] | |
63
b4fb652484b4
Define a split_fields function to split fields, and use it
Benoît Allard <benoit.allard@greenbone.net>
parents:
62
diff
changeset
|
86 aliases = split_fields(request.form['id_aliases']) |
0 | 87 tracking._identification._aliases = aliases |
88 tracking._status = request.form['status'] | |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
89 version = parseVersion(request.form['version']) |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
90 if version is None: |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
91 flash('Cannot parse Version field: "%s"' % request.form['version'], 'warning') |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
92 else: |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
93 tracking._version = version |
0 | 94 tracking._initialDate = parseDate(request.form['initial']) |
95 tracking._currentDate = parseDate(request.form['current']) | |
96 if wasNone: | |
97 get_current().setTracking(tracking) | |
98 if (not request.form['gen_engine']) and (not request.form['gen_date']): | |
99 generator = None | |
100 else: | |
101 generator._engine = request.form['gen_engine'] or None | |
102 if request.form['gen_date']: | |
103 generator._date = parseDate(request.form['gen_date']) | |
104 else: | |
105 generator._date = None | |
106 tracking.setGenerator(generator) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
107 return redirect(url_for('.view')) |
0 | 108 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
109 @document.route('/revision/<int:index>/edit', methods=['GET', 'POST']) |
0 | 110 @document_required |
111 def edit_revision(index): | |
112 cvrf = get_current() | |
113 if cvrf._tracking is None: | |
114 abort(404) | |
115 try: | |
116 revision = cvrf._tracking._history[index] | |
117 except IndexError: | |
118 abort(404) | |
119 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
120 return render_template('document/edit_revision.j2', number='.'.join('%s'%v for v in revision._number), date=revision._date, description=revision._description, action='Update') |
0 | 121 |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
122 version = parseVersion(request.form['number']) |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
123 if version is None: |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
124 flash('Cannot parse Revision Number: %s' % request.form['number']) |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
125 else: |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
126 revision._number = version |
0 | 127 revision._date = parseDate(request.form['date']) |
128 revision._description = request.form['description'] | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
129 return redirect(url_for('.view')) |
0 | 130 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
131 @document.route('/revision/add', methods=['GET', 'POST']) |
0 | 132 @document_required |
133 def add_revision(): | |
134 tracking = get_current()._tracking | |
135 if request.method != 'POST': | |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
136 if tracking is None: |
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
137 flash('The tracking information should be set first to be able to add a revision.', 'danger') |
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
138 return redirect(url_for('.edit_tracking')) |
0 | 139 version = tracking._version |
140 version = version[:-1] + (version[-1] + 1,) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
141 return render_template('document/edit_revision.j2', number='.'.join("%d"%v for v in version), date=utcnow(), action='Add') |
0 | 142 |
143 version = parseVersion(request.form['number']) | |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
144 if version is None: |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
145 flash('Cannot parse Revision Number: "%s", assuming "0.0"' % request.form['number']) |
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
146 version = (0,0) |
0 | 147 date = parseDate(request.form['date']) |
148 revision = CVRFRevision(version, date, request.form['description']) | |
149 tracking.addRevision(revision) | |
150 if 'update_tracking' in request.form: | |
151 tracking._version = version | |
152 tracking._currentDate = date | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
153 return redirect(url_for('.view')) |
0 | 154 |
73 | 155 @document.route('/revision/<int:index>/del', methods=['POST']) |
67
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
156 @document_required |
73 | 157 def del_revision(index): |
68
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
158 history = get_current()._tracking._history |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
159 if not (0 <= index < len(history)): |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
160 flash('Revision not found', 'danger') |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
161 abort(404) |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
162 del history[index] |
67
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
163 return redirect(url_for('.view')) |
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
164 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
165 @document.route('/distribution/edit', methods=['GET', 'POST']) |
0 | 166 @document_required |
167 def edit_distribution(): | |
168 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
169 return render_template('document/edit_distribution.j2', distribution=get_current()._distribution) |
0 | 170 |
171 get_current().setDistribution(request.form['distribution']) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
172 return redirect(url_for('.view')) |
0 | 173 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
174 @document.route('/severity/edit', methods=['GET', 'POST']) |
0 | 175 @document_required |
176 def edit_severity(): | |
177 severity = get_current()._aggregateseverity | |
178 if severity is None: | |
179 severity = CVRFAggregateSeverity('') | |
180 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
181 return render_template('document/edit_severity.j2', severity=severity) |
0 | 182 if not request.form['severity']: |
183 severity = None | |
184 else: | |
185 severity._severity = request.form['severity'] | |
186 severity.setNamespace(request.form['namespace'] or None) | |
187 get_current().setAggregateSeverity(severity) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
188 return redirect(url_for('.view')) |
0 | 189 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
190 @document.route('/note/<int:ordinal>') |
0 | 191 @document_required |
192 def view_note(ordinal): | |
193 note = get_current().getNote(ordinal) | |
194 if note is None: | |
195 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
196 return render_template('document/view_note.j2', note=note) |
0 | 197 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
198 @document.route('/note/<int:ordinal>/edit', methods=['GET', 'POST']) |
0 | 199 @document_required |
200 def edit_note(ordinal): | |
201 note = get_current().getNote(ordinal) | |
202 if note is None: | |
203 abort(404) | |
204 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
205 return render_template('document/edit_note.j2', note=note, types = note.TYPES) |
0 | 206 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
207 update_note_from_request(note) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
208 return redirect(url_for('.view_note', ordinal=note._ordinal )) |
0 | 209 |
210 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
211 @document.route('/note/add', methods=['GET', 'POST']) |
0 | 212 @document_required |
213 def add_note(): | |
214 if request.method != 'POST': | |
215 next_ordinal = 1 | |
216 notes = get_current()._notes | |
217 if notes: | |
218 next_ordinal = notes[-1]._ordinal + 1 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
219 return render_template('document/edit_note.j2', ordinal=next_ordinal, types=CVRFNote.TYPES, action='Add') |
0 | 220 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
221 note = create_note_from_request() |
0 | 222 get_current().addNote(note) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
223 return redirect(url_for('.view')) |
0 | 224 |
73 | 225 @document.route('/note/<int:ordinal>/del', methods=['POST']) |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
226 @document_required |
73 | 227 def del_note(ordinal): |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
228 cvrf = get_current() |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
229 note = cvrf.getNote(ordinal) |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
230 if note is None: |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
231 flash('Note not found', 'danger') |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
232 abort(404) |
73 | 233 cvrf._notes.remove(note) |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
234 return redirect(url_for('.view')) |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
235 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
236 @document.route('/reference/<int:index>/edit', methods=['GET', 'POST']) |
0 | 237 @document_required |
238 def edit_reference(index): | |
239 try: | |
240 ref = get_current()._references[index] | |
241 except IndexError: | |
242 abort(404) | |
243 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
244 return render_template('document/edit_reference.j2', _type=ref._type, url=ref._url, description=ref._description, types=('',) + ref.TYPES) |
0 | 245 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
246 update_reference_from_request(ref) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
247 return redirect(url_for('.view')) |
0 | 248 |
249 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
250 @document.route('/reference/add', methods=['GET', 'POST']) |
0 | 251 @document_required |
252 def add_reference(): | |
253 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
254 return render_template('document/edit_reference.j2', action='Add', types=('',) + CVRFReference.TYPES) |
0 | 255 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
256 ref = create_reference_from_request() |
0 | 257 get_current().addReference(ref) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
258 return redirect(url_for('.view')) |
0 | 259 |
73 | 260 @document.route('/reference/<int:index>/del', methods=['POST']) |
72
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
261 @document_required |
73 | 262 def del_reference(index): |
72
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
263 refs = get_current()._references |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
264 if not (0 <= index < len(refs)): |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
265 flash('Reference not found', 'danger') |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
266 abort(404) |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
267 del refs[index] |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
268 return redirect(url_for('.view')) |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
269 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
270 @document.route('/acknowledgment/<int:index>') |
0 | 271 @document_required |
272 def view_acknowledgment(index): | |
273 try: | |
274 ack = get_current()._acknowledgments[index] | |
275 except IndexError: | |
276 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
277 return render_template('document/view_acknowledgment.j2', acknowledgment=ack, index=index, action='Update') |
0 | 278 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
279 @document.route('/acknowledgment/<int:index>/edit', methods=['GET', 'POST']) |
0 | 280 @document_required |
281 def edit_acknowledgment(index): | |
282 try: | |
283 ack = get_current()._acknowledgments[index] | |
284 except IndexError: | |
285 abort(404) | |
286 if request.method != 'POST': | |
64
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
287 return render_template('document/edit_acknowledgment.j2', |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
288 names=ack._names, organizations=ack._organizations, |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
289 description=ack._description, url=ack._url, |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
290 action='Update') |
0 | 291 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
292 update_acknowledgment_from_request(ack) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
293 return redirect(url_for('.view')) |
0 | 294 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
295 @document.route('/acknowledgment/add', methods=['GET', 'POST']) |
0 | 296 @document_required |
297 def add_acknowledgment(): | |
298 if request.method != 'POST': | |
64
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
299 return render_template('document/edit_acknowledgment.j2', |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
300 action='Add') |
0 | 301 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
302 ack = create_acknowledgment_from_request() |
0 | 303 get_current().addAcknowledgment(ack) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
304 return redirect(url_for('.view')) |
74
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
305 |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
306 @document.route('/acknowledgment/<int:index>/del', methods=['POST']) |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
307 @document_required |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
308 def del_acknowledgment(index): |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
309 acks = get_current()._acknowledgments |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
310 if not( 0 <= index < len(acks)): |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
311 flash('Acknowledgment not found', 'danger') |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
312 abort(404) |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
313 del acks[index] |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
314 return redirect(url_for('.view')) |