[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:
parent
20ba91b98c
commit
a00bb35e54
1 changed files with 35 additions and 0 deletions
|
|
@ -147,6 +147,41 @@ class WorkspaceUserLinkSerializer(BaseSerializer):
|
||||||
return value
|
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):
|
class IssueRecentVisitSerializer(serializers.ModelSerializer):
|
||||||
project_identifier = serializers.SerializerMethodField()
|
project_identifier = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue