[WEB-3285] fix: creating and updating duplicate quick links (#6557)

* fix: creating and updating duplicate quick links

* fix: improve code readibiltiy
This commit is contained in:
Sangeetha 2025-02-07 20:06:47 +05:30 committed by GitHub
parent 20ba91b98c
commit a00bb35e54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -147,6 +147,41 @@ class WorkspaceUserLinkSerializer(BaseSerializer):
return value
def create(self, validated_data):
# Filtering the WorkspaceUserLink with the given url to check if the link already exists.
url = validated_data.get("url")
workspace_user_link = WorkspaceUserLink.objects.filter(
url=url,
workspace_id=validated_data.get("workspace_id"),
owner=validated_data.get("owner")
)
if workspace_user_link.exists():
raise serializers.ValidationError(
{"error": "URL already exists for this workspace and owner"}
)
return WorkspaceUserLink.objects.create(**validated_data)
def update(self, instance, validated_data):
# Filtering the WorkspaceUserLink with the given url to check if the link already exists.
url = validated_data.get("url")
workspace_user_link = WorkspaceUserLink.objects.filter(
url=url,
workspace_id=instance.workspace_id,
owner=instance.owner
)
if workspace_user_link.exclude(pk=instance.id).exists():
raise serializers.ValidationError(
{"error": "URL already exists for this workspace and owner"}
)
return super().update(instance, validated_data)
class IssueRecentVisitSerializer(serializers.ModelSerializer):
project_identifier = serializers.SerializerMethodField()