diff --git a/travo/course.py b/travo/course.py index c422a94daf03573b9bb987533bf99c7b05aefc6c..298daad50dd0c3b79637d004a29431ecaecd627e 100644 --- a/travo/course.py +++ b/travo/course.py @@ -2,6 +2,7 @@ import logging import os.path from dataclasses import dataclass, field from deprecation import deprecated # type: ignore +import re import subprocess from typing import List, Optional, Tuple, Union @@ -17,6 +18,19 @@ def missing_course() -> 'Course': raise ValueError("missing required argument: 'course'") +""" +Characters that are forbidden in GitLab group names + +https://docs.gitlab.com/ee/user/reserved_names.html#limitations-on-project-and-group-names + +Test: + + >>> re.sub(forbidden_in_gitlab_group_name, " ", "a-s+d o_98#(*&$'sadf.)") + '-a+sd o_98 ( sadf.)' +""" +forbidden_in_gitlab_group_name = re.compile(r"[^.()\w+-]") + + @dataclass class CourseAssignment(Assignment): # Until Python 3.10 and keyword only fields, a subdataclass @@ -124,6 +138,10 @@ class CourseAssignment(Assignment): assert not isinstance(user, AnonymousUser) assert user.name is not None name = user.name + + # Replace forbidden characters by spaces + name = re.sub(forbidden_in_gitlab_group_name, " ", name) + if self.course.group_submissions: name = _('submission group name', name=user.name) components = [name, self.course.name]