Ajout du joueur responsable
CI - Security, Lint & Tests / validate (push) Canceled after 0s

This commit is contained in:
cedrick2711
2026-09-27 14:25:29 -04:00
parent bd9ed4bdc7
commit 2e5903b131
18 changed files with 795 additions and 14 deletions
+8 -7
View File
@@ -23,7 +23,7 @@ from app.models import (
TeamPlayer,
)
from app.pagination import paginate
from app.permissions import can_manage_org_team, coach_org_teams, visible_org_teams
from app.permissions import coach_org_teams, representative_org_teams, visible_org_teams
from app.responders import respond_after_change
from app.routes.matches import default_end_time
from app.services.scheduling import notify_participants, zip_participants
@@ -36,10 +36,11 @@ team_matches_bp = Blueprint('team_matches', __name__, url_prefix='/team-matches'
def can_manage_team_match(team):
"""Whether the current user can manage matches for this team.
Same rule as administering the team itself, so it is the same call.
This function used to restate it, and the restatement drifted.
Everyone who administers the team, plus the player named as its
responsible. Narrower than administering the team itself: a responsible
schedules and edits matches, but does not touch the roster.
"""
return can_manage_org_team(current_user, team)
return current_user.can_manage_team_matches(team)
def season_locked():
@@ -300,13 +301,13 @@ def delete_match(match_id):
@login_required
def api_manageable_teams():
"""API endpoint returning teams the current user can schedule matches for."""
if not current_user.can_schedule_matches():
return jsonify([])
if isinstance(current_user, (Admin, Manager)):
teams = OrgTeam.query.order_by(OrgTeam.name).all()
elif isinstance(current_user, Coach):
teams = coach_org_teams(current_user)
elif isinstance(current_user, Player):
# A responsible schedules matches for their own team(s) only.
teams = representative_org_teams(current_user)
else:
return jsonify([])
+35 -3
View File
@@ -26,7 +26,7 @@ from app.models import (
Tryout,
User,
)
from app.permissions import visible_org_teams
from app.permissions import representative_org_teams, visible_org_teams
from app.responders import respond_after_change
from app.time_utils import utc_now_naive
from app.validators import NoteContentSchema, OrgTeamSchema, TeamPlayerSchema, TeamStaffSchema
@@ -40,10 +40,12 @@ def list_teams():
"""List all organization teams visible to the current user."""
can_manage = current_user.can_manage_teams()
if isinstance(current_user, Player):
# A player reaches this page only as a team's responsible; anyone else
# is sent to their own view.
if isinstance(current_user, Player) and not representative_org_teams(current_user):
flash(_('Use My Team(s) to view your teams.'), 'info')
return redirect(url_for('teams.my_teams'))
if not isinstance(current_user, (Admin, Coach, Manager)):
if not isinstance(current_user, (Admin, Coach, Manager, Player)):
flash(_('You do not have permission to view teams.'), 'danger')
return redirect(url_for('main.dashboard'))
@@ -563,6 +565,36 @@ def toggle_player_status(team_id, player_id):
)
@teams_bp.route('/<int:team_id>/toggle_representative/<int:player_id>', methods=['POST'])
@json_endpoint
@login_required
def toggle_player_representative(team_id, player_id):
"""Name or un-name a player as their team's responsible (president only).
The responsible gains match-management rights for this one team. The
flag itself stays a president's decision: this is deliberately the one
roster action a responsible cannot perform on their own team.
"""
db.get_or_404(OrgTeam, team_id)
if not current_user.can_designate_team_representative():
return jsonify({'error': 'Permission denied'}), 403
tp = TeamPlayer.query.filter_by(player_id=player_id, org_team_id=team_id).first()
if not tp:
return jsonify({'error': 'Player not found on this team'}), 404
tp.is_team_representative = not tp.is_team_representative
db.session.commit()
return jsonify(
{
'success': True,
'player_id': player_id,
'is_team_representative': tp.is_team_representative,
'player_name': tp.player.username,
}
)
@teams_bp.route('/<int:team_id>/add-team-note', methods=['POST'])
@login_required
def add_team_note(team_id):