[WEB-5878] chore: add validation for project name/identifier for special characters (#8529)
* chore: update ProjectSerializer to raise validation for special characters in name and identifier * chore: update external endpoints * fix: external api serializer validation * update serializer to send error code * fix: move the regex expression to Project model
This commit is contained in:
parent
f0dcf66167
commit
c4b3d52466
3 changed files with 42 additions and 0 deletions
|
|
@ -5,6 +5,9 @@
|
|||
# Third party imports
|
||||
from rest_framework import serializers
|
||||
|
||||
# Python imports
|
||||
import re
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer, DynamicBaseSerializer
|
||||
from django.db.models import Max
|
||||
|
|
@ -37,6 +40,9 @@ class ProjectSerializer(BaseSerializer):
|
|||
project_id = self.instance.id if self.instance else None
|
||||
workspace_id = self.context["workspace_id"]
|
||||
|
||||
if re.match(Project.FORBIDDEN_IDENTIFIER_CHARS_PATTERN, name):
|
||||
raise serializers.ValidationError(detail="PROJECT_NAME_CANNOT_CONTAIN_SPECIAL_CHARACTERS")
|
||||
|
||||
project = Project.objects.filter(name=name, workspace_id=workspace_id)
|
||||
|
||||
if project_id:
|
||||
|
|
@ -53,6 +59,9 @@ class ProjectSerializer(BaseSerializer):
|
|||
project_id = self.instance.id if self.instance else None
|
||||
workspace_id = self.context["workspace_id"]
|
||||
|
||||
if re.match(Project.FORBIDDEN_IDENTIFIER_CHARS_PATTERN, identifier):
|
||||
raise serializers.ValidationError(detail="PROJECT_IDENTIFIER_CANNOT_CONTAIN_SPECIAL_CHARACTERS")
|
||||
|
||||
project = Project.objects.filter(identifier=identifier, workspace_id=workspace_id)
|
||||
|
||||
if project_id:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue