|
1 | | -import pytz |
2 | | -from enum import Enum |
3 | 1 | from datetime import datetime |
4 | | -from framework import status |
| 2 | +from enum import Enum |
5 | 3 |
|
6 | | -from django.utils import timezone |
7 | | -from django.core.exceptions import PermissionDenied, ValidationError |
8 | | -from django.urls import NoReverseMatch |
| 4 | +import pytz |
9 | 5 | from django.db import transaction |
10 | | -from django.db.models import F, Case, When, IntegerField |
11 | 6 | from django.contrib import messages |
12 | 7 | from django.contrib.auth.mixins import PermissionRequiredMixin |
| 8 | +from django.core.exceptions import PermissionDenied, ValidationError |
| 9 | +from django.db.models import F, Case, When, IntegerField |
13 | 10 | from django.http import HttpResponse |
| 11 | +from django.shortcuts import redirect, reverse, get_object_or_404 |
| 12 | +from django.urls import NoReverseMatch |
| 13 | +from django.urls import reverse_lazy |
| 14 | +from django.utils import timezone |
14 | 15 | from django.views.generic import ( |
15 | 16 | View, |
16 | 17 | FormView, |
17 | 18 | ListView, |
18 | 19 | ) |
19 | | -from django.shortcuts import redirect, reverse, get_object_or_404 |
20 | | -from django.urls import reverse_lazy |
21 | 20 |
|
| 21 | +from admin.base.forms import GuidForm |
22 | 22 | from admin.base.utils import change_embargo_date |
23 | 23 | from admin.base.views import GuidView |
24 | | -from admin.base.forms import GuidForm |
25 | | -from admin.notifications.views import delete_selected_notifications |
26 | 24 | from admin.nodes.forms import AddSystemTagForm, RegistrationDateForm |
27 | | - |
28 | | -from api.share.utils import update_share |
| 25 | +from admin.notifications.views import delete_selected_notifications |
29 | 26 | from api.caching.tasks import update_storage_usage_cache |
30 | | - |
| 27 | +from api.share.utils import update_share |
| 28 | +from framework import status |
31 | 29 | from osf.exceptions import NodeStateError, RegistrationStuckError |
32 | 30 | from osf.management.commands.change_node_region import _update_schema_meta |
33 | 31 | from osf.models import ( |
|
53 | 51 | REINDEX_ELASTIC, |
54 | 52 | ) |
55 | 53 | from osf.utils.permissions import ADMIN, API_CONTRIBUTOR_PERMISSIONS |
56 | | - |
57 | 54 | from scripts.approve_registrations import approve_past_pendings |
58 | | - |
59 | 55 | from website import settings, search |
60 | 56 | from website.archiver.tasks import force_archive |
61 | 57 |
|
@@ -149,7 +145,8 @@ def get_context_data(self, **kwargs): |
149 | 145 | 'STORAGE_LIMITS': settings.StorageLimits, |
150 | 146 | 'node': node, |
151 | 147 | # to edit contributors we should have guid as django prohibits _id usage as it starts with an underscore |
152 | | - 'annotated_contributors': node.contributor_set.prefetch_related('user__guids').annotate(guid=F('user__guids___id')), |
| 148 | + 'annotated_contributors': node.contributor_set.prefetch_related('user__guids').annotate( |
| 149 | + guid=F('user__guids___id')), |
153 | 150 | 'children': children, |
154 | 151 | 'permissions': API_CONTRIBUTOR_PERMISSIONS, |
155 | 152 | 'has_update_permission': self.request.user.has_perm('osf.change_node'), |
@@ -209,7 +206,9 @@ class NodeRemoveContributorView(NodeMixin, View): |
209 | 206 | def post(self, request, *args, **kwargs): |
210 | 207 | node = self.get_object() |
211 | 208 | user = OSFUser.objects.get(id=self.kwargs.get('user_id')) |
212 | | - if node.has_permission(user, ADMIN) and not node._get_admin_contributors_query(node._contributors.all(), require_active=False).exclude(user=user).exists(): |
| 209 | + if node.has_permission(user, ADMIN) and not node._get_admin_contributors_query(node._contributors.all(), |
| 210 | + require_active=False).exclude( |
| 211 | + user=user).exists(): |
213 | 212 | messages.error(self.request, 'Must be at least one admin on this node.') |
214 | 213 | return redirect(self.get_success_url()) |
215 | 214 |
|
@@ -906,6 +905,7 @@ class ForceArchiveRegistrationsView(NodeMixin, View): |
906 | 905 | def post(self, request, *args, **kwargs): |
907 | 906 | # Prevents circular imports that cause admin app to hang at startup |
908 | 907 | from osf.management.commands.force_archive import verify, DEFAULT_PERMISSIBLE_ADDONS |
| 908 | + from osf.models.admin_log_entry import update_admin_log, MANUAL_ARCHIVE_RESTART |
909 | 909 |
|
910 | 910 | registration = self.get_object() |
911 | 911 | force_archive_params = request.POST |
@@ -933,16 +933,31 @@ def post(self, request, *args, **kwargs): |
933 | 933 | messages.error(request, str(exc)) |
934 | 934 | return redirect(self.get_success_url()) |
935 | 935 | else: |
936 | | - # For actual archiving, skip synchronous verification to avoid 502 timeouts |
937 | | - # Verification will be performed asynchronously in the task |
938 | | - force_archive_task = force_archive.delay( |
939 | | - str(registration._id), |
940 | | - permissible_addons=list(addons), |
941 | | - allow_unconfigured=allow_unconfigured, |
942 | | - skip_collisions=skip_collision, |
943 | | - delete_collisions=delete_collision, |
944 | | - ) |
945 | | - messages.success(request, f'Registration archive process has started. Task id: {force_archive_task.id}.') |
| 936 | + try: |
| 937 | + update_admin_log( |
| 938 | + user_id=request.user.id, |
| 939 | + object_id=registration.pk, |
| 940 | + object_repr=str(registration), |
| 941 | + message=f'Manual archive restart initiated for registration {registration._id}', |
| 942 | + action_flag=MANUAL_ARCHIVE_RESTART |
| 943 | + ) |
| 944 | + # For actual archiving, skip synchronous verification to avoid 502 timeouts |
| 945 | + # Verification will be performed asynchronously in the task |
| 946 | + force_archive_task = force_archive.delay( |
| 947 | + str(registration._id), |
| 948 | + permissible_addons=list(addons), |
| 949 | + allow_unconfigured=allow_unconfigured, |
| 950 | + skip_collisions=skip_collision, |
| 951 | + delete_collisions=delete_collision, |
| 952 | + ) |
| 953 | + messages.success( |
| 954 | + request, |
| 955 | + f'Registration archive process has started. Task id: {force_archive_task.id}.' |
| 956 | + ) |
| 957 | + except Exception as exc: |
| 958 | + messages.error(request, |
| 959 | + f'This registration cannot be archived due to {exc.__class__.__name__}: {str(exc)}. ' |
| 960 | + f'If the problem persists get a developer to fix it.') |
946 | 961 |
|
947 | 962 | return redirect(self.get_success_url()) |
948 | 963 |
|
|
0 commit comments