From 97b9bd557799c6a4073f6f14ec130d9278b01edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20K=C3=BCnzel?= <simonk@fsmpi.rwth-aachen.de> Date: Mon, 3 Jun 2024 21:17:36 +0200 Subject: [PATCH] Update allowed values for course handle --- api_specification.md | 8 ++++++-- src/api/objects/types.py | 8 ++++++-- tests/routes/object_modifications.py | 14 +++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api_specification.md b/api_specification.md index 1d98282..c06a2b9 100644 --- a/api_specification.md +++ b/api_specification.md @@ -1,4 +1,4 @@ -# Specification of the Web API for the Video-AG Website (v0.52). +# Specification of the Web API for the Video-AG Website (v0.53). ## Introduction @@ -1025,7 +1025,7 @@ Executes the specified action. | lecture_id | int | ✓ | Existence must be checked | | user_id | int | ✓ | Existence must be checked | | user_id_list | array of user_id | ✓ | | -| course_id_string | id_string | ✓ | Must not be used by other course | +| course_id_string | string | ✓ | Must match `[a-zA-Z0-9_-]{1,100}`, must not be used by other course, must **not** be one of: `courses`, `faq`, `imprint`, `licenses`, `search`, `site`, `internal` | | job_state | id_string | | possible values: `ready`, `running`, `finished`, `failed`, `deleted` | | job_type | id_string | | possible values: `probe`, `probe-raw`, `remux`, `thumbnail`, `transcode`, `publish_video`, `simple_live_transcode`, `complex_live_transcode`, `live_forward` | @@ -1522,6 +1522,10 @@ Possible `error_code`: ## Changelog +### v0.53 + +* Changed type of `course_id_string` to regex. Added forbidden values. + ### v0.52 * Added error code `site_is_overloaded` diff --git a/src/api/objects/types.py b/src/api/objects/types.py index 62faf79..27a51aa 100644 --- a/src/api/objects/types.py +++ b/src/api/objects/types.py @@ -1,5 +1,5 @@ +import re -from api.miscellaneous import ID_STRING_REGEX_NO_LENGTH from api.objects.type import (IntType, LongType, SimpleType, ObjectIdType, StringType, SimpleStringType, UniqueStringType, MappedStringType, SemesterStringType, @@ -11,11 +11,15 @@ TYPE_BOOLEAN = SimpleType("boolean", lambda db: bool(db), lambda json_value: jso TYPE_STRING_SHORT = StringType(256) TYPE_STRING_LONG = StringType(8192) TYPE_URL = SimpleStringType("url", 1024, 0, None) + +# Also update in API specification when modifying! +FORBIDDEN_COURSE_ID_STRING_VALUES = ["courses", "faq", "imprint", "licenses", "search", "site", "internal"] +# noinspection RegExpUnnecessaryNonCapturingGroup TYPE_COURSE_ID_STRING = UniqueStringType( "course_id_string", 100, 1, - ID_STRING_REGEX_NO_LENGTH, + re.compile(f"(?!(?:{'|'.join(FORBIDDEN_COURSE_ID_STRING_VALUES)})$)[a-zA-Z0-9_-]+"), "courses_data", "id", "handle" diff --git a/tests/routes/object_modifications.py b/tests/routes/object_modifications.py index 0f55c4f..982c50e 100644 --- a/tests/routes/object_modifications.py +++ b/tests/routes/object_modifications.py @@ -463,7 +463,19 @@ class ObjectModificationsTest(ApiTest): "/object_management/course/2/configuration", { "updates": { - "id_string": "00" + "id_string": "a/b" + }, + "expected_current_values": {} + }, + expected_response_code=HTTP_400_BAD_REQUEST, + use_moderator_login=True + ) + self.do_json_request( + "PATCH", + "/object_management/course/2/configuration", + { + "updates": { + "id_string": "courses" }, "expected_current_values": {} }, -- GitLab