Skip to content

Commit

Permalink
avoid standard config to be modified
Browse files Browse the repository at this point in the history
  • Loading branch information
biuti committed Aug 29, 2024
1 parent 4000b6b commit d63a56b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion airscore/igc_parsing_config/_overide.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
owner: superuser
editable: False
editable: false
description: Practically no checks, used to force acceptance of IGC file.

#
Expand Down
2 changes: 1 addition & 1 deletion airscore/igc_parsing_config/smartphone.yaml
Original file line number Diff line number Diff line change
@@ -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.

#
Expand Down
3 changes: 1 addition & 2 deletions airscore/igc_parsing_config/standard.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 7 additions & 8 deletions airscore/templates/users/igc_parsing_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<form method='post' action=''>
{{configform.hidden_tag()}}
<div class='container'>
<br>
<center>
<p style="text-align:center;">
<h1>Setting: {{name}}</h1>
<h5>{{description}}</h5>
</center>
{% if not save %}
<h5>This file is read only. You may save it as another file that you will then be able to edit</h5>
{% endif %}
</p>
</div>
<p>
<button class='btn btn-primary ml-4' type='button' data-toggle='collapse' data-target='#collapse1'
Expand Down Expand Up @@ -158,13 +160,11 @@ <h6>These are the settings that are used to detect thermals. Thermal detection i
</div>
</div>
<div class='container'>
<br>
<center>
<p style="text-align:center;">
{% if save %}
<button id='save' type='button' class='btn btn-danger' data-toggle='modal' data-target='#save_modal'
data-dismiss='modal'>Save
</button>

{% endif%}
<button type='button' class='btn btn-primary' id='save-as' data-toggle='modal' data-target='#save_as_modal'>Save
as
Expand All @@ -173,9 +173,8 @@ <h6>These are the settings that are used to detect thermals. Thermal detection i
<button id='delete' type='button' class='btn btn-danger' data-toggle='modal' data-target='#delete_modal'
data-dismiss='modal'>Delete
</button>

{% endif%}
</center>
</p>
</div>


Expand Down
31 changes: 19 additions & 12 deletions airscore/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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/<string:filename>', methods=['POST'])
Expand Down

0 comments on commit d63a56b

Please sign in to comment.