Skip to content

[ENG-7977] Add ability for admin app to change registry that a registration belongs to #11145

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

Open
wants to merge 1 commit into
base: feature/pbs-25-10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/nodes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
re_path(r'^(?P<guid>[a-z0-9]+)/schema_responses/$', views.AdminNodeSchemaResponseView.as_view(),
name='schema-responses'),
re_path(r'^(?P<guid>[a-z0-9]+)/update_embargo/$', views.RegistrationUpdateEmbargoView.as_view(), name='update-embargo'),
re_path(r'^(?P<guid>[a-z0-9]+)/change_provider/$', views.RegistrationChangeProviderView.as_view(), name='change-provider'),
re_path(r'^(?P<guid>[a-z0-9]+)/remove/$', views.NodeDeleteView.as_view(), name='remove'),
re_path(r'^(?P<guid>[a-z0-9]+)/restore/$', views.NodeDeleteView.as_view(), name='restore'),
re_path(r'^(?P<guid>[a-z0-9]+)/confirm_spam/$', views.NodeConfirmSpamView.as_view(), name='confirm-spam'),
Expand Down
25 changes: 24 additions & 1 deletion admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ListView,
TemplateView,
)
from django.shortcuts import redirect, reverse
from django.shortcuts import redirect, reverse, get_object_or_404
from django.urls import reverse_lazy

from admin.base.utils import change_embargo_date
Expand All @@ -33,6 +33,7 @@
NodeLog,
AbstractNode,
Registration,
RegistrationProvider,
RegistrationApproval,
SpamStatus
)
Expand Down Expand Up @@ -398,6 +399,28 @@ def post(self, request, *args, **kwargs):
return redirect(self.get_success_url())


class RegistrationChangeProviderView(NodeMixin, View):
""" Allows authorized users to update provider of a registration.
"""
permission_required = ('osf.change_node')

def post(self, request, *args, **kwargs):
provider_id = int(request.POST.get('provider_id'))
provider = get_object_or_404(RegistrationProvider, pk=provider_id)
registration = self.get_object()

try:
provider.validate_schema(registration.registration_schema)
registration.provider = provider
registration.save()
except ValidationError as exc:
messages.error(request, str(exc))
else:
messages.success(request, 'Provider successfully changed.')

return redirect(self.get_success_url())


class NodeSpamList(PermissionRequiredMixin, ListView):
""" Allows authorized users to view a list of nodes that have a particular spam status.
"""
Expand Down
8 changes: 3 additions & 5 deletions admin/templates/nodes/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ <h2>{{ node.type|cut:'osf.'|title }}: <b>{{ node.title }}</b> <a href="{{ node.a
</tr>
<tr>
<td>Provider</td>
{% if node.provider %}
<td><a href="{{ node | reverse_registration_provider }}">{{ node.provider.name }}</a></td>
{% else %}
<td>None</td>
{% endif %}
<td>
{% include "nodes/registration_provider.html" with node=node %}
</td>
</tr>
<tr>
<td>Parent</td>
Expand Down
17 changes: 17 additions & 0 deletions admin/templates/nodes/registration_provider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% load node_extras %}

{% if node.provider %}
<form id="provider-list-form" method="post" action="{% url 'nodes:change-provider' guid=node.guid %}">
{% csrf_token %}
<select id="provider-list" name="provider_id" onchange="this.form.submit()">
<option value="{{ node.provider.id }}">{{ node.provider.name }}</option> <!-- default value -->
{% for provider in node.available_providers %}
{% if not provider.id == node.provider.id %}
<option value="{{ provider.id }}">{{ provider.name }}</option>
{% endif %}
{% endfor %}
</select>
</form>
{% else %}
<p>None</p>
{% endif %}
8 changes: 8 additions & 0 deletions osf/models/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ def date_withdrawn(self):
def withdrawal_justification(self):
return getattr(self.root.retraction, 'justification', None)

@property
def available_providers(self):
"""Return all providers that support current registration schema."""
schema = self.registration_schema
if not schema:
return RegistrationProvider.objects.none()
return RegistrationProvider.objects.filter(schemas=schema)

@property
def provider_specific_metadata(self):
"""Surfaces the additional_metadata fields supported by the provider.
Expand Down
Loading