feat: workspace user preference api#6497
Conversation
WalkthroughThis 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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (3)
✨ 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 (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
UserPreferenceKeysenum.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
📒 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
WorkspaceUserPreferenceViewSetis 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>/
Description
This PR will provide APIs for workspace user preferences.
Summary by CodeRabbit
New Features
Improvements