Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeethailango committed Dec 31, 2024
1 parent ac20cc4 commit 3c5c892
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
1 change: 0 additions & 1 deletion apiserver/plane/app/serializers/favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def get_entity_model_and_serializer(entity_type):
}
return entity_map.get(entity_type, (None, None))


class UserFavoriteSerializer(serializers.ModelSerializer):
entity_data = serializers.SerializerMethodField()

Expand Down
97 changes: 97 additions & 0 deletions apiserver/plane/app/serializers/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,100 @@ class Meta:
model = WorkspaceUserProperties
fields = "__all__"
read_only_fields = ["workspace", "user"]

class WorkspaceUserLinkSerializer(BaseSerializer):
class Meta:
model = WorkspaceUserLink
fields = "__all__"
read_only_fields = ["workspace", "owner"]

def to_internal_value(self, data):
url = data.get("url", "")
if url and not url.startswith(("http://", "https://")):
data["url"] = "http://" + url

return super().to_internal_value(data)

def validate_url(self, value):
url_validator = URLValidator()
try:
url_validator(value)
except ValidationError:
raise serializers.ValidationError({"error": "Invalid URL format."})

return value

class IssueRecentVisitSerializer(serializers.ModelSerializer):
class Meta:
model = Issue
fields = ["name", "state", "priority", "assignees"]

class ProjectMemberSerializer(BaseSerializer):
member = UserLiteSerializer(read_only=True)

class Meta:
model = ProjectMember
fields = ["member"]

class ProjectRecentVisitSerializer(serializers.ModelSerializer):
project_members = serializers.SerializerMethodField()

class Meta:
model = Project
fields = ["id", "name", "logo_props", "project_members"]

def get_project_members(self, obj):
members = ProjectMember.objects.filter(project_id=obj.id)

serializer = ProjectMemberSerializer(members, many=True)
return serializer.data

class PageRecentVisitSerializer(serializers.ModelSerializer):
project_id = serializers.SerializerMethodField()

class Meta:
model = Page
fields = ["id", "name", "logo_props", "project_id", "owned_by"]

def get_project_id(self, obj):
project = (
obj.projects.first()
)
return project.id if project else None

def get_entity_model_and_serializer(entity_type):
entity_map = {
"issue": (Issue, IssueRecentVisitSerializer),
"page": (Page, PageRecentVisitSerializer),
"project": (Project, ProjectRecentVisitSerializer)
}
return entity_map.get(entity_type, (None, None))

class WorkspaceRecentVisitSerializer(BaseSerializer):
entity_data = serializers.SerializerMethodField()

class Meta:
model = UserRecentVisit
fields = [
"id",
"entity_name",
"entity_identifier",
"entity_data",
"visited_at"
]
read_only_fields = ["workspace", "owner", "created_by", "updated_by"]

def get_entity_data(self, obj):
entity_name = obj.entity_name
entity_identifier = obj.entity_identifier

entity_model, entity_serializer = get_entity_model_and_serializer(entity_name)

if entity_model and entity_serializer:
try:
entity = entity_model.objects.get(pk=entity_identifier)

return entity_serializer(entity).data
except entity_model.DoesNotExist:
return None
return None

0 comments on commit 3c5c892

Please sign in to comment.