diff --git a/RIGS/urls.py b/RIGS/urls.py index 8c2140db..8793b741 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -111,6 +111,7 @@ name='event_checkin_override'), path('event//thread/', permission_required_with_403('RIGS.change_event')(views.CreateForumThread.as_view()), name='event_thread'), + path('event/webhook/', views.RecieveForumWebhook.as_view(), name='webhook_recieve'), # Finance path('invoice/', permission_required_with_403('RIGS.view_invoice')(views.InvoiceIndex.as_view()), diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py index 22494961..5371510a 100644 --- a/RIGS/views/rigboard.py +++ b/RIGS/views/rigboard.py @@ -5,6 +5,9 @@ import simplejson import urllib +from envparse import env +from bs4 import BeautifulSoup + from django.conf import settings from django.contrib import messages from django.contrib.staticfiles import finders @@ -20,6 +23,7 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.views import generic +from django.views.decorators.csrf import csrf_exempt from PyRIGS import decorators from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related @@ -391,7 +395,18 @@ def get_redirect_url(self, *args, **kwargs): params = { 'title': str(event), - 'body': 'https://rigs.nottinghamtec.co.uk/event/{}'.format(event.pk), + 'body': 'https://rigs.nottinghamtec.co.uk/event/{}'.format(event.pk, event.pk), 'category': 'rig-info' } return 'https://forum.nottinghamtec.co.uk/new-topic' + "?" + urllib.parse.urlencode(params) + + +class RecieveForumWebhook(generic.View): + @csrf_exempt + def post(self, request, *args, **kwargs): + if request.POST.get('secret') == env('FORUM_WEBHOOK_SECRET'): + event_id = BeautifulSoup(request.POST.get('body'), "html.parser") + event = models.Event.objects.filter(pk=soup.select_one('div[id="event-id"]')).first() + if event: + event.forum_url = "" + event.save()