|
1 | 1 | from flask import ( |
2 | 2 | Blueprint, render_template, request, session, |
3 | | - redirect, url_for, flash, abort, current_app |
| 3 | + redirect, url_for, flash, abort, current_app, make_response |
4 | 4 | ) |
5 | 5 | from utils.results_loader import load_estimated_results_table, get_filter_options, ESTIMATED_FIELD_MAP |
6 | 6 | from routes.results import extract_query_params |
|
11 | 11 | estimated_bp = Blueprint("estimated", __name__) |
12 | 12 |
|
13 | 13 |
|
| 14 | +def _render_estimated_auth_required(): |
| 15 | + systems_info = get_all_systems_info() |
| 16 | + response = make_response(render_template( |
| 17 | + "estimated_results.html", |
| 18 | + rows=[], columns=[], |
| 19 | + authenticated=False, systems_info=systems_info, |
| 20 | + pagination={"page": 1, "per_page": 100, "total": 0, "total_pages": 1}, |
| 21 | + filter_options={"systems": [], "codes": [], "exps": []}, |
| 22 | + current_system=None, current_code=None, |
| 23 | + current_exp=None, current_per_page=100, |
| 24 | + )) |
| 25 | + response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" |
| 26 | + response.headers["Pragma"] = "no-cache" |
| 27 | + return response |
| 28 | + |
| 29 | + |
14 | 30 | # GET /estimated/ |
15 | 31 | @estimated_bp.route("/", methods=["GET"], strict_slashes=False) |
16 | 32 | def estimated_results(): |
17 | 33 | authenticated = session.get("authenticated", False) |
| 34 | + if not authenticated: |
| 35 | + return _render_estimated_auth_required() |
| 36 | + |
18 | 37 | email = session.get("user_email") |
19 | 38 |
|
20 | 39 | store = get_user_store() |
@@ -58,19 +77,24 @@ def estimated_results(): |
58 | 77 | field_map=ESTIMATED_FIELD_MAP, |
59 | 78 | ) |
60 | 79 | systems_info = get_all_systems_info() |
61 | | - return render_template( |
| 80 | + response = make_response(render_template( |
62 | 81 | "estimated_results.html", |
63 | 82 | rows=rows, columns=columns, |
64 | 83 | authenticated=authenticated, systems_info=systems_info, |
65 | 84 | pagination=pagination_info, filter_options=filter_options, |
66 | 85 | current_system=filter_system, current_code=filter_code, |
67 | 86 | current_exp=filter_exp, current_per_page=per_page, |
68 | | - ) |
| 87 | + )) |
| 88 | + response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" |
| 89 | + response.headers["Pragma"] = "no-cache" |
| 90 | + return response |
69 | 91 |
|
70 | 92 |
|
71 | 93 | # GET /estimated/<filename> |
72 | 94 | @estimated_bp.route("/<filename>") |
73 | 95 | def show_estimated_result(filename): |
| 96 | + if not session.get("authenticated", False): |
| 97 | + abort(403, "Authentication required to view estimated data") |
74 | 98 | estimated_dir = current_app.config["ESTIMATED_DIR"] |
75 | 99 | check_file_permission(filename, estimated_dir) |
76 | 100 | return load_result_file(filename, estimated_dir) |
0 commit comments