Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/feature/b-and-i-25-01' into fe…
Browse files Browse the repository at this point in the history
…ature/allow-for-un-withdrawing-preprint-via-admin

# Conflicts:
#	admin/preprints/urls.py
#	admin/preprints/views.py
  • Loading branch information
bodintsov committed Feb 11, 2025
2 parents efdf94c + 1855d55 commit c76d0c2
Show file tree
Hide file tree
Showing 71 changed files with 8,778 additions and 6,935 deletions.
1 change: 1 addition & 0 deletions admin/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
re_path(r'^schema_responses/', include('admin.schema_responses.urls', namespace='schema_responses')),
re_path(r'^registration_schemas/', include('admin.registration_schemas.urls', namespace='registration_schemas')),
re_path(r'^cedar_metadata_templates/', include('admin.cedar.urls', namespace='cedar_metadata_templates')),
re_path(r'^draft_registrations/', include('admin.draft_registrations.urls', namespace='draft_registrations')),
]),
),
]
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions admin/draft_registrations/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import re_path

from admin.draft_registrations import views


app_name = 'draft_registrations'


urlpatterns = [
re_path(r'^$', views.UserDraftRegistrationSearchView.as_view(), name='search'),
re_path(r'^(?P<draft_registration_id>\w+)/$', views.DraftRegistrationView.as_view(), name='detail'),
]
54 changes: 54 additions & 0 deletions admin/draft_registrations/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.urls import NoReverseMatch, reverse
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.shortcuts import redirect
from django.views.generic import FormView
from django.views.generic import DetailView

from admin.base.forms import GuidForm
from osf.models.registrations import DraftRegistration


class DraftRegistrationMixin(PermissionRequiredMixin):

def get_object(self):
draft_registration = DraftRegistration.load(self.kwargs['draft_registration_id'])
draft_registration.guid = draft_registration._id
return draft_registration

def get_success_url(self):
return reverse('draft_registrations:detail', kwargs={
'draft_registration_id': self.kwargs['draft_registration_id']
})


class UserDraftRegistrationSearchView(PermissionRequiredMixin, FormView):
""" Allows authorized users to search for user's draft registrations by his guid.
"""
template_name = 'draft_registrations/search.html'
permission_required = 'osf.view_osfuser'
raise_exception = True
form_class = GuidForm

def form_valid(self, form):
guid = form.cleaned_data['guid']
if guid:
try:
return redirect(reverse('users:draft-registrations', kwargs={'guid': guid}))
except NoReverseMatch as e:
messages.error(self.request, str(e))

return super().form_valid(form)


class DraftRegistrationView(DraftRegistrationMixin, DetailView):
""" Allows authorized users to view draft registration
"""
template_name = 'draft_registrations/detail.html'
permission_required = 'osf.view_draftregistration'

def get_context_data(self, **kwargs):
draft_registration = self.get_object()
return super().get_context_data(**{
'draft_registration': draft_registration
}, **kwargs)
11 changes: 10 additions & 1 deletion admin/nodes/templatetags/node_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
AbstractNode,
Contributor,
Preprint,
PreprintContributor
PreprintContributor,
DraftRegistration,
DraftRegistrationContributor
)

from osf.models.spam import SpamStatus
Expand Down Expand Up @@ -57,6 +59,11 @@ def reverse_schema_response(value):
return reverse('schema_responses:detail', kwargs={'schema_response_id': value.id})


@register.filter
def reverse_draft_registration(value):
return reverse('draft_registrations:detail', kwargs={'draft_registration_id': value._id})


@register.filter
def order_by(queryset, args):
args = [x.strip() for x in args.split(',')]
Expand All @@ -69,6 +76,8 @@ def get_permissions(user, resource):
return Contributor.objects.get(user=user, node=resource).permission
elif isinstance(resource, Preprint):
return PreprintContributor.objects.get(user=user, preprint=resource).permission
elif isinstance(resource, DraftRegistration):
return DraftRegistrationContributor.objects.get(user=user, draft_registration=resource).permission


