progression 50% pour evolution des joueurs
CI - Security, Lint & Tests / validate (push) Failing after 1m13s
CI - Security, Lint & Tests / validate (push) Failing after 1m13s
This commit is contained in:
@@ -343,3 +343,73 @@ def coach_manages_tryout(coach, tryout):
|
||||
if tryout.target_org_team_id:
|
||||
return tryout.target_org_team_id in coach_org_team_ids(coach)
|
||||
return False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Player Evolution — Objectives
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def can_view_objectives(user):
|
||||
"""Whether the user may view the objectives list.
|
||||
|
||||
Everyone except regular players without any context can browse objectives.
|
||||
Players see only their own.
|
||||
"""
|
||||
return True
|
||||
|
||||
|
||||
def can_manage_objectives(user):
|
||||
"""Whether the user may create, edit, or delete objectives.
|
||||
|
||||
Presidents, managers, and coaches may manage objectives. Players are
|
||||
read-only.
|
||||
"""
|
||||
from app.models import Admin, Coach, Manager
|
||||
|
||||
return isinstance(user, (Admin, Manager, Coach))
|
||||
|
||||
|
||||
def can_manage_objective(user, objective):
|
||||
"""Whether the user may edit or delete a specific objective.
|
||||
|
||||
Presidents and managers may manage any objective. A coach may manage
|
||||
objectives assigned to their players or their teams.
|
||||
"""
|
||||
from app.models import Admin, Coach, Manager
|
||||
|
||||
if isinstance(user, (Admin, Manager)):
|
||||
return True
|
||||
if isinstance(user, Coach):
|
||||
if objective.player_id and objective.player_id in coach_player_ids(user):
|
||||
return True
|
||||
if objective.team_id and objective.team_id in coach_org_team_ids(user):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def can_view_objective(user, objective):
|
||||
"""Whether the user may view this objective's detail page.
|
||||
|
||||
Presidents, managers, and coaches may view any they manage.
|
||||
A player may view only their own assigned objectives.
|
||||
Everyone else may view objectives they created.
|
||||
"""
|
||||
from app.models import Admin, Coach, Manager, Player
|
||||
|
||||
if isinstance(user, (Admin, Manager)):
|
||||
return True
|
||||
if isinstance(user, Coach):
|
||||
return can_manage_objective(user, objective)
|
||||
if isinstance(user, Player):
|
||||
return objective.player_id == user.id
|
||||
return objective.created_by == user.id
|
||||
|
||||
|
||||
def can_add_objective_entry(user, objective):
|
||||
"""Whether the user may record a KPI measurement on this objective.
|
||||
|
||||
The same as can_view_objective — the assigned player may record
|
||||
their own measurements on their own objectives.
|
||||
"""
|
||||
return can_view_objective(user, objective)
|
||||
|
||||
Reference in New Issue
Block a user