diff --git a/app/routes/tryouts.py b/app/routes/tryouts.py index 4d375e9..4c2be4c 100644 --- a/app/routes/tryouts.py +++ b/app/routes/tryouts.py @@ -32,7 +32,7 @@ from app.models import ( TryoutRegistration, User, ) -from app.validators import TryoutSchema +from app.validators import PlayerSelectionSchema, TryoutSchema tryouts_bp = Blueprint('tryouts', __name__, url_prefix='/tryouts') @@ -479,13 +479,21 @@ def register_player(tryout_id): if not current_user.can_manage_this_tryout(tryout): flash(_('Permission denied.'), 'danger') return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id)) - player_id = request.form.get('player_id') - if not player_id: + try: + data = PlayerSelectionSchema().load(form_payload()) + except ValidationError as err: + flash_validation_errors(err) + return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id)) + + if not data['player_id']: flash(_('Please select a player.'), 'danger') return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id)) - player = User.query.get_or_404(int(player_id)) - if not isinstance(player, Player): + # Same two checks as the team roster (SEC-16): the right role, and an + # account that has not been deactivated. The select this comes from now + # filters both, but the select is not the control. + player = db.session.get(User, data['player_id']) + if not player or not isinstance(player, Player) or not player.is_active_account: flash(_('Can only register players.'), 'danger') return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id)) diff --git a/app/routes/users/contracts.py b/app/routes/users/contracts.py index 865bc8f..eda1c8b 100644 --- a/app/routes/users/contracts.py +++ b/app/routes/users/contracts.py @@ -38,7 +38,9 @@ def manageable_players(): if player_ids else [] ) - return User.query.filter_by(role='player').order_by(User.username).all() + # is_active_account: a contract select that still lists people who have + # left the club invites filing paperwork against them (SEC-16). + return User.query.filter_by(role='player', is_active_account=True).order_by(User.username).all() @users_bp.route('/contracts') diff --git a/app/validators.py b/app/validators.py index 230773b..7c25b24 100644 --- a/app/validators.py +++ b/app/validators.py @@ -501,8 +501,15 @@ class TeamStaffSchema(StripMixin): ) -class TeamPlayerSchema(StripMixin): - """A player being put on a team roster, and where they stand on it.""" +class PlayerSelectionSchema(StripMixin): + """One player id, picked from a `