@register.simple_tag
Expand Down
2 changes: 2 additions & 0 deletions admin/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
re_path(r'^(?P<guid>\w+)/reindex_elastic_preprint/$', views.PreprintReindexElastic.as_view(), name='reindex-elastic-preprint'),
re_path(r'^(?P<guid>\w+)/approve_withdrawal/$', views.PreprintApproveWithdrawalRequest.as_view(), name='approve-withdrawal'),
re_path(r'^(?P<guid>\w+)/reject_withdrawal/$', views.PreprintRejectWithdrawalRequest.as_view(), name='reject-withdrawal'),
re_path(r'^(?P<guid>\w+)/resync_crossref/$', views.PreprintResyncCrossRefView.as_view(), name='resync-crossref'),
re_path(r'^(?P<guid>\w+)/make_published/$', views.PreprintMakePublishedView.as_view(), name='make-published'),
re_path(r'^(?P<guid>\w+)/unwithdraw/$', views.PreprintUnwithdrawView.as_view(), name='unwithdraw'),
]
22 changes: 22 additions & 0 deletions admin/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,28 @@ def post(self, request, *args, **kwargs):

return redirect(self.get_success_url())


class PreprintResyncCrossRefView(PreprintMixin, View):
""" Allows an authorized user to run resync with CrossRef for a single object.
"""
permission_required = 'osf.change_node'

def post(self, request, *args, **kwargs):
preprint = self.get_object()
preprint.request_identifier_update('doi', create=True)
return redirect(self.get_success_url())


class PreprintMakePublishedView(PreprintMixin, View):
""" Allows an authorized user to make a preprint published.
"""
permission_required = 'osf.change_node'

def post(self, request, *args, **kwargs):
preprint = self.get_object()
preprint.set_published(True, request, True)
return redirect(self.get_success_url())

class PreprintUnwithdrawView(PreprintMixin, View):
""" Allows authorized users to unwithdraw a preprint that was previously withdrawn.
"""
Expand Down
10 changes: 10 additions & 0 deletions admin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
</ul>
</div>
{% endif %}
{% if perms.osf.view_draftregistration %}
<li><a role="button" data-toggle="collapse" href="#collapseDraftRegistrations">
<i class='fa fa-caret-down'></i> Draft Registrations
</a></li>
<div class="collapse" id="collapseDraftRegistrations">
<ul class="sidebar-menu sidebar-menu-inner">
<li><a href="{% url 'draft_registrations:search' %}"><i class='fa fa-link'></i> <span>Search Draft Registrations</span></a></li>
</ul>
</div>
{% endif %}
{% if perms.osf.view_spam %}
<li><a href="{% url 'comments:comments' %}"><i class='fa fa-link'></i> <span>Flagged Comments</span></a></li>
{% endif %}
Expand Down
29 changes: 29 additions & 0 deletions admin/templates/draft_registrations/contributors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load node_extras %}

