-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10707 from uditijmehta/feature/duplicate-notifica…
…tions-fix [ENG-5075] Add Admin Screen to Manage Duplicate Notifications - Refactor Duplicate Notifications
- Loading branch information
Showing
10 changed files
with
80 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,30 @@ | ||
from django.contrib.auth.decorators import user_passes_test | ||
from django.shortcuts import render, redirect | ||
from admin.base.utils import osf_staff_check | ||
from osf.models.notifications import NotificationSubscription | ||
from django.db.models import Count | ||
|
||
def delete_selected_notifications(selected_ids): | ||
NotificationSubscription.objects.filter(id__in=selected_ids).delete() | ||
|
||
def detect_duplicate_notifications(): | ||
duplicates = ( | ||
NotificationSubscription.objects.values('user', 'node', 'event_name') | ||
.annotate(count=Count('id')) | ||
.filter(count__gt=1) | ||
) | ||
def detect_duplicate_notifications(node_id=None): | ||
query = NotificationSubscription.objects.values('_id').annotate(count=Count('_id')).filter(count__gt=1) | ||
if node_id: | ||
query = query.filter(node_id=node_id) | ||
|
||
detailed_duplicates = [] | ||
for dup in duplicates: | ||
for dup in query: | ||
notifications = NotificationSubscription.objects.filter( | ||
user=dup['user'], node=dup['node'], event_name=dup['event_name'] | ||
_id=dup['_id'] | ||
).order_by('created') | ||
|
||
for notification in notifications: | ||
detailed_duplicates.append({ | ||
'id': notification.id, | ||
'user': notification.user, | ||
'node': notification.node, | ||
'_id': notification._id, | ||
'event_name': notification.event_name, | ||
'created': notification.created, | ||
'count': dup['count'] | ||
'count': dup['count'], | ||
'email_transactional': [u._id for u in notification.email_transactional.all()], | ||
'email_digest': [u._id for u in notification.email_digest.all()], | ||
'none': [u._id for u in notification.none.all()] | ||
}) | ||
|
||
return detailed_duplicates | ||
|
||
def process_duplicate_notifications(request): | ||
detailed_duplicates = detect_duplicate_notifications() | ||
|
||
if request.method == 'POST': | ||
selected_ids = request.POST.getlist('selected_notifications') | ||
delete_selected_notifications(selected_ids) | ||
return detailed_duplicates, 'Selected duplicate notifications have been deleted.', True | ||
|
||
return detailed_duplicates, '', False | ||
|
||
@user_passes_test(osf_staff_check) | ||
def handle_duplicate_notifications(request): | ||
detailed_duplicates, message, is_post = process_duplicate_notifications(request) | ||
|
||
context = {'duplicates': detailed_duplicates} | ||
if is_post: | ||
context['message'] = message | ||
return redirect('notifications:handle_duplicate_notifications') | ||
|
||
return render(request, 'notifications/handle_duplicate_notifications.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
admin/templates/notifications/handle_duplicate_notifications.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.