Skip to content

Commit 3c81303

Browse files
committed
fix: csp rules for notification importers preview view
Preview was prevented by CSP control.
1 parent b4bfe92 commit 3c81303

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

notification_importers/admin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import importlib
22
import logging
33

4+
from csp.decorators import csp_update
45
from django.conf import settings
56
from django.contrib import admin, messages
67
from django.http import HttpResponseRedirect
@@ -10,6 +11,8 @@
1011
from django_ilmoitin.admin import NotificationTemplateAdmin
1112
from django_ilmoitin.models import NotificationTemplate
1213

14+
from palvelutarjotin.consts import CSP
15+
1316
from .notification_importer import (
1417
AbstractNotificationImporter,
1518
NotificationImporterException,
@@ -107,6 +110,16 @@ def _send_error_message(self, request, message):
107110
logger.error(message)
108111
self.message_user(request, message, messages.ERROR)
109112

113+
# Acecpt CSP_UNSAFE_INLINE for the changeform view to allow
114+
# the preview template to work correctly.
115+
@csp_update(
116+
SCRIPT_SRC=settings.CSP_SCRIPT_SRC + [CSP.UNSAFE_INLINE],
117+
)
118+
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
119+
return super().changeform_view(
120+
request, object_id, form_url, extra_context=extra_context
121+
)
122+
110123

111124
if hasattr(settings, "NOTIFICATIONS_IMPORTER"):
112125
admin.site.unregister(NotificationTemplate)

0 commit comments

Comments
 (0)