Mercurial > farol > farol
annotate farol/document.py @ 64:aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 08 Oct 2014 14:28:29 +0200 |
parents | b4fb652484b4 |
children | f1705e90695b |
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, |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
26 url_for) |
0 | 27 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
28 from farolluz.parsers.cvrf import parseDate, parseVersion |
62
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
29 from farolluz.cvrf import (CVRFNote, CVRFReference, CVRFPublisher, |
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
30 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
|
31 CVRFAggregateSeverity) |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
32 from farolluz.renderer import utcnow |
0 | 33 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
34 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
|
35 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
|
36 update_acknowledgment_from_request, create_acknowledgment_from_request, |
b4fb652484b4
Define a split_fields function to split fields, and use it
Benoît Allard <benoit.allard@greenbone.net>
parents:
62
diff
changeset
|
37 split_fields) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
38 from .session import document_required, get_current |
0 | 39 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
40 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
41 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
|
42 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
43 @document.route('/') |
0 | 44 @document_required |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
45 def view(): |
0 | 46 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
|
47 return render_template('document/view.j2', cvrf=cvrf) |
0 | 48 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
49 @document.route('/title/edit', methods=['GET', 'POST']) |
0 | 50 @document_required |
51 def edit_title(): | |
52 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
|
53 return render_template('document/edit_title.j2', title = get_current()._title, _type = get_current()._type) |
0 | 54 |
55 | |
56 get_current()._title = request.form['title'] | |
57 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
|
58 return redirect(url_for('.view')) |
0 | 59 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
60 @document.route('/publisher/edit', methods=['GET', 'POST']) |
0 | 61 @document_required |
62 def edit_publisher(): | |
63 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
|
64 return render_template('document/edit_publisher.j2', publisher = get_current()._publisher or CVRFPublisher(''), types=CVRFPublisher.TYPES) |
0 | 65 |
66 publisher = CVRFPublisher(request.form['type'], request.form['vendorid'] or None) | |
67 publisher.setContact(request.form['contact'] or None) | |
68 publisher.setAuthority(request.form['authority'] or None) | |
69 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
|
70 return redirect(url_for('.view')) |
0 | 71 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
72 @document.route('/tracking/edit', methods=['GET', 'POST']) |
0 | 73 @document_required |
74 def edit_tracking(): | |
75 wasNone = False | |
76 tracking = get_current()._tracking | |
77 if tracking is None: | |
78 wasNone = True | |
79 tracking = CVRFTracking(CVRFTrackingID(''), 'Draft', (0,), utcnow(), utcnow()) | |
80 generator = tracking._generator | |
81 if not tracking._generator: | |
82 generator = CVRFGenerator() | |
83 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
|
84 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 | 85 |
86 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
|
87 aliases = split_fields(request.form['id_aliases']) |
0 | 88 tracking._identification._aliases = aliases |
89 tracking._status = request.form['status'] | |
90 tracking._version = parseVersion(request.form['version']) | |
91 tracking._initialDate = parseDate(request.form['initial']) | |
92 tracking._currentDate = parseDate(request.form['current']) | |
93 if wasNone: | |
94 get_current().setTracking(tracking) | |
95 if (not request.form['gen_engine']) and (not request.form['gen_date']): | |
96 generator = None | |
97 else: | |
98 generator._engine = request.form['gen_engine'] or None | |
99 if request.form['gen_date']: | |
100 generator._date = parseDate(request.form['gen_date']) | |
101 else: | |
102 generator._date = None | |
103 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
|
104 return redirect(url_for('.view')) |
0 | 105 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
106 @document.route('/revision/<int:index>/edit', methods=['GET', 'POST']) |
0 | 107 @document_required |
108 def edit_revision(index): | |
109 cvrf = get_current() | |
110 if cvrf._tracking is None: | |
111 abort(404) | |
112 try: | |
113 revision = cvrf._tracking._history[index] | |
114 except IndexError: | |
115 abort(404) | |
116 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
|
117 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 | 118 |
119 revision._number = parseVersion(request.form['number']) | |
120 revision._date = parseDate(request.form['date']) | |
121 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
|
122 return redirect(url_for('.view')) |
0 | 123 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
124 @document.route('/revision/add', methods=['GET', 'POST']) |
0 | 125 @document_required |
126 def add_revision(): | |
127 tracking = get_current()._tracking | |
128 if request.method != 'POST': | |
129 version = tracking._version | |
130 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
|
131 return render_template('document/edit_revision.j2', number='.'.join("%d"%v for v in version), date=utcnow(), action='Add') |
0 | 132 |
133 version = parseVersion(request.form['number']) | |
134 date = parseDate(request.form['date']) | |
135 revision = CVRFRevision(version, date, request.form['description']) | |
136 tracking.addRevision(revision) | |
137 if 'update_tracking' in request.form: | |
138 tracking._version = version | |
139 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
|
140 return redirect(url_for('.view')) |
0 | 141 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
142 @document.route('/distribution/edit', methods=['GET', 'POST']) |
0 | 143 @document_required |
144 def edit_distribution(): | |
145 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
|
146 return render_template('document/edit_distribution.j2', distribution=get_current()._distribution) |
0 | 147 |
148 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
|
149 return redirect(url_for('.view')) |
0 | 150 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
151 @document.route('/severity/edit', methods=['GET', 'POST']) |
0 | 152 @document_required |
153 def edit_severity(): | |
154 severity = get_current()._aggregateseverity | |
155 if severity is None: | |
156 severity = CVRFAggregateSeverity('') | |
157 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
|
158 return render_template('document/edit_severity.j2', severity=severity) |
0 | 159 if not request.form['severity']: |
160 severity = None | |
161 else: | |
162 severity._severity = request.form['severity'] | |
163 severity.setNamespace(request.form['namespace'] or None) | |
164 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
|
165 return redirect(url_for('.view')) |
0 | 166 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
167 @document.route('/note/<int:ordinal>') |
0 | 168 @document_required |
169 def view_note(ordinal): | |
170 note = get_current().getNote(ordinal) | |
171 if note is None: | |
172 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
173 return render_template('document/view_note.j2', note=note) |
0 | 174 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
175 @document.route('/note/<int:ordinal>/edit', methods=['GET', 'POST']) |
0 | 176 @document_required |
177 def edit_note(ordinal): | |
178 note = get_current().getNote(ordinal) | |
179 if note is None: | |
180 abort(404) | |
181 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
|
182 return render_template('document/edit_note.j2', note=note, types = note.TYPES) |
0 | 183 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
184 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
|
185 return redirect(url_for('.view_note', ordinal=note._ordinal )) |
0 | 186 |
187 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
188 @document.route('/note/add', methods=['GET', 'POST']) |
0 | 189 @document_required |
190 def add_note(): | |
191 if request.method != 'POST': | |
192 next_ordinal = 1 | |
193 notes = get_current()._notes | |
194 if notes: | |
195 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
|
196 return render_template('document/edit_note.j2', ordinal=next_ordinal, types=CVRFNote.TYPES, action='Add') |
0 | 197 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
198 note = create_note_from_request() |
0 | 199 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
|
200 return redirect(url_for('.view')) |
0 | 201 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
202 @document.route('/reference/<int:index>/edit', methods=['GET', 'POST']) |
0 | 203 @document_required |
204 def edit_reference(index): | |
205 try: | |
206 ref = get_current()._references[index] | |
207 except IndexError: | |
208 abort(404) | |
209 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
|
210 return render_template('document/edit_reference.j2', _type=ref._type, url=ref._url, description=ref._description, types=('',) + ref.TYPES) |
0 | 211 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
212 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
|
213 return redirect(url_for('.view')) |
0 | 214 |
215 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
216 @document.route('/reference/add', methods=['GET', 'POST']) |
0 | 217 @document_required |
218 def add_reference(): | |
219 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
|
220 return render_template('document/edit_reference.j2', action='Add', types=('',) + CVRFReference.TYPES) |
0 | 221 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
222 ref = create_reference_from_request() |
0 | 223 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
|
224 return redirect(url_for('.view')) |
0 | 225 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
226 @document.route('/acknowledgment/<int:index>') |
0 | 227 @document_required |
228 def view_acknowledgment(index): | |
229 try: | |
230 ack = get_current()._acknowledgments[index] | |
231 except IndexError: | |
232 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
233 return render_template('document/view_acknowledgment.j2', acknowledgment=ack, index=index, action='Update') |
0 | 234 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
235 @document.route('/acknowledgment/<int:index>/edit', methods=['GET', 'POST']) |
0 | 236 @document_required |
237 def edit_acknowledgment(index): | |
238 try: | |
239 ack = get_current()._acknowledgments[index] | |
240 except IndexError: | |
241 abort(404) | |
242 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
|
243 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
|
244 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
|
245 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
|
246 action='Update') |
0 | 247 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
248 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
|
249 return redirect(url_for('.view')) |
0 | 250 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
251 @document.route('/acknowledgment/add', methods=['GET', 'POST']) |
0 | 252 @document_required |
253 def add_acknowledgment(): | |
254 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
|
255 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
|
256 action='Add') |
0 | 257 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
258 ack = create_acknowledgment_from_request() |
0 | 259 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
|
260 return redirect(url_for('.view')) |