Skip to content
Draft
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/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
re_path(r'^draft_registrations/', include('admin.draft_registrations.urls', namespace='draft_registrations')),
re_path(r'^files/', include('admin.files.urls', namespace='files')),
re_path(r'^share_reindex/', include('admin.share_reindex.urls', namespace='share_reindex')),
re_path(r'^notifications/', include('admin.notifications.urls', namespace='notifications')),
]),
),
]
Expand Down
14 changes: 8 additions & 6 deletions admin/maintenance/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytz
import datetime

from osf.models import MaintenanceState
from osf.models import MaintenanceState, MaintenanceMode
import website.maintenance as maintenance
from admin.maintenance.forms import MaintenanceForm

Expand Down Expand Up @@ -36,15 +36,17 @@ def get_context_data(self, **kwargs):
maintenance = MaintenanceState.objects.first()
kwargs['form'] = MaintenanceForm()
kwargs['current_alert'] = model_to_dict(maintenance) if maintenance else None
kwargs['maintenance_mode'] = MaintenanceMode.is_under_maintenance()
return super().get_context_data(**kwargs)

def post(self, request, *args, **kwargs):
data = request.POST

start = convert_eastern_to_utc(data['start']).isoformat() if data.get('start') else None
end = convert_eastern_to_utc(data['end']).isoformat() if data.get('end') else None

maintenance.set_maintenance(data.get('message', ''), data['level'], start, end)
if maintenance_mode := data.get('maintenance_mode'):
MaintenanceMode(maintenance_mode=False if maintenance_mode == 'True' else True).save()
else:
start = convert_eastern_to_utc(data['start']).isoformat() if data.get('start') else None
end = convert_eastern_to_utc(data['end']).isoformat() if data.get('end') else None
maintenance.set_maintenance(data.get('message', ''), data['level'], start, end)
return redirect('maintenance:display')


Expand Down
12 changes: 11 additions & 1 deletion admin/management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,17 @@ def post(self, request):
class SyncNotificationTemplates(ManagementCommandPermissionView):

def post(self, request):
populate_notification_types()
run_type = request.POST.get('run_type')
if run_type == 'restore_one':
template_name = request.POST.get('template_name')
if not template_name:
messages.error(request, 'A template name must be specified when restoring one template. Check your inputs and try again')
return redirect(reverse('management:commands'))
populate_notification_types(restore_one=template_name)
elif run_type == 'restore_all':
populate_notification_types(restore_all=True)
else:
populate_notification_types()
messages.success(request, 'Notification templates have been successfully synced.')
return redirect(reverse('management:commands'))

Expand Down
8 changes: 8 additions & 0 deletions admin/notifications/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import forms
from osf.models import NotificationType


class NotificationTypeForm(forms.ModelForm):
class Meta:
model = NotificationType
fields = '__all__'
14 changes: 14 additions & 0 deletions admin/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.urls import re_path
from . import views

app_name = 'admin'

urlpatterns = [
re_path(r'$', views.NotificationsList.as_view(), name='list'),
re_path(r'types/$', views.NotificationTypeList.as_view(), name='types_list'),
re_path(r'type_display/(?P<pk>\d+)/$', views.NotificationTypeDisplay.as_view(), name='type_display'),
re_path(r'type_detail/(?P<pk>\d+)/$', views.NotificationTypeDetail.as_view(), name='type_detail'),
re_path(r'types_preview/(?P<pk>\d+)/$', views.NotificationTypePreview.as_view(), name='types_preview'),
re_path(r'subscriptions/$', views.NotificationSubscriptionsList.as_view(), name='subscriptions_list'),
re_path(r'email_tasks/$', views.EmailTasksList.as_view(), name='email_tasks_list'),
]
Loading
Loading