Skip to content

feat: quick links CRUD#6286

Closed
sangeethailango wants to merge 3 commits intopreviewfrom
feat-quick-links
Closed

feat: quick links CRUD#6286
sangeethailango wants to merge 3 commits intopreviewfrom
feat-quick-links

Conversation

@sangeethailango
Copy link
Member

@sangeethailango sangeethailango commented Dec 27, 2024

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features

    • Introduced a new serializer for managing workspace user links.
    • Added endpoints for creating, listing, and managing quick links within workspaces.
  • Bug Fixes

    • Enhanced validation and error handling for quick link creation and updates.
  • Documentation

    • Updated import statements to reflect new functionality related to quick links in the workspace.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


sangeetha seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request introduces enhancements for managing quick links within workspaces. It adds a new serializer, WorkspaceUserLinkSerializer, for the WorkspaceUserLink model, creates a QuickLinkViewSet to handle quick link operations, and establishes new URL patterns for creating, listing, and updating quick links. The changes facilitate workspace users in managing quick links with appropriate permission controls.

Changes

File Change Summary
apiserver/plane/app/serializers/__init__.py Added import for WorkspaceUserLinkSerializer
apiserver/plane/app/serializers/workspace.py Introduced WorkspaceUserLinkSerializer for WorkspaceUserLink model
apiserver/plane/app/urls/workspace.py Added URL patterns for quick link management
apiserver/plane/app/views/__init__.py Imported QuickLinkViewSet
apiserver/plane/app/views/workspace/quick_link.py Created QuickLinkViewSet with create and partial update methods

Possibly related PRs

  • chore: quick link migration #6274: This PR introduces the WorkspaceUserLink model, which is directly related to the WorkspaceUserLinkSerializer added in the main PR, as both pertain to the same WorkspaceUserLink entity and its functionality.

Suggested labels

🌐frontend

Suggested reviewers

  • pablohashescobar
  • sriramveeraghanta
  • SatishGandham

Poem

🐰 Hop, hop, quick links arise!
In workspaces, new features surprise
Serializers dance, routes unfurl
A rabbit's code begins to swirl
Swift and nimble, connections grow
Technology's magic starts to flow! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sangeethailango sangeethailango marked this pull request as draft December 27, 2024 14:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
apiserver/plane/app/views/workspace/quick_link.py (1)

29-29: Shorten line length.

A static analysis tool indicates line length exceeds 88 characters. Consider breaking it into multiple lines or using local variables to make it more readable and comply with style guides.

- serializer = WorkspaceUserLinkSerializer(quick_link, data=request.data, partial=True)
+ serializer = WorkspaceUserLinkSerializer(
+     quick_link, data=request.data, partial=True
+ )
🧰 Tools
🪛 Ruff (0.8.2)

29-29: Line too long (93 > 88)

(E501)

apiserver/plane/app/urls/workspace.py (2)

217-218: Use a more descriptive comment.

While "quick link" is clear, it can be more descriptive for future maintainers, e.g., "# Endpoints for managing quick links within a workspace".


219-223: Remove trailing space from name="workspace-quick-links " string.

There is a trailing space in the name argument's string literal, which can accidentally cause inconsistencies when referencing this path name in other parts of the code.

-        name="workspace-quick-links "
+        name="workspace-quick-links"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 211d5e1 and 64c2d0a.

📒 Files selected for processing (5)
  • apiserver/plane/app/serializers/__init__.py (1 hunks)
  • apiserver/plane/app/serializers/workspace.py (2 hunks)
  • apiserver/plane/app/urls/workspace.py (2 hunks)
  • apiserver/plane/app/views/__init__.py (1 hunks)
  • apiserver/plane/app/views/workspace/quick_link.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/app/views/workspace/quick_link.py

29-29: Line too long (93 > 88)

(E501)

🔇 Additional comments (4)
apiserver/plane/app/serializers/workspace.py (1)

110-114: Serializer fields look consistent.

The WorkspaceUserLinkSerializer includes fields = "__all__", but marks workspace and owner as read-only. This is consistent with many usage patterns to avoid accidental overrides. No issues found here.

apiserver/plane/app/serializers/__init__.py (1)

22-22: LGTM.

Importing WorkspaceUserLinkSerializer here neatly centralizes your exports. No changes needed.

apiserver/plane/app/views/__init__.py (1)

75-75: Approved import addition.

Adding QuickLinkViewSet is consistent with the new feature. This arrangement keeps workspace-related views logically grouped.

apiserver/plane/app/urls/workspace.py (1)

224-228: Verify whether a GET endpoint is needed to retrieve a single quick link.

Currently, only patch and delete are exposed for single quick links. If retrieving an individual quick link by ID is desired, consider adding a retrieve action. Otherwise, confirm that you do not need to retrieve a single quick link in your use case.

✅ Verification successful

Let me gather more information about the quick link functionality to better understand the use case.


Let me try a different approach to understand the quick link functionality better.


A GET endpoint for single quick link retrieval is not necessary

Based on the codebase analysis:

  • The workspace quick links are simple entities with basic fields (title, url, metadata)
  • All quick links for a workspace can be retrieved using the list endpoint (GET /workspaces/<slug>/quick-links/)
  • The current CRUD operations (list all, create, update, delete) are sufficient for the use case
  • There's no evidence of a need for individual quick link retrieval in the frontend code

Since quick links are lightweight resources and can be efficiently retrieved through the list endpoint, adding a separate retrieve endpoint would be unnecessary complexity.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of QuickLinkViewSet across the codebase to confirm if GET retrieval by pk is needed.
rg -A 5 --heading $'QuickLinkViewSet'

