Skip to content
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
7 changes: 7 additions & 0 deletions admin/nodes/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import forms


class RegistrationDateForm(forms.Form):
registered_date = forms.DateTimeField(
widget=forms.DateTimeInput(attrs={'class': 'form-control'}),
)
1 change: 1 addition & 0 deletions admin/nodes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
re_path(r'^(?P<guid>[a-z0-9]+)/logs/$', views.AdminNodeLogView.as_view(), name='node-logs'),
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_registration_date/$', views.RegistrationUpdateDateView.as_view(), name='update-registration-date'),
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'),
Expand Down
34 changes: 34 additions & 0 deletions admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from admin.base.views import GuidView
from admin.base.forms import GuidForm
from admin.notifications.views import delete_selected_notifications
from admin.nodes.forms import RegistrationDateForm

from api.share.utils import update_share
from api.caching.tasks import update_storage_usage_cache
Expand Down Expand Up @@ -89,6 +90,36 @@ def get_success_url(self):
return reverse('nodes:node', kwargs={'guid': self.kwargs['guid']})


class RegistrationUpdateDateView(NodeMixin, View):
permission_required = 'osf.change_node'
raise_exception = True

def post(self, request, *args, **kwargs):
node = self.get_object()
form = RegistrationDateForm(request.POST)
if form.is_valid():
last_date = node.registered_date
new_date = form.cleaned_data['registered_date']
node.registered_date = new_date
node.created = new_date
node.save()

node.add_log(
action=NodeLog.REGISTRATION_DATE_UPDATED,
auth=request,
params={
'last_date': str(last_date),
'new_date': str(new_date)
},
log_date=timezone.now(),
should_hide=False,
Copy link
Contributor

@ihorsokhanexoft ihorsokhanexoft Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be True so that this log doesn't update last_logged date of the registration as it's an admin action. This parameter is responsible for updating or not last_logged attribute

osf.io/osf/models/mixins.py

Lines 144 to 145 in 376c526

if not log.should_hide:
self.last_logged = last_logged

After that, assign this ticket to Yuhuai for code review

)
messages.success(request, 'Registration date updated successfully.')
else:
messages.error(request, 'Please enter a valid date.')
return redirect(self.get_success_url())


class NodeView(NodeMixin, GuidView):
""" Allows authorized users to view node info.
"""
Expand All @@ -100,6 +131,9 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
node = self.get_object()

if isinstance(node, Registration):
context['registration_date_form'] = RegistrationDateForm(initial={'registered_date': node.registered_date})

children = node.get_nodes(is_node_link=False)
# Annotate guid because django templates prohibit accessing attributes that start with underscores
children = AbstractNode.objects.filter(
Expand Down
22 changes: 22 additions & 0 deletions admin/templates/nodes/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ <h2>{{ node.type|cut:'osf.'|title }}: <b>{{ node.title }}</b> <a href="{{ node.a
<td>Guid</td>
<td>{{ node.guid }}</td>
</tr>
<tr>
<td>Created</td>
<td>{{ node.created }}</td>
</tr>
{% if node.is_registration %}
<tr>
<td>Registered Date</td>
<td>{{ node.registered_date }}</td>
</tr>
{% if registration_date_form %}
<tr>
<td></td>
<td>
<form method="post" action="{% url 'nodes:update-registration-date' guid=node.guid %}">
{% csrf_token %}
{{ registration_date_form.as_p }}
<button type="submit" class="btn btn-primary">Update Date</button>
</form>
</td>
</tr>
{% endif %}
{% endif %}
<tr>
<td>Title</td>
<td>{{ node.title }}</td>
Expand Down
3 changes: 2 additions & 1 deletion osf/models/nodelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class NodeLog(ObjectIDMixin, BaseModel):

CATEGORY_UPDATED = 'category_updated'
ARTICLE_DOI_UPDATED = 'article_doi_updated'
REGISTRATION_DATE_UPDATED = 'registration_date_updated'

ADDON_ADDED = 'addon_added'
ADDON_REMOVED = 'addon_removed'
Expand Down Expand Up @@ -153,7 +154,7 @@ class NodeLog(ObjectIDMixin, BaseModel):
WIKI_DELETED, WIKI_RENAMED, MADE_WIKI_PUBLIC,
MADE_WIKI_PRIVATE, CONTRIB_ADDED, CONTRIB_REMOVED, CONTRIB_REORDERED, CURATOR_ADDED, CURATOR_REMOVED,
PERMISSIONS_UPDATED, MADE_PRIVATE, MADE_PUBLIC, TAG_ADDED, TAG_REMOVED, EDITED_TITLE,
EDITED_DESCRIPTION, UPDATED_FIELDS, FILE_MOVED, FILE_COPIED, FILE_METADATA_UPDATED,
EDITED_DESCRIPTION, REGISTRATION_DATE_UPDATED, UPDATED_FIELDS, FILE_MOVED, FILE_COPIED, FILE_METADATA_UPDATED,
FOLDER_CREATED, FILE_ADDED, FILE_UPDATED, FILE_REMOVED, FILE_RESTORED, ADDON_ADDED,
ADDON_REMOVED, COMMENT_ADDED, COMMENT_REMOVED, COMMENT_UPDATED, COMMENT_RESTORED,
MADE_CONTRIBUTOR_VISIBLE, CONFIRM_HAM, FLAG_SPAM, CONFIRM_SPAM,
Expand Down
1 change: 1 addition & 0 deletions website/static/js/logActionsList.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"subjects_updated": "${user} updated the subjects on ${node}",
"view_only_link_added": "${user} created ${anonymous_link} view-only link to ${node}",
"view_only_link_removed": "${user} removed ${anonymous_link} view-only link to ${node}",
"registration_date_updated": "${user} updated registration date of ${node} from ${last_date} to ${new_date}",
"has_coi_updated": "${user} changed the conflict of interest statement availability for ${preprint}.",
"coi_statement_updated": "${user} changed the conflict of interest statement for ${preprint}.",
"has_data_links_updated": "${user} has updated the has links to data field to ${value}",
Expand Down