forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/b-and-i-24-14' of https://github.com/CenterForO…
…penScience/osf.io into fix-preprint-emails * 'feature/b-and-i-24-14' of https://github.com/CenterForOpenScience/osf.io: Make resubmissions more like submissions (CenterForOpenScience#10709) renamed files with travis in their names fixed case where it was more appropriate removed all travis mentions and replaced them with CI [ENG-2562] add system tags to users created via institutional sign up system (CenterForOpenScience#10696) refactor handle_duplicate_notifications and add tests Shorten lines; rename script for test clarity fix flake8 errors add admin screen to manage duplicate notifications [ENG-2814] Allow Read-only and Read/Write contributors to view a project's draft registrations (CenterForOpenScience#10660) [CR][ENG-5997] merge develop into b-and-i branch (CenterForOpenScience#10691) add exception handling in case state doesn't change [ENG-4527] Fix citation to use registered date (CenterForOpenScience#10678) restrict state changes more and allow no-ops split apart change provider views from general preprint view and machine_state change viewa Re-add permissions changes for files on withdrawn registrations (CenterForOpenScience#10671) [ENG-4903] Fixes issue with email confirmation links failing due to database congestion (CenterForOpenScience#10662) # Conflicts: # osf/utils/notifications.py # website/templates/emails/reviews_resubmission_confirmation.html.mako
- Loading branch information
Showing
58 changed files
with
1,520 additions
and
1,306 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 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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import re_path | ||
from admin.notifications import views | ||
|
||
app_name = 'notifications' | ||
|
||
urlpatterns = [ | ||
re_path(r'^$', views.handle_duplicate_notifications, name='handle_duplicate_notifications'), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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) | ||
) | ||
|
||
detailed_duplicates = [] | ||
for dup in duplicates: | ||
notifications = NotificationSubscription.objects.filter( | ||
user=dup['user'], node=dup['node'], event_name=dup['event_name'] | ||
).order_by('created') | ||
|
||
for notification in notifications: | ||
detailed_duplicates.append({ | ||
'id': notification.id, | ||
'user': notification.user, | ||
'node': notification.node, | ||
'event_name': notification.event_name, | ||
'created': notification.created, | ||
'count': dup['count'] | ||
}) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
from django import forms | ||
|
||
from osf.models import Preprint | ||
|
||
from osf.utils.workflows import ReviewStates | ||
|
||
class ChangeProviderForm(forms.ModelForm): | ||
class Meta: | ||
model = Preprint | ||
fields = ('provider',) | ||
|
||
|
||
class MachineStateForm(forms.ModelForm): | ||
class Meta: | ||
model = Preprint | ||
fields = ('machine_state',) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
if not self.instance.is_public: | ||
self.fields['machine_state'].widget.attrs['disabled'] = 'disabled' | ||
else: | ||
if self.instance.machine_state == ReviewStates.INITIAL.db_name: | ||
self.fields['machine_state'].choices = [ | ||
(ReviewStates.INITIAL.value, ReviewStates.INITIAL.value), | ||
(ReviewStates.PENDING.value, ReviewStates.PENDING.value), | ||
] | ||
else: | ||
# Disabled Option you are on | ||
self.fields['machine_state'].widget.attrs['disabled'] = 'disabled' | ||
self.fields['machine_state'].choices = [ | ||
(self.instance.machine_state.title(), self.instance.machine_state) | ||
] |
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
Oops, something went wrong.