Length of output: 853


Script:

#!/bin/bash
# Check the model and serializer implementation
ast-grep --pattern 'class WorkspaceUserLink'

# Check frontend API calls
rg -g '*.{ts,tsx}' 'quick-link.*pk'

Length of output: 84


Script:

#!/bin/bash
# Check the model definition
rg -A 10 "class WorkspaceUserLink"

# Check frontend API calls related to quick links
rg -g '*.{ts,tsx}' -A 5 "quick-link"

# Check serializer implementation
rg -A 10 "class WorkspaceUserLinkSerializer"

Length of output: 1718

@sangeethailango sangeethailango marked this pull request as ready for review December 30, 2024 08:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
apiserver/plane/app/serializers/workspace.py (1)

120-125: Consider more flexible URL handling

The current implementation automatically prepends "http://" to URLs without a protocol. This might not always be the desired behavior:

  1. Some URLs might intentionally use other protocols
  2. Internal URLs might not need a protocol

Consider this more flexible approach:

     def to_internal_value(self, data):
         url = data.get("url", "")
-        if url and not url.startswith(("http://", "https://")):
+        if url and not any(url.startswith(p) for p in ["http://", "https://", "/"]):
             data["url"] = "http://" + url
         
         return super().to_internal_value(data)
apiserver/plane/app/urls/workspace.py (1)

218-223: Fix URL pattern name formatting

There's an extra space in the URL pattern name.

Apply this fix:

     path(
         "workspaces/<str:slug>/quick-links/",
         QuickLinkViewSet.as_view({"get": "list", "post": "create"}),
-        name="workspace-quick-links "
+        name="workspace-quick-links"
     ),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64c2d0a and 48846e2.

📒 Files selected for processing (2)
  • apiserver/plane/app/serializers/workspace.py (2 hunks)
  • apiserver/plane/app/urls/workspace.py (2 hunks)
🔇 Additional comments (4)
apiserver/plane/app/serializers/workspace.py (2)

14-14: LGTM: Import statements are properly organized

The new imports are correctly placed and necessary for URL validation functionality.

Also applies to: 18-20


114-118: LGTM: Serializer configuration is properly structured

The serializer is correctly configured with appropriate read-only fields for workspace and owner.

apiserver/plane/app/urls/workspace.py (2)

30-30: LGTM: ViewSet import is properly placed

The QuickLinkViewSet import is correctly added to the existing imports.


219-228: Verify ViewSet implementation completeness

The URL patterns suggest CRUD operations (list, create, partial_update, destroy), but we should verify that the ViewSet properly implements all these methods.

Let's check the ViewSet implementation:

✅ Verification successful

ViewSet implementation is complete and correct

The implementation is properly structured and complete. Here's why:

  • QuickLinkViewSet inherits from BaseViewSet which extends Django's ModelViewSet
  • ModelViewSet automatically provides the standard list and destroy methods
  • The custom implementations for create and partial_update methods are properly defined with appropriate permissions and error handling
  • The base class provides proper queryset handling through get_queryset method
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify QuickLinkViewSet implementation completeness

# Search for QuickLinkViewSet class definition and its methods
ast-grep --pattern $'class QuickLinkViewSet {
  $$$
  list($$$) {
    $$$
  }
  $$$
  create($$$) {
    $$$
  }
  $$$
  partial_update($$$) {
    $$$
  }
  $$$
  destroy($$$) {
    $$$
  }
  $$$
}'

Length of output: 198


Script:

#!/bin/bash
# Let's try a different approach to find the QuickLinkViewSet implementation
# First, let's find the file containing QuickLinkViewSet
rg "class QuickLinkViewSet" -l

# Then let's see the full implementation with context
rg "class QuickLinkViewSet" -A 50

Length of output: 2452


Script:

#!/bin/bash
# Let's check the BaseViewSet to see if it provides the list and destroy methods
rg "class BaseViewSet" -A 20

# Also check if there are any other list/destroy method implementations in the quick_link.py file
rg "def (list|destroy)" apiserver/plane/app/views/workspace/quick_link.py

Length of output: 2701

Comment on lines +127 to +134
def validate_url(self, value):
url_validator = URLValidator()
try:
url_validator(value)
except ValidationError:
raise serializers.ValidationError({"error": "Invalid URL format."})

return value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance URL validation error handling

The current URL validation has two issues:

  1. Error message structure is inconsistent with DRF's standard format
  2. Validation could be more comprehensive

Consider this enhanced implementation:

     def validate_url(self, value):
         url_validator = URLValidator()
         try:
             url_validator(value)
         except ValidationError:
-            raise serializers.ValidationError({"error": "Invalid URL format."})
+            raise serializers.ValidationError("Invalid URL format.")
 
+        # Additional validation for security
+        if value.startswith("http://"):
+            raise serializers.ValidationError(
+                "For security reasons, only HTTPS URLs are allowed."
+            )
+
         return value
📝 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.

Suggested change
def validate_url(self, value):
url_validator = URLValidator()
try:
url_validator(value)
except ValidationError:
raise serializers.ValidationError({"error": "Invalid URL format."})
return value
def validate_url(self, value):
url_validator = URLValidator()
try:
url_validator(value)
except ValidationError:
raise serializers.ValidationError("Invalid URL format.")
# Additional validation for security
if value.startswith("http://"):
raise serializers.ValidationError(
"For security reasons, only HTTPS URLs are allowed."
)
return value

@sriramveeraghanta sriramveeraghanta deleted the feat-quick-links branch May 2, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants