diff --git a/taiga/projects/serializers.py b/taiga/projects/serializers.py index 613fbc02..a06f9a15 100644 --- a/taiga/projects/serializers.py +++ b/taiga/projects/serializers.py @@ -68,6 +68,22 @@ class TaskStatusSerializer(ModelSerializer): class Meta: model = models.TaskStatus + def validate_name(self, attrs, source): + """ + Check the task name is not duplicated in the project on creation + """ + qs = None + # If the user story status exists: + if self.object and attrs.get("name", None): + qs = models.TaskStatus.objects.filter(project=self.object.project, name=attrs[source]) + + if not self.object and attrs.get("project", None) and attrs.get("name", None): + qs = models.TaskStatus.objects.filter(project=attrs["project"], name=attrs[source]) + + if qs and qs.exists(): + raise serializers.ValidationError("Name duplicated for the project") + + return attrs # Issues common serializers @@ -85,6 +101,23 @@ class IssueStatusSerializer(ModelSerializer): class Meta: model = models.IssueStatus + def validate_name(self, attrs, source): + """ + Check the issue name is not duplicated in the project on creation + """ + qs = None + # If the user story status exists: + if self.object and attrs.get("name", None): + qs = models.IssueStatus.objects.filter(project=self.object.project, name=attrs[source]) + + if not self.object and attrs.get("project", None) and attrs.get("name", None): + qs = models.IssueStatus.objects.filter(project=attrs["project"], name=attrs[source]) + + if qs and qs.exists(): + raise serializers.ValidationError("Name duplicated for the project") + + return attrs + class IssueTypeSerializer(ModelSerializer): class Meta: