Skip to content

Comments

feat: workspace user preference api#6497

Merged
sriramveeraghanta merged 3 commits intopreviewfrom
workspace-user-preference-api
Jan 28, 2025
Merged

feat: workspace user preference api#6497
sriramveeraghanta merged 3 commits intopreviewfrom
workspace-user-preference-api

Conversation

@sangeethailango
Copy link
Member

@sangeethailango sangeethailango commented Jan 28, 2025

Description

This PR will provide APIs for workspace user preferences.

Summary by CodeRabbit

  • New Features

    • Added workspace user preferences functionality.
    • Introduced new API endpoints for managing user preferences in workspaces.
    • Expanded user preference options with new keys for Teams and Initiatives.
  • Improvements

    • Enhanced workspace management by allowing users to set and update specific preferences.
    • Implemented permission-based access to user preference management.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces a feature for managing workspace user preferences in the Plane application. It includes the addition of a new serializer, view, and URL routes, as well as extending the existing model with new enumeration values for user preferences. The changes allow users to retrieve and update their workspace-specific preferences, enhancing the API's capabilities while ensuring existing functionality remains unaffected.

Changes

File Change Summary
apiserver/plane/app/serializers/workspace.py Added WorkspaceUserPreferenceSerializer with read-only fields for workspace user preferences
apiserver/plane/app/urls/workspace.py Added two new URL patterns for workspace user preferences endpoints
apiserver/plane/app/views/__init__.py Imported WorkspaceUserPreferenceViewSet
apiserver/plane/app/views/workspace/user_preference.py Created WorkspaceUserPreferenceViewSet with get and patch methods for handling user preferences
apiserver/plane/db/models/__init__.py Added import for WorkspaceUserPreference
apiserver/plane/db/models/workspace.py Added TEAMS and INITIATIVES enum values to UserPreferenceKeys

Possibly related PRs

  • [WEB-3038]feat: home preferences #6308: Addition of WorkspaceHomePreferenceSerializer in this PR is directly related to the WorkspaceUserPreferenceSerializer in the main PR, as both serializers handle user preferences within the workspace context.

Suggested labels

📡api, ⚙️backend

Suggested reviewers

  • pablohashescobar
  • sriramveeraghanta

Poem

🐰 Hop, hop, preferences take flight!
In workspaces, settings shine bright
Teams and initiatives align
With user choices, so divine
Code rabbit's magic, pure delight! 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39c3187 and 0d1e8c8.

📒 Files selected for processing (1)
  • apiserver/plane/app/views/workspace/user_preference.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
apiserver/plane/app/views/workspace/user_preference.py (3)

1-19: LGTM! Well-structured class setup.

The imports are well-organized, and the class follows Django REST framework conventions with proper model and serializer configuration.


56-74: LGTM! Well-implemented PATCH endpoint.

The implementation follows REST framework best practices with proper:

  • Permission checks
  • Error handling
  • Status codes
  • Serializer validation

47-54: 🛠️ Refactor suggestion

Optimize database queries by removing redundant query.

The second preference query is unnecessary as we already have the data from the first query and bulk creation.

Refactor to use existing data:

-        preference = WorkspaceUserPreference.objects.filter(
-            user=request.user, workspace_id=workspace.id
-        )
-
-        return Response(
-            preference.values("key", "is_pinned", "sort_order"),
-            status=status.HTTP_200_OK,
-        )
+        return Response(
+            get_preference.values("key", "is_pinned", "sort_order"),
+            status=status.HTTP_200_OK,
+        )

Likely invalid or redundant comment.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 ready for review January 28, 2025 13:26
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: 3

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

47-53: Optimize database queries.

The code performs an additional query to fetch the same data. We can reuse the existing queryset.

-        preference = WorkspaceUserPreference.objects.filter(
-            user=request.user, workspace_id=workspace.id
-        )
-
-        return Response(
-            preference.values("key", "is_pinned", "sort_order"),
-            status=status.HTTP_200_OK,
-        )
+        return Response(
+            get_preference.values("key", "is_pinned", "sort_order"),
+            status=status.HTTP_200_OK,
+        )
apiserver/plane/app/serializers/workspace.py (1)

264-268: Add field validation to the serializer.

Consider adding validation for the fields to ensure data integrity:

 class WorkspaceUserPreferenceSerializer(BaseSerializer):
+    def validate_sort_order(self, value):
+        if value is not None and value < 0:
+            raise serializers.ValidationError("Sort order cannot be negative")
+        return value
+
     class Meta:
         model = WorkspaceUserPreference
         fields = ["key", "is_pinned", "sort_order"]
         read_only_fields = ["workspace", "created_by", "updated_by"]
apiserver/plane/db/models/workspace.py (1)

398-399: LGTM! Clean addition of preference keys.

The new preference keys for teams and initiatives follow the established pattern and naming convention of existing keys in the UserPreferenceKeys enum.

However, consider adding docstrings to describe the purpose and expected behavior of these preferences for better maintainability.

 class UserPreferenceKeys(models.TextChoices):
     CYCLES = "cycles", "Cycles"
     VIEWS = "views", "Views"
     ANALYTICS = "analytics", "Analytics"
-    TEAMS = "teams", "Teams"
-    INITIATIVES = "initiatives", "Initiatives"
+    TEAMS = "teams", "Teams"  # Controls team-related preferences such as pinning and sorting
+    INITIATIVES = "initiatives", "Initiatives"  # Controls initiative-related preferences such as pinning and sorting
     PROJECTS = "projects", "Projects"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 74913a6 and 39c3187.

📒 Files selected for processing (6)
  • 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/user_preference.py (1 hunks)
  • apiserver/plane/db/models/__init__.py (1 hunks)
  • apiserver/plane/db/models/workspace.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-apiserver
🔇 Additional comments (4)
apiserver/plane/db/models/__init__.py (1)

72-73: LGTM!

The import addition follows the module's established patterns.

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

51-51: LGTM!

The import addition follows the module's established patterns.

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

34-34: LGTM! Clean import addition.

The import of WorkspaceUserPreferenceViewSet is properly placed with other workspace-related view imports.


262-272: LGTM! Well-structured URL patterns for user preferences.

The URL patterns follow RESTful conventions and maintain consistency with existing workspace endpoints:

  • Base endpoint for collection operations: /workspaces/<str:slug>/user-preferences/
  • Key-specific endpoint for individual preference operations: /workspaces/<str:slug>/user-preferences/<str:key>/

@sangeethailango sangeethailango self-assigned this Jan 28, 2025
@sriramveeraghanta sriramveeraghanta merged commit 6a8d320 into preview Jan 28, 2025
12 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the workspace-user-preference-api branch January 28, 2025 15:20
@coderabbitai coderabbitai bot mentioned this pull request Feb 10, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants