This commit is contained in:
+35
-3
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user