<tr>
<td>Contributors</td>
<td>
<table class="table table-bordered table-hover">
<thead>
<tr>
<td>Email</td>
<td>Name</td>
<td>Permissions</td>
</tr>
</thead>
<tbody>
{% for user in draft_registration.contributors %}
<tr>
<td>
<a href="{{ user | reverse_user }}">
{{ user }}
</a>
</td>
<td>{{ user.fullname }}</td>
<td>{% get_permissions user draft_registration %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</td>
</tr>
67 changes: 67 additions & 0 deletions admin/templates/draft_registrations/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% extends 'base.html' %}
{% load static %}
{% load node_extras %}
{% block title %}
<title>{{ draft_registration.type|cut:'osf.'|title }}: {{draft_registration.guid}} </title>
{% endblock title %}
{% block content %}
<div class="container-fluid">
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
<div class="row">
<h2>Draft Registration: <b>{{ draft_registration.title }}</b> <a href="{{ draft_registration.absolute_url }}"> ({{draft_registration.guid}})</a> </h2>
<table class="table table-striped">
<thead>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>ID</td>
<td>{{ draft_registration.guid }}</td>
</tr>
<tr>
<td>Url</td>
<td><a href="{{ draft_registration.absolute_url }}">{{ draft_registration.absolute_url }}</a></td>
</tr>
<tr>
<td>Title</td>
<td>{{ draft_registration.title }}</td>
</tr>
<tr>
<td>Creator</td>
<td><a href="{{ draft_registration.creator | reverse_user }}">{{ draft_registration.creator }}</a></td>
</tr>
<tr>
<td>Deleted</td>
<td>{{ draft_registration.deleted }}</td>
</tr>
<tr>
<td>Public</td>
<td>{{ draft_registration.is_public }}</td>
</tr>
<tr>
<td>Provider</td>
{% if draft_registration.provider %}
<td><a href="{{ draft_registration | reverse_registration_provider }}">{{ draft_registration.provider.name }}</a></td>
{% else %}
<td>None</td>
{% endif %}
</tr>
{% include "draft_registrations/contributors.html" with draft_registration=draft_registration %}
<tr>
<td>Node storage usage</td>
<td>
<b>Current usage:</b> {{ draft_registration.storage_usage }}<br>
</td>
</tr>
</tbody>
</table>
</div>
</div>
{% endblock content %}
23 changes: 23 additions & 0 deletions admin/templates/draft_registrations/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% load static %}
{#{% load node_extras %}#}
{% block title %}
<title>Draft Registrations Search</title>
{% endblock title %}
{% block content %}
<div class="container-fluid">
<div class="row">
<form action="{% url 'draft_registrations:search' %}" method="post">
{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger">{{ form.errors }}</div>
{% endif %}
<div class="form-group">
<label for="guid">User GUID:</label>
{{ form.guid }}
</div>
<input type="submit" class="btn btn-primary" value="Submit" />
</form>
</div>
</div>
{% endblock content %}
24 changes: 24 additions & 0 deletions admin/templates/preprints/make_published.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% if not preprint.is_published %}
<a data-toggle="modal" data-target="#confirmPublished" class="btn btn-info">
Make Published
</a>
<div class="modal" id="confirmPublished">
<div class="modal-dialog">
<div class="modal-content">
<form class="well" method="post" action="{% url 'preprints:make-published' guid=preprint.guid %}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3>Are you sure you want to make this preprint published?</h3>
</div>
{% csrf_token %}
<div class="modal-footer">
<input class="btn btn-danger" type="submit" value="Confirm" />
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
2 changes: 2 additions & 0 deletions admin/templates/preprints/preprint.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
{% include "preprints/mark_spam.html" with preprint=preprint %}
{% include "preprints/reindex_preprint_share.html" with preprint=preprint %}
{% include "preprints/reindex_preprint_elastic.html" with preprint=preprint %}
{% include "preprints/resync_crossref.html" with preprint=preprint %}
{% include "preprints/make_private.html" with preprint=preprint %}
{% include "preprints/make_public.html" with preprint=preprint %}
{% include "preprints/make_published.html" with preprint=preprint %}
</div>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions admin/templates/preprints/resync_crossref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% if preprint.article_doi %}
<a data-toggle="modal" data-target="#confirmResyncCrossRef" class="btn btn-info">
Resync with Crossref
</a>
<div class="modal" id="confirmResyncCrossRef">
<div class="modal-dialog">
<div class="modal-content">
<form class="well" method="post" action="{% url 'preprints:resync-crossref' guid=preprint.guid %}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3>Are you sure you want to resync with CrossRef?</h3>
</div>
{% csrf_token %}
<div class="modal-footer">
<input class="btn btn-danger" type="submit" value="Confirm" />
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
42 changes: 42 additions & 0 deletions admin/templates/users/draft-registrations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends 'base.html' %}
{% load node_extras %}
{% include "util/pagination.html" with items=page status=status %}
{% block content %}
<table class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Date created</th>
<th>Public</th>
<th>Contributors</th>
</tr>
</thead>
<tbody>
{% for draft_registration in draft_registrations %}
<tr>
<td>
<a href="{{ draft_registration | reverse_draft_registration }}"
class="btn btn-primary">
{{ draft_registration.guid }}
</a>
</td>
<td>
{{draft_registration.title}}
</td>
<td>
{{ draft_registration.created| date }}
</td>
<td>
{{ draft_registration.is_public }}
</td>
<td>
{% for user in draft_registration.contributors %}
<a href="{{ user | reverse_user }}">{{ user.username }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
1 change: 1 addition & 0 deletions admin/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
re_path(r'^(?P<guid>[a-z0-9]+)/reindex_elastic_user/$', views.UserReindexElastic.as_view(),
name='reindex-elastic-user'),
re_path(r'^(?P<guid>[a-z0-9]+)/merge_accounts/$', views.UserMergeAccounts.as_view(), name='merge-accounts'),
re_path(r'^(?P<guid>[a-z0-9]+)/draft_registrations/$', views.UserDraftRegistrationsList.as_view(), name='draft-registrations'),
]
Loading

0 comments on commit c76d0c2

Please sign in to comment.