Skip to content

Commit

Permalink
fix/add initial backend view and url route
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPRobinson committed Jan 21, 2025
1 parent cf35290 commit 38ce658
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dataworkspace/dataworkspace/apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from django.shortcuts import render
from django.urls import reverse
from django.utils.timezone import now, timedelta
from django.views import View
from django.views.generic import FormView
from requests import HTTPError
Expand Down Expand Up @@ -463,3 +464,17 @@ def form_valid(self, form):
if cleaned["contact_type"] == form.ContactTypes.GET_HELP:
return HttpResponseRedirect(reverse("support"))
return HttpResponseRedirect(reverse("feedback"))


class SetNotificationCookie(View):
def post(self, request, *args, **kwargs):
# id_campaign = request.POST.get("id_campaign")
id_campaign = "placholder"
# config_notification_banner = NotificationBannerConfig.objects.filter(campaign_id=id_campaign)
# date_expiry = config_notification_banner.expiry_date
date_expiry = now() + timedelta(days=1)
if now() >= date_expiry:
response = JsonResponse({"message": f"campaign {id_campaign} expired"})
else:
action = request.POST.get("action")
response.set_cookie(f"{id_campaign}_{action}", "true", expires=date_expiry)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.

Check warning

Code scanning / CodeQL

Construction of a cookie using user-supplied input Medium

Cookie is constructed from a
user-supplied input
.
9 changes: 9 additions & 0 deletions dataworkspace/dataworkspace/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CustomVisualisationReviewView,
NewsletterSubscriptionView,
RestoreTableDAGTaskStatusView,
SetNotificationCookie,
ServeS3UploadedFileView,
SupportAnalysisDatasetView,
SupportView,
Expand Down Expand Up @@ -200,6 +201,14 @@
login_required(RestoreTableDAGTaskStatusView.as_view()),
name="restore-table-task-status",
),
path(
"restore-table/status/<str:execution_date>/<str:task_id>",
login_required(RestoreTableDAGTaskStatusView.as_view()),
name="restore-table-task-status",
),
path(
"set-notification-cookie/", SetNotificationCookie.as_view(), name="set_notification_cookie"
),
]

if settings.DEBUG:
Expand Down

0 comments on commit 38ce658

Please sign in to comment.