-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[WEB-2383] feat: Inbox Settings v2 #6644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
Changes from all commits
831c936
6b5d007
266de8c
5618160
b22f5f8
77253c9
6cd1a33
5590ccc
a2717ae
75916ce
05c7dc5
fe62709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||||||||||||
from ..base import BaseAPIView | ||||||||||||||
from plane.db.models.workspace import WorkspaceHomePreference | ||||||||||||||
from plane.app.permissions import allow_permission, ROLE | ||||||||||||||
from plane.db.models import Workspace | ||||||||||||||
from plane.db.models import Workspace, WorkspaceUserNotificationPreference, NotificationTransportChoices | ||||||||||||||
from plane.app.serializers.workspace import WorkspaceHomePreferenceSerializer | ||||||||||||||
|
||||||||||||||
# Third party imports | ||||||||||||||
|
@@ -59,6 +59,37 @@ def get(self, request, slug): | |||||||||||||
user=request.user, workspace_id=workspace.id | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
# Notification preference get or create | ||||||||||||||
workspace = Workspace.objects.get(slug=slug) | ||||||||||||||
get_notification_preferences = ( | ||||||||||||||
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove redundant workspace fetch. The workspace object is already fetched on line 21, so there's no need to fetch it again here. This redundant fetch can be removed to improve performance. # Notification preference get or create
- workspace = Workspace.objects.get(slug=slug)
get_notification_preferences = (
WorkspaceUserNotificationPreference.objects.filter( 📝 Committable suggestion
Suggested change
|
||||||||||||||
WorkspaceUserNotificationPreference.objects.filter( | ||||||||||||||
workspace=workspace, user=request.user | ||||||||||||||
) | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
create_transports = [] | ||||||||||||||
|
||||||||||||||
transports = [ | ||||||||||||||
transport | ||||||||||||||
for transport, _ in NotificationTransportChoices.choices | ||||||||||||||
] | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
for transport in transports: | ||||||||||||||
if transport not in get_notification_preferences.values_list( | ||||||||||||||
"transport", flat=True | ||||||||||||||
): | ||||||||||||||
create_transports.append(transport) | ||||||||||||||
|
||||||||||||||
_ = WorkspaceUserNotificationPreference.objects.bulk_create( | ||||||||||||||
[ | ||||||||||||||
WorkspaceUserNotificationPreference( | ||||||||||||||
workspace=workspace, user=request.user, transport=transport | ||||||||||||||
) | ||||||||||||||
for transport in create_transports | ||||||||||||||
] | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
return Response( | ||||||||||||||
preference.values("key", "is_enabled", "config", "sort_order"), | ||||||||||||||
status=status.HTTP_200_OK, | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 377 to 395 can be clubbed into the following.
This will be concise and improve readability of the code.