Changement du refresh handler, soft reset d'ajouter sur beaucoup de formulaire de modification
CI - Security, Lint & Tests / validate (push) Failing after 1m3s

This commit is contained in:
cedrick2711
2026-09-08 11:27:53 -04:00
parent e2e2b1b07e
commit 4a2e2f053f
42 changed files with 722 additions and 333 deletions
+17 -16
View File
@@ -10,6 +10,7 @@ from marshmallow import ValidationError
from werkzeug.utils import secure_filename
from app.extensions import db
from app.responders import respond_after_change
from app.models import Admin, Coach, Contract, Manager, Player, User
from app.models.admin_settings import AppSettings
from app.permissions import can_manage_player_contract, coach_player_ids
@@ -102,11 +103,11 @@ def upload_contract():
"""Upload a contract for a player."""
if not isinstance(current_user, (Admin, Manager, Coach)):
flash(_('Only presidents, managers, and coaches can upload contracts.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
if document_uploads_locked():
flash(_('Document uploads are currently disabled.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
players = manageable_players()
@@ -125,13 +126,13 @@ def upload_contract():
if not can_manage_player_contract(current_user, player_id):
flash(_('You do not have permission to upload a contract for this player.'), 'danger')
return redirect(url_for('users.upload_contract'))
return respond_after_change(url_for('users.upload_contract'))
file = request.files.get('contract_file')
error = pdf_upload_error(file, ALLOWED_CONTRACT_EXTENSIONS)
if error:
flash(error, 'danger')
return redirect(url_for('users.upload_contract'))
return respond_after_change(url_for('users.upload_contract'))
player = db.get_or_404(User, player_id)
player_teams = player.get_org_teams()
@@ -154,7 +155,7 @@ def upload_contract():
flash(
_('Contract storage is temporarily unavailable. Please try again later.'), 'danger'
)
return redirect(url_for('users.upload_contract'))
return respond_after_change(url_for('users.upload_contract'))
contract = Contract(
player_id=player_id,
@@ -171,7 +172,7 @@ def upload_contract():
_('Contract uploaded successfully for %(username)s!', username=player.username),
'success',
)
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
return render_template('pages/upload_contract.html', players=players)
@@ -183,17 +184,17 @@ def upload_signed_contract(contract_id):
contract = db.get_or_404(Contract, contract_id)
if not contract.can_upload_signed(current_user):
flash(_('Only the player can upload their signed contract.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
if document_uploads_locked():
flash(_('Document uploads are currently disabled.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
file = request.files.get('signed_file')
error = pdf_upload_error(file, ALLOWED_SIGNED_EXTENSIONS)
if error:
flash(error, 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
signed_filename = f"signed_{contract.stored_filename}"
# Legacy local records keep their signed copy beside the original. Drive
@@ -208,7 +209,7 @@ def upload_signed_contract(contract_id):
stored_signed_path = store_uploaded_document(file, signed_path)
except GoogleDriveStorageError:
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
contract.signed_filename = signed_filename
contract.signed_file_path = stored_signed_path
@@ -216,7 +217,7 @@ def upload_signed_contract(contract_id):
contract.signed_at = utc_now_naive()
db.session.commit()
flash(_('Signed contract uploaded successfully!'), 'success')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
@users_bp.route('/contracts/<int:contract_id>/download')
@@ -226,12 +227,12 @@ def download_contract(contract_id):
contract = db.get_or_404(Contract, contract_id)
if not contract.can_view(current_user):
flash(_('You do not have permission to download this contract.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
try:
document = open_document(contract.file_path)
except GoogleDriveStorageError:
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
return send_file(document, as_attachment=True, download_name=contract.original_filename)
@@ -242,13 +243,13 @@ def download_signed_contract(contract_id):
contract = db.get_or_404(Contract, contract_id)
if not contract.can_view(current_user):
flash(_('You do not have permission to download this contract.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
if not contract.signed_file_path:
flash(_('No signed contract available.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
try:
document = open_document(contract.signed_file_path)
except GoogleDriveStorageError:
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
return redirect(url_for('users.list_contracts'))
return respond_after_change(url_for('users.list_contracts'))
return send_file(document, as_attachment=True, download_name=contract.signed_filename)
+20 -19
View File
@@ -10,6 +10,7 @@ from flask_login import current_user, login_required
from marshmallow import ValidationError
from app.extensions import db
from app.responders import respond_after_change
from app.forms import flash_validation_errors, form_payload
from app.models import (
Coach,
@@ -176,14 +177,14 @@ def manage_team_notes():
org_teams = coach_org_teams(current_user)
if not org_teams:
flash(_('You are not assigned to a team.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
org_team = org_teams[0]
try:
data = NoteContentSchema().load(form_payload(list_fields=()))
except ValidationError as err:
flash_validation_errors(err)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
note = TeamNote(
org_team_id=org_team.id,
@@ -194,7 +195,7 @@ def manage_team_notes():
db.session.commit()
flash(_('Team notes saved successfully!'), 'success')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
# ---------------------------------------------------------------------------
@@ -214,17 +215,17 @@ def manage_personal_notes():
data = PersonalNoteSchema().load(form_payload(list_fields=()))
except ValidationError as err:
flash_validation_errors(err)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
player_id = data['player_id']
player = db.get_or_404(User, player_id)
if not isinstance(player, Player):
flash(_('Can only add notes for players.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if not coach_can_access_player(current_user, player_id):
flash(_('You can only write notes about players you work with.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
note = PersonalNote(
player_id=player_id,
@@ -234,7 +235,7 @@ def manage_personal_notes():
db.session.add(note)
db.session.commit()
flash(_('Note added for %(username)s.', username=player.username), 'success')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
# ---------------------------------------------------------------------------
@@ -254,44 +255,44 @@ def add_personal_note():
data = PersonalNoteSchema().load(form_payload(list_fields=()))
except ValidationError as err:
flash_validation_errors(err)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
player_id = data['player_id']
player = db.get_or_404(User, player_id)
if not isinstance(player, Player):
flash(_('Can only add notes for players.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if not coach_can_access_player(current_user, player_id):
flash(_('You can only write notes about players you work with.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if data['match_id']:
match = db.get_or_404(Match, data['match_id'])
if not current_user.can_manage_this_tryout(match.tryout):
flash(_('You cannot use that match as note context.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if not MatchParticipant.query.filter_by(match_id=match.id, player_id=player_id).first():
flash(_('That player did not participate in the selected match.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if data['tryout_id']:
tryout = db.get_or_404(Tryout, data['tryout_id'])
if not current_user.can_manage_this_tryout(tryout):
flash(_('You cannot use that tryout as note context.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if not TryoutRegistration.query.filter_by(tryout_id=tryout.id, player_id=player_id).first():
flash(_('That player is not registered for the selected tryout.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if data['team_id']:
team = db.get_or_404(Team, data['team_id'])
if not current_user.can_manage_this_tryout(team.tryout):
flash(_('You cannot use that team as note context.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if not TeamMember.query.filter_by(team_id=team.id, player_id=player_id).first():
flash(_('That player is not on the selected team.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
note = PersonalNote(
player_id=player_id,
@@ -304,7 +305,7 @@ def add_personal_note():
db.session.add(note)
db.session.commit()
flash(_('Note added for %(username)s.', username=player.username), 'success')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
# ---------------------------------------------------------------------------
@@ -323,7 +324,7 @@ def add_note_from_tryout(tryout_id):
tryout = db.get_or_404(Tryout, tryout_id)
if not current_user.can_manage_this_tryout(tryout):
flash(_('You do not have permission to add notes for this tryout.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
preselected_player_id = request.args.get('player_id', type=int)
# Get registrations as players for the select list
@@ -387,7 +388,7 @@ def add_note_from_match(match_id):
match_obj = db.get_or_404(Match, match_id)
if not current_user.can_manage_this_tryout(match_obj.tryout):
flash(_('You do not have permission to add notes for this match.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
# Get participants as players for the select list
participants = MatchParticipant.query.filter_by(match_id=match_id).all()
+12 -11
View File
@@ -6,6 +6,7 @@ from flask_login import current_user, login_required
from marshmallow import ValidationError
from app.extensions import db
from app.responders import respond_after_change
from app.forms import flash_validation_errors, form_payload
from app.models import Coach, CoachAvailability, OneOnOneRequest, PersonalNote, Player, TeamNote
from app.routes.users.blueprint import users_bp
@@ -64,13 +65,13 @@ def one_on_one():
if request.method == 'POST':
if not coach:
flash(_('Cannot request One on One - no coach assigned.'), 'danger')
return redirect(url_for('users.one_on_one'))
return respond_after_change(url_for('users.one_on_one'))
try:
data = OneOnOneRequestSchema().load(form_payload())
except ValidationError as err:
flash_validation_errors(err)
return redirect(url_for('users.one_on_one'))
return respond_after_change(url_for('users.one_on_one'))
date_obj = data['date']
start_time = data['start_time']
@@ -90,7 +91,7 @@ def one_on_one():
if not is_available:
flash(_("The requested time is not within the coach's availability."), 'danger')
return redirect(url_for('users.one_on_one'))
return respond_after_change(url_for('users.one_on_one'))
request_obj = OneOnOneRequest(
player_id=current_user.id,
@@ -118,7 +119,7 @@ def one_on_one():
)
flash(_('Your One on One request has been submitted!'), 'success')
return redirect(url_for('users.one_on_one'))
return respond_after_change(url_for('users.one_on_one'))
# Build list of upcoming dates that have coach availability
from datetime import date as date_cls
@@ -169,11 +170,11 @@ def accept_one_on_one(request_id):
if request_obj.coach_id != current_user.id:
flash(_('This request is not for you.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if request_obj.status != 'pending':
flash(_('This request has already been processed.'), 'info')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
player = request_obj.player
request_obj.status = 'approved'
@@ -204,7 +205,7 @@ def accept_one_on_one(request_id):
),
'success',
)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
@users_bp.route('/one-on-one/<int:request_id>/reject', methods=['POST'])
@@ -219,17 +220,17 @@ def reject_one_on_one(request_id):
if request_obj.coach_id != current_user.id:
flash(_('This request is not for you.'), 'danger')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
if request_obj.status != 'pending':
flash(_('This request has already been processed.'), 'info')
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
try:
data = OneOnOneRejectionSchema().load(form_payload(list_fields=()))
except ValidationError as err:
flash_validation_errors(err)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
rejection_reason = data['rejection_reason']
player = request_obj.player
@@ -264,4 +265,4 @@ def reject_one_on_one(request_id):
),
'info',
)
return redirect(url_for('users.notes_dashboard'))
return respond_after_change(url_for('users.notes_dashboard'))
+2 -1
View File
@@ -6,6 +6,7 @@ from flask_login import current_user, login_required
from marshmallow import ValidationError
from app.extensions import db, hash_password
from app.responders import respond_after_change
from app.logging_config import log_auth_event
from app.models import (
ESPORT_GAMES,
@@ -129,7 +130,7 @@ def edit_profile():
db.session.commit()
flash(_('Profile updated successfully!'), 'success')
return redirect(url_for('users.profile'))
return respond_after_change(url_for('users.profile'))
return render_template(
'pages/edit_profile.html',