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-source-tags * 'feature/b-and-i-24-14' of https://github.com/CenterForOpenScience/osf.io: 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: # addons/boa/requirements.txt # addons/box/requirements.txt # addons/dataverse/requirements.txt # addons/dropbox/requirements.txt # addons/github/requirements.txt # addons/gitlab/requirements.txt # addons/mendeley/requirements.txt # addons/owncloud/requirements.txt # addons/s3/requirements.txt # addons/twofactor/requirements.txt # addons/wiki/requirements.txt # addons/zotero/requirements.txt # api/base/utils.py # api/users/serializers.py # api_tests/draft_registrations/views/test_draft_registration_list.py # api_tests/nodes/views/test_node_draft_registration_list.py # api_tests/users/views/test_user_draft_registration_list.py # api_tests/users/views/test_user_settings.py # docker-compose.yml # poetry.lock # pyproject.toml # requirements.txt # requirements/dev.txt # requirements/release.txt # tests/test_views.py # website/util/metrics.py
- Loading branch information
Showing
57 changed files
with
1,605 additions
and
1,074 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Requirements for the boa add-on | ||
boa-api==0.1.14 | ||
|
||
# Requirements for running asyncio in celery, using 3.4.1 for Python 3.6 compatibility | ||
asgiref==3.7.2 |
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 @@ | ||
boxsdk==3.9.2 |
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,3 @@ | ||
# Allow for optional timeout parameter. | ||
# https://github.com/IQSS/dataverse-client-python/pull/27 | ||
git+https://github.com/CenterForOpenScience/dataverse-client-python.git@2b3827578048e6df3818f82381c7ea9a2395e526 # branch is feature/dv-client-updates |
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 @@ | ||
dropbox==11.36.2 |
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,3 @@ | ||
cachecontrol==0.14.0 | ||
github3.py==4.0.1 | ||
uritemplate==4.1.1 |
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 @@ | ||
python-gitlab==4.4.0 |
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,2 @@ | ||
# up-to-date with mendeley's master + add folder support and future dep updates | ||
git+https://github.com/CenterForOpenScience/mendeley-python-sdk.git@be8a811fa6c3b105d9f5c656cabb6b1ba855ed5b # branch is feature/osf-dep-updates |
Empty file.
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,2 @@ | ||
# Requirements for the owncloud add-on | ||
pyocclient==0.6.0 |
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 @@ | ||
boto3==1.34.60 |
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 @@ | ||
pyotp==2.9.0 |
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 @@ | ||
pymongo==4.6.3 |
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 @@ | ||
Pyzotero==1.5.18 |
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
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: 54 additions & 0 deletions
54
admin/templates/notifications/handle_duplicate_notifications.html
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 @@ | ||
{% extends "base.html" %} | ||
{% load render_bundle from webpack_loader %} | ||
{% load static %} | ||
|
||
{% block title %} | ||
<title>Duplicate Notifications</title> | ||
{% endblock title %} | ||
|
||
{% block content %} | ||
<h2>Duplicate Notifications</h2> | ||
|
||
{% if message %} | ||
<div class="alert alert-success"> | ||
{{ message }} | ||
</div> | ||
{% endif %} | ||
|
||
{% if duplicates %} | ||
<form method="post"> | ||
{% csrf_token %} | ||
<table class="table table-striped table-hover table-responsive"> | ||
<thead> | ||
<tr> | ||
<th>Select</th> | ||
<th>User</th> | ||
<th>Node</th> | ||
<th>Event Name</th> | ||
<th>Created</th> | ||
<th>Count</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for notification in duplicates %} | ||
<tr> | ||
<td><input type="checkbox" name="selected_notifications" value="{{ notification.id }}"></td> | ||
<td>{{ notification.user }}</td> | ||
<td>{{ notification.node }}</td> | ||
<td>{{ notification.event_name }}</td> | ||
<td>{{ notification.created }}</td> | ||
<td>{{ notification.count }}</td> | ||
</tr> | ||
{% empty %} | ||
<tr> | ||
<td colspan="6">No duplicate notifications found!</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
<button type="submit" class="btn btn-danger">Delete Selected</button> | ||
</form> | ||
{% else %} | ||
<p>No duplicate notifications found.</p> | ||
{% endif %} | ||
{% endblock content %} |
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,22 @@ | ||
{% load node_extras %} | ||
<tr> | ||
<td>Machine State</td> | ||
<td> | ||
<h4 >{{ preprint.machine_state }}</h4> | ||
<h4 >{{ preprint.state }}</h4> | ||
{% if perms.osf.change_preprint %} | ||
<a class="btn btn-link" role="button" data-toggle="collapse" href="#collapseChangeMachineState"> | ||
Change preprint machine_state | ||
</a> | ||
<div class="collapse" id="collapseChangeMachineState"> | ||
<div class="well"> | ||
<form action="{% url 'preprints:preprint-machine-state' guid=preprint.guid %}" method="post"> | ||
{% csrf_token %} | ||
{{ change_machine_state_form.as_p }} | ||
<input class="btn-btn-primary" type="submit" value="Submit" /> | ||
</form> | ||
</div> | ||
</div> | ||
{% endif %} | ||
</td> | ||
</tr> |
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
Empty file.
Oops, something went wrong.