[WEB-3186] chore: added endpoints for issue and issue description versioning#6434
[WEB-3186] chore: added endpoints for issue and issue description versioning#6434
Conversation
WalkthroughThis pull request introduces new serializers, URL patterns, and API endpoints for managing issue versions and description versions in the Plane application. The changes enable tracking and retrieving historical versions of issues and their descriptions, providing a comprehensive versioning mechanism. The implementation includes serialization classes, URL routing, and view endpoints that support listing and retrieving specific versions with pagination and timezone-aware processing. Changes
Possibly related PRs
Suggested Labels
Suggested Reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
apiserver/plane/app/views/issue/version.py (1)
17-66: Refactor common code to reduce duplication.Both
IssueVersionEndpointandIssueDescriptionVersionEndpointhave similar implementations in theirprocess_paginated_resultandgetmethods. Consider refactoring the common logic into a base class or utility functions to reduce code duplication and improve maintainability.Also applies to: 69-118
apiserver/plane/app/urls/issue.py (1)
261-280: Update the URL pattern names to be more specific.The URL pattern names should be more descriptive and specific to their functionality instead of using the generic "page-versions" for all endpoints.
Consider using these names instead:
- name="page-versions", + name="issue-versions",- name="page-versions", + name="issue-version-detail",- name="page-versions", + name="issue-description-versions",- name="page-versions", + name="issue-description-version-detail",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apiserver/plane/app/serializers/__init__.py(1 hunks)apiserver/plane/app/serializers/issue.py(2 hunks)apiserver/plane/app/urls/issue.py(2 hunks)apiserver/plane/app/views/__init__.py(1 hunks)apiserver/plane/app/views/issue/version.py(1 hunks)
🔇 Additional comments (5)
apiserver/plane/app/views/issue/version.py (1)
1-15: Review of imports and initial setup.Imports and initial setup look correct and necessary for the functionality of the endpoints.
apiserver/plane/app/serializers/__init__.py (1)
75-76: Added new serializers correctly.The
IssueVersionDetailSerializerandIssueDescriptionVersionDetailSerializerare correctly imported, enabling their use in the views.apiserver/plane/app/views/__init__.py (1)
144-145: Imported new endpoints successfully.The
IssueVersionEndpointandIssueDescriptionVersionEndpointare properly imported from.issue.version, integrating the new endpoints into the application.apiserver/plane/app/urls/issue.py (1)
27-28: LGTM! The URL structure follows RESTful conventions.The URL patterns are well-structured and follow REST conventions for versioning resources. The use of UUIDs for identification and the hierarchical structure (workspace -> project -> issue -> version) is appropriate.
Also applies to: 261-280
apiserver/plane/app/serializers/issue.py (1)
674-732: LGTM! Well-structured serializers with appropriate field definitions.Both serializers are well-implemented with:
- Proper inheritance from BaseSerializer
- Comprehensive field lists
- Appropriate read-only fields for maintaining data integrity
| issue_version = IssueVersion.objects.get( | ||
| workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk | ||
| ) |
There was a problem hiding this comment.
Handle exceptions when retrieving objects with .get().
The IssueVersion.objects.get() method will raise an exception if the object does not exist, leading to a server error. To prevent this, consider handling the IssueVersion.DoesNotExist exception and returning an appropriate 404 response.
Apply this fix:
def get(self, request, slug, project_id, issue_id, pk=None):
if pk:
- issue_version = IssueVersion.objects.get(
+ try:
+ issue_version = IssueVersion.objects.get(
workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk
+ )
+ except IssueVersion.DoesNotExist:
+ return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
serializer = IssueVersionDetailSerializer(issue_version)
return Response(serializer.data, status=status.HTTP_200_OK)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| issue_version = IssueVersion.objects.get( | |
| workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk | |
| ) | |
| def get(self, request, slug, project_id, issue_id, pk=None): | |
| if pk: | |
| try: | |
| issue_version = IssueVersion.objects.get( | |
| workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk | |
| ) | |
| except IssueVersion.DoesNotExist: | |
| return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND) | |
| serializer = IssueVersionDetailSerializer(issue_version) | |
| return Response(serializer.data, status=status.HTTP_200_OK) |
| issue_description_version = IssueDescriptionVersion.objects.get( | ||
| workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk | ||
| ) |
There was a problem hiding this comment.
Handle exceptions when retrieving objects with .get().
The IssueDescriptionVersion.objects.get() method will raise an exception if the object does not exist, leading to a server error. To prevent this, consider handling the IssueDescriptionVersion.DoesNotExist exception and returning an appropriate 404 response.
Apply this fix:
def get(self, request, slug, project_id, issue_id, pk=None):
if pk:
- issue_description_version = IssueDescriptionVersion.objects.get(
+ try:
+ issue_description_version = IssueDescriptionVersion.objects.get(
workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk
+ )
+ except IssueDescriptionVersion.DoesNotExist:
+ return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
serializer = IssueDescriptionVersionDetailSerializer(
issue_description_versionCommittable suggestion skipped: line range outside the PR's diff.
| class IssueVersionDetailSerializer(BaseSerializer): | ||
| class Meta: | ||
| model = IssueVersion | ||
| fields = [ | ||
| "id", | ||
| "workspace", | ||
| "project", | ||
| "issue", | ||
| "parent", | ||
| "state", | ||
| "estimate_point", | ||
| "name", | ||
| "priority", | ||
| "start_date", | ||
| "target_date", | ||
| "assignees", | ||
| "sequence_id", | ||
| "labels", | ||
| "sort_order", | ||
| "completed_at", | ||
| "archived_at", | ||
| "is_draft", | ||
| "external_source", | ||
| "external_id", | ||
| "type", | ||
| "cycle", | ||
| "modules", | ||
| "meta", | ||
| "name", | ||
| "last_saved_at", | ||
| "owned_by", | ||
| "created_at", | ||
| "updated_at", | ||
| "created_by", | ||
| "updated_by", | ||
| ] | ||
| read_only_fields = ["workspace", "project", "issue"] | ||
|
|
There was a problem hiding this comment.
Remove the duplicate 'name' field.
The name field appears twice in the fields list at lines 685 and 702.
Apply this diff to remove the duplicate:
"type",
"cycle",
"modules",
"meta",
- "name",
"last_saved_at",
"owned_by",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class IssueVersionDetailSerializer(BaseSerializer): | |
| class Meta: | |
| model = IssueVersion | |
| fields = [ | |
| "id", | |
| "workspace", | |
| "project", | |
| "issue", | |
| "parent", | |
| "state", | |
| "estimate_point", | |
| "name", | |
| "priority", | |
| "start_date", | |
| "target_date", | |
| "assignees", | |
| "sequence_id", | |
| "labels", | |
| "sort_order", | |
| "completed_at", | |
| "archived_at", | |
| "is_draft", | |
| "external_source", | |
| "external_id", | |
| "type", | |
| "cycle", | |
| "modules", | |
| "meta", | |
| "name", | |
| "last_saved_at", | |
| "owned_by", | |
| "created_at", | |
| "updated_at", | |
| "created_by", | |
| "updated_by", | |
| ] | |
| read_only_fields = ["workspace", "project", "issue"] | |
| class IssueVersionDetailSerializer(BaseSerializer): | |
| class Meta: | |
| model = IssueVersion | |
| fields = [ | |
| "id", | |
| "workspace", | |
| "project", | |
| "issue", | |
| "parent", | |
| "state", | |
| "estimate_point", | |
| "name", | |
| "priority", | |
| "start_date", | |
| "target_date", | |
| "assignees", | |
| "sequence_id", | |
| "labels", | |
| "sort_order", | |
| "completed_at", | |
| "archived_at", | |
| "is_draft", | |
| "external_source", | |
| "external_id", | |
| "type", | |
| "cycle", | |
| "modules", | |
| "meta", | |
| "last_saved_at", | |
| "owned_by", | |
| "created_at", | |
| "updated_at", | |
| "created_by", | |
| "updated_by", | |
| ] | |
| read_only_fields = ["workspace", "project", "issue"] |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
apiserver/plane/app/views/issue/version.py (2)
18-26: Reduce code duplication by extracting common functionality.Both endpoint classes have identical
process_paginated_resultmethods. Consider extracting this into a mixin or base class to follow DRY principles.+class VersionEndpointMixin: + def process_paginated_result(self, fields, results, timezone): + paginated_data = results.values(*fields) + + datetime_fields = ["created_at", "updated_at"] + paginated_data = user_timezone_converter( + paginated_data, datetime_fields, timezone + ) + + return paginated_data + -class IssueVersionEndpoint(BaseAPIView): +class IssueVersionEndpoint(BaseAPIView, VersionEndpointMixin): - def process_paginated_result(self, fields, results, timezone): - paginated_data = results.values(*fields) - - datetime_fields = ["created_at", "updated_at"] - paginated_data = user_timezone_converter( - paginated_data, datetime_fields, timezone - ) - - return paginated_dataAlso applies to: 70-78
40-51: Extract common required fields into a constant.Both endpoint classes use identical required fields. Consider extracting these into a shared constant to improve maintainability.
+VERSION_REQUIRED_FIELDS = [ + "id", + "workspace", + "project", + "issue", + "last_saved_at", + "owned_by", + "created_at", + "updated_at", + "created_by", + "updated_by", +] class IssueVersionEndpoint(BaseAPIView, VersionEndpointMixin): def get(self, request, slug, project_id, issue_id, pk=None): ... - required_fields = [ - "id", - "workspace", - "project", - "issue", - "last_saved_at", - "owned_by", - "created_at", - "updated_at", - "created_by", - "updated_by", - ] + required_fields = VERSION_REQUIRED_FIELDSAlso applies to: 94-105
apiserver/plane/app/serializers/issue.py (1)
713-732: Improve code organization and documentation.The serializer would benefit from:
- Adding a class-level docstring to explain its purpose
- Organizing fields into logical groups for better readability
Apply this diff to improve the code:
class IssueDescriptionVersionDetailSerializer(BaseSerializer): + """Serializer for IssueDescriptionVersion model to track historical versions of issue descriptions.""" + class Meta: model = IssueDescriptionVersion fields = [ "id", # Relationship fields "workspace", "project", "issue", # Description fields "description_binary", "description_html", "description_stripped", "description_json", # Timestamps "last_saved_at", "created_at", "updated_at", # Ownership "owned_by", "created_by", "updated_by", ] read_only_fields = ["workspace", "project", "issue"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apiserver/plane/app/serializers/__init__.py(1 hunks)apiserver/plane/app/serializers/issue.py(2 hunks)apiserver/plane/app/urls/issue.py(2 hunks)apiserver/plane/app/views/__init__.py(1 hunks)apiserver/plane/app/views/issue/version.py(1 hunks)
🔇 Additional comments (3)
apiserver/plane/app/views/__init__.py (1)
144-145: LGTM!The imports are correctly placed and follow the existing pattern.
apiserver/plane/app/serializers/__init__.py (1)
75-76: LGTM!The serializer imports are correctly placed within the issue-related imports section.
apiserver/plane/app/serializers/issue.py (1)
36-37: LGTM! Model imports are properly organized.The new model imports are correctly placed within the existing model imports section.
| issue_version = IssueVersion.objects.get( | ||
| workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk | ||
| ) |
There was a problem hiding this comment.
Add error handling for non-existent objects.
The .get() calls could raise DoesNotExist exceptions. Consider adding proper error handling.
+from django.core.exceptions import ObjectDoesNotExist
+from rest_framework import status
class IssueVersionEndpoint(BaseAPIView):
def get(self, request, slug, project_id, issue_id, pk=None):
if pk:
- issue_version = IssueVersion.objects.get(
- workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk
- )
+ try:
+ issue_version = IssueVersion.objects.get(
+ workspace__slug=slug, project_id=project_id, issue_id=issue_id, pk=pk
+ )
+ except ObjectDoesNotExist:
+ return Response(
+ {"error": "Issue version not found"},
+ status=status.HTTP_404_NOT_FOUND
+ )Also applies to: 83-85
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/", | ||
| IssueVersionEndpoint.as_view(), | ||
| name="page-versions", | ||
| ), | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/<uuid:pk>/", | ||
| IssueVersionEndpoint.as_view(), | ||
| name="page-versions", | ||
| ), | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/", | ||
| IssueDescriptionVersionEndpoint.as_view(), | ||
| name="page-versions", | ||
| ), | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/<uuid:pk>/", | ||
| IssueDescriptionVersionEndpoint.as_view(), | ||
| name="page-versions", | ||
| ), |
There was a problem hiding this comment.
Fix inconsistent URL pattern names.
The URL pattern names "page-versions" seem incorrect for issue-related endpoints. Consider using more appropriate names like "issue-versions" and "issue-description-versions".
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/",
IssueVersionEndpoint.as_view(),
- name="page-versions",
+ name="issue-versions",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/<uuid:pk>/",
IssueVersionEndpoint.as_view(),
- name="page-versions",
+ name="issue-version-detail",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/",
IssueDescriptionVersionEndpoint.as_view(),
- name="page-versions",
+ name="issue-description-versions",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/<uuid:pk>/",
IssueDescriptionVersionEndpoint.as_view(),
- name="page-versions",
+ name="issue-description-version-detail",
),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/", | |
| IssueVersionEndpoint.as_view(), | |
| name="page-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/<uuid:pk>/", | |
| IssueVersionEndpoint.as_view(), | |
| name="page-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/", | |
| IssueDescriptionVersionEndpoint.as_view(), | |
| name="page-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/<uuid:pk>/", | |
| IssueDescriptionVersionEndpoint.as_view(), | |
| name="page-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/", | |
| IssueVersionEndpoint.as_view(), | |
| name="issue-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/versions/<uuid:pk>/", | |
| IssueVersionEndpoint.as_view(), | |
| name="issue-version-detail", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/", | |
| IssueDescriptionVersionEndpoint.as_view(), | |
| name="issue-description-versions", | |
| ), | |
| path( | |
| "workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/description-versions/<uuid:pk>/", | |
| IssueDescriptionVersionEndpoint.as_view(), | |
| name="issue-description-version-detail", | |
| ), |
| class IssueVersionDetailSerializer(BaseSerializer): | ||
| class Meta: | ||
| model = IssueVersion | ||
| fields = [ | ||
| "id", | ||
| "workspace", | ||
| "project", | ||
| "issue", | ||
| "parent", | ||
| "state", | ||
| "estimate_point", | ||
| "name", | ||
| "priority", | ||
| "start_date", | ||
| "target_date", | ||
| "assignees", | ||
| "sequence_id", | ||
| "labels", | ||
| "sort_order", | ||
| "completed_at", | ||
| "archived_at", | ||
| "is_draft", | ||
| "external_source", | ||
| "external_id", | ||
| "type", | ||
| "cycle", | ||
| "modules", | ||
| "meta", | ||
| "name", | ||
| "last_saved_at", | ||
| "owned_by", | ||
| "created_at", | ||
| "updated_at", | ||
| "created_by", | ||
| "updated_by", | ||
| ] | ||
| read_only_fields = ["workspace", "project", "issue"] | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix duplicate field and improve code organization.
The serializer has the following issues:
- The field 'name' is duplicated (lines 685 and 702)
- Missing class-level docstring to explain the serializer's purpose
- Related fields could be grouped together for better readability
Apply this diff to fix the issues:
class IssueVersionDetailSerializer(BaseSerializer):
+ """Serializer for IssueVersion model to track historical versions of issues."""
+
class Meta:
model = IssueVersion
fields = [
"id",
# Relationship fields
"workspace",
"project",
"issue",
"parent",
"state",
"cycle",
"modules",
# Core issue fields
"name",
"priority",
"estimate_point",
"sequence_id",
"sort_order",
# Date fields
"start_date",
"target_date",
"completed_at",
"archived_at",
"last_saved_at",
"created_at",
"updated_at",
# Relationship arrays
"assignees",
"labels",
# Status flags
"is_draft",
# External references
"external_source",
"external_id",
"type",
# Additional data
"meta",
# Ownership
"owned_by",
"created_by",
"updated_by",
- "name", # Remove duplicate field
]
read_only_fields = ["workspace", "project", "issue"]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class IssueVersionDetailSerializer(BaseSerializer): | |
| class Meta: | |
| model = IssueVersion | |
| fields = [ | |
| "id", | |
| "workspace", | |
| "project", | |
| "issue", | |
| "parent", | |
| "state", | |
| "estimate_point", | |
| "name", | |
| "priority", | |
| "start_date", | |
| "target_date", | |
| "assignees", | |
| "sequence_id", | |
| "labels", | |
| "sort_order", | |
| "completed_at", | |
| "archived_at", | |
| "is_draft", | |
| "external_source", | |
| "external_id", | |
| "type", | |
| "cycle", | |
| "modules", | |
| "meta", | |
| "name", | |
| "last_saved_at", | |
| "owned_by", | |
| "created_at", | |
| "updated_at", | |
| "created_by", | |
| "updated_by", | |
| ] | |
| read_only_fields = ["workspace", "project", "issue"] | |
| class IssueVersionDetailSerializer(BaseSerializer): | |
| """Serializer for IssueVersion model to track historical versions of issues.""" | |
| class Meta: | |
| model = IssueVersion | |
| fields = [ | |
| "id", | |
| # Relationship fields | |
| "workspace", | |
| "project", | |
| "issue", | |
| "parent", | |
| "state", | |
| "cycle", | |
| "modules", | |
| # Core issue fields | |
| "name", | |
| "priority", | |
| "estimate_point", | |
| "sequence_id", | |
| "sort_order", | |
| # Date fields | |
| "start_date", | |
| "target_date", | |
| "completed_at", | |
| "archived_at", | |
| "last_saved_at", | |
| "created_at", | |
| "updated_at", | |
| # Relationship arrays | |
| "assignees", | |
| "labels", | |
| # Status flags | |
| "is_draft", | |
| # External references | |
| "external_source", | |
| "external_id", | |
| "type", | |
| # Additional data | |
| "meta", | |
| # Ownership | |
| "owned_by", | |
| "created_by", | |
| "updated_by", | |
| ] | |
| read_only_fields = ["workspace", "project", "issue"] |
Description
Type of Change
References
[WEB-3186]
Summary by CodeRabbit
Release Notes
New Features
Improvements
The update provides more granular tracking and retrieval of issue and description version information across workspaces and projects.