Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #372 from SELab-2/enforce-group-size
Browse files Browse the repository at this point in the history
Enforce max group size
  • Loading branch information
msathieu authored May 23, 2024
2 parents 7b36f10 + 8e426cb commit f0dd284
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/domain/logic/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from db.models import Group, Project, ProjectStatistics, Student, Submission, SubmissionState
from domain.logic.basic_operations import get, get_all
from domain.logic.submission import get_last_submission, get_submissions_of_group
from errors.database_errors import ActionAlreadyPerformedError, NoSuchRelationError
from errors.database_errors import ActionAlreadyPerformedError, ConflictingRelationError, NoSuchRelationError
from errors.logic_errors import ArchivedError


Expand Down Expand Up @@ -83,6 +83,9 @@ def add_student_to_group(session: Session, student_id: int, group_id: int) -> No
student: Student = get(session, Student, ident=student_id)
group: Group = get(session, Group, ident=group_id)

if len(group.students) >= group.project.max_students:
msg = "Group is already full"
raise ConflictingRelationError(msg)
if student in group.students:
msg = f"Student with id {student_id} already in group with id {group_id}"
raise ActionAlreadyPerformedError(msg)
Expand Down

0 comments on commit f0dd284

Please sign in to comment.