regler probleme avec la creation d'equipe et 1 manager par tryout changer pour plusieurs
CI - Security, Lint & Tests / validate (push) Failing after 58s
CI - Security, Lint & Tests / validate (push) Failing after 58s
This commit is contained in:
+18
-5
@@ -51,7 +51,7 @@ def can_manage():
|
||||
|
||||
def tryout_form_payload():
|
||||
"""The tryout form, shaped for marshmallow (ARCH-005)."""
|
||||
return form_payload(list_fields=('coach_ids',), optional_blank=())
|
||||
return form_payload(list_fields=('coach_ids', 'manager_ids'), optional_blank=())
|
||||
|
||||
|
||||
def coaches_from_ids(coach_ids):
|
||||
@@ -67,6 +67,13 @@ def coaches_from_ids(coach_ids):
|
||||
return User.query.filter(User.id.in_(coach_ids), User.role == 'coach').all()
|
||||
|
||||
|
||||
def managers_from_ids(manager_ids):
|
||||
"""The manager accounts behind these ids, filtered by role."""
|
||||
if not manager_ids:
|
||||
return []
|
||||
return User.query.filter(User.id.in_(manager_ids), User.role == 'manager').all()
|
||||
|
||||
|
||||
def _users_by_id(user_ids):
|
||||
"""Load these users in one query, keyed by id.
|
||||
|
||||
@@ -160,12 +167,12 @@ def create_tryout():
|
||||
created_by=current_user.id,
|
||||
status='upcoming',
|
||||
target_org_team_id=data['target_org_team_id'],
|
||||
manager_id=data['manager_id'],
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.flush()
|
||||
|
||||
tryout.coaches = coaches_from_ids(data['coach_ids'])
|
||||
tryout.managers = managers_from_ids(data['manager_ids'])
|
||||
|
||||
db.session.commit()
|
||||
flash(_('Tryout created successfully!'), 'success')
|
||||
@@ -221,8 +228,14 @@ def edit_tryout(tryout_id):
|
||||
tryout.location = data['location']
|
||||
tryout.max_players = data['max_players']
|
||||
tryout.target_org_team_id = data['target_org_team_id']
|
||||
tryout.manager_id = data['manager_id']
|
||||
tryout.coaches = coaches_from_ids(data['coach_ids'])
|
||||
|
||||
# Only update staff lists when the form explicitly sends them.
|
||||
# An absent checkbox group (all unchecked or JS failed) means
|
||||
# \"don't change\", not \"remove everyone\".
|
||||
if 'coach_ids' in request.form:
|
||||
tryout.coaches = coaches_from_ids(data['coach_ids'])
|
||||
if 'manager_ids' in request.form:
|
||||
tryout.managers = managers_from_ids(data['manager_ids'])
|
||||
|
||||
db.session.commit()
|
||||
flash(_('Tryout updated successfully!'), 'success')
|
||||
@@ -241,7 +254,7 @@ def view_tryout(tryout_id):
|
||||
if isinstance(current_user, Admin):
|
||||
can_view = True
|
||||
elif isinstance(current_user, Manager):
|
||||
can_view = tryout.created_by == current_user.id or tryout.manager_id == current_user.id
|
||||
can_view = current_user.can_manage_this_tryout(tryout)
|
||||
elif isinstance(current_user, Coach):
|
||||
can_view = current_user.can_manage_this_tryout(tryout)
|
||||
elif isinstance(current_user, Player):
|
||||
|
||||
Reference in New Issue
Block a user