This commit is contained in:
@@ -158,6 +158,78 @@ def can_manage_org_team(user, org_team):
|
||||
return bool(org_team) and user.can_manage_this_org_team(org_team)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Team representatives ("joueurs responsables")
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def is_team_representative(user, org_team):
|
||||
"""Whether the user is the named responsible of this organisation team.
|
||||
|
||||
Args:
|
||||
user: The acting user.
|
||||
org_team: The team concerned.
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
if not user or not org_team:
|
||||
return False
|
||||
|
||||
from app.models import TeamPlayer
|
||||
|
||||
return (
|
||||
TeamPlayer.query.filter_by(
|
||||
player_id=user.id,
|
||||
org_team_id=org_team.id,
|
||||
is_team_representative=True,
|
||||
).first()
|
||||
is not None
|
||||
)
|
||||
|
||||
|
||||
def representative_org_teams(user):
|
||||
"""Organisation teams the user is the responsible of, ordered by name.
|
||||
|
||||
Args:
|
||||
user: The acting user.
|
||||
|
||||
Returns:
|
||||
list[OrgTeam]: Possibly empty.
|
||||
"""
|
||||
from app.models import OrgTeam, TeamPlayer
|
||||
|
||||
if not user:
|
||||
return []
|
||||
return (
|
||||
OrgTeam.query.join(TeamPlayer, TeamPlayer.org_team_id == OrgTeam.id)
|
||||
.filter(
|
||||
TeamPlayer.player_id == user.id,
|
||||
TeamPlayer.is_team_representative.is_(True),
|
||||
)
|
||||
.order_by(OrgTeam.name)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
def can_manage_team_matches(user, org_team):
|
||||
"""Whether the user may manage this team's matches and practices.
|
||||
|
||||
The staff rule (see :func:`can_manage_org_team`) *plus* the player named
|
||||
as the team's responsible. Deliberately narrower than
|
||||
``can_manage_org_team``: a responsible schedules and edits matches, but
|
||||
does not administer the roster.
|
||||
|
||||
Args:
|
||||
user: The acting user.
|
||||
org_team: The team concerned.
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
return can_manage_org_team(user, org_team) or is_team_representative(user, org_team)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Reach over players
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user