From 6fe6f95fa6ae8a9c5aac305f6db4ed6333d6fa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=2E=20Thi=C3=A9ry?= Date: Tue, 12 Sep 2023 17:38:05 +0200 Subject: [PATCH] group_submissions: handle forbidden characters coming from users' names --- travo/course.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/travo/course.py b/travo/course.py index c422a94..298daad 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] -- GitLab