Skip to content

Commit

Permalink
Mockup webhook recieving view
Browse files Browse the repository at this point in the history
  • Loading branch information
FreneticScribbler committed Jun 26, 2023
1 parent 76cd545 commit 2c808d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions RIGS/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
name='event_checkin_override'),

path('event/<int:pk>/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()),
Expand Down
17 changes: 16 additions & 1 deletion RIGS/views/rigboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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': '<span class="hidden" id="event-id">{}</span>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()

0 comments on commit 2c808d0

Please sign in to comment.