From d63a56b1928e32daaf160d4a8f5f8c0a397c3eb9 Mon Sep 17 00:00:00 2001 From: Antonio Golfari Date: Thu, 29 Aug 2024 07:37:50 +0200 Subject: [PATCH] avoid standard config to be modified --- airscore/igc_parsing_config/_overide.yaml | 2 +- airscore/igc_parsing_config/smartphone.yaml | 2 +- airscore/igc_parsing_config/standard.yaml | 3 +- .../templates/users/igc_parsing_settings.html | 15 +++++---- airscore/user/views.py | 31 ++++++++++++------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/airscore/igc_parsing_config/_overide.yaml b/airscore/igc_parsing_config/_overide.yaml index 354e52aa..155c7404 100644 --- a/airscore/igc_parsing_config/_overide.yaml +++ b/airscore/igc_parsing_config/_overide.yaml @@ -1,5 +1,5 @@ owner: superuser -editable: False +editable: false description: Practically no checks, used to force acceptance of IGC file. # diff --git a/airscore/igc_parsing_config/smartphone.yaml b/airscore/igc_parsing_config/smartphone.yaml index 3788b2aa..f5b908bb 100644 --- a/airscore/igc_parsing_config/smartphone.yaml +++ b/airscore/igc_parsing_config/smartphone.yaml @@ -1,5 +1,5 @@ owner: superuser -editable: False +editable: false description: Very loose altitude checking settings. Use when there is no airspace checking and igc files may come from smartphones with poor quality GPSs that produce erroneous altitude readings. # diff --git a/airscore/igc_parsing_config/standard.yaml b/airscore/igc_parsing_config/standard.yaml index 2a483174..ad3d12d3 100644 --- a/airscore/igc_parsing_config/standard.yaml +++ b/airscore/igc_parsing_config/standard.yaml @@ -1,7 +1,6 @@ owner: stuartm editable: false -description: standard settings. Ideal for competitions using igc files from flight - instruments.-test +description: standard settings. Ideal for competitions using igc files from flight instruments. # # Flight validation parameters. diff --git a/airscore/templates/users/igc_parsing_settings.html b/airscore/templates/users/igc_parsing_settings.html index 5cb4063b..1524c158 100644 --- a/airscore/templates/users/igc_parsing_settings.html +++ b/airscore/templates/users/igc_parsing_settings.html @@ -12,11 +12,13 @@
{{configform.hidden_tag()}}
-
-
+

Setting: {{name}}

{{description}}
-
+ {% if not save %} +
This file is read only. You may save it as another file that you will then be able to edit
+ {% endif %} +

- {% endif%} - {% endif%} - +

diff --git a/airscore/user/views.py b/airscore/user/views.py index 041ad8df..3e46833d 100644 --- a/airscore/user/views.py +++ b/airscore/user/views.py @@ -1702,7 +1702,6 @@ def igc_parsing_config(filename: str): from trackUtils import read_igc_config_yaml, save_igc_config_yaml igc_config_form = IgcParsingConfigForm() filename += '.yaml' - save = True config = read_igc_config_yaml(filename) if request.method == 'GET': if config is None: @@ -1725,9 +1724,9 @@ def igc_parsing_config(filename: str): igc_config_form.min_time_for_bearing_change.data = config['min_time_for_bearing_change'] igc_config_form.min_time_for_thermal.data = config['min_time_for_thermal'] - if current_user.username == config['owner']: - save = True - if request.method == 'POST': + save = bool(config['editable']) if current_user.username == config['owner'] else False + + elif request.method == 'POST': config['description'] = igc_config_form.description.data config['min_fixes'] = igc_config_form.min_fixes.data config['max_seconds_between_fixes'] = igc_config_form.max_seconds_between_fixes.data @@ -1746,16 +1745,24 @@ def igc_parsing_config(filename: str): config['min_time_for_bearing_change'] = igc_config_form.min_time_for_bearing_change.data config['min_time_for_thermal'] = igc_config_form.min_time_for_thermal.data config['owner'] = current_user.username - if igc_config_form.save.data and current_user.username == config['owner']: - save_igc_config_yaml(filename, config) - flash("saved", category='info') + config['editable'] = True + if igc_config_form.save.data: + if not config['editable']: + flash("the file is read only", category='danger') + elif not current_user.username == config['owner']: + flash("you are not the owner of this file", category='danger') + else: + save_igc_config_yaml(filename, config) + flash("saved", category='info') + return jsonify(success=True) if igc_config_form.save_as.data and igc_config_form.new_name.data: - save_igc_config_yaml(igc_config_form.new_name.data + '.yaml', config) - flash("saved as " + igc_config_form.new_name.data, category='info') - return render_template('users/igc_parsing_settings.html', save=save, name=filename, - description=config['description'], configform=igc_config_form) + new_filename = igc_config_form.new_name.data + '.yaml' + save_igc_config_yaml(new_filename, config) + flash("saved as " + new_filename, category='info') + return render_template('users/igc_parsing_settings.html', save=config['editable'], name=new_filename[:-5], + description=config['description'], configform=igc_config_form) return render_template('users/igc_parsing_settings.html', save=save, name=filename[:-5], - description=config['description'], configform=igc_config_form) + description=config['description'], configform=igc_config_form) @blueprint.route('/_del_igc_config/', methods=['POST'])