mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 00:42:17 +00:00
Mockup webhook recieving view
This commit is contained in:
@@ -111,6 +111,7 @@ urlpatterns = [
|
|||||||
name='event_checkin_override'),
|
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/<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
|
# Finance
|
||||||
path('invoice/', permission_required_with_403('RIGS.view_invoice')(views.InvoiceIndex.as_view()),
|
path('invoice/', permission_required_with_403('RIGS.view_invoice')(views.InvoiceIndex.as_view()),
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import premailer
|
|||||||
import simplejson
|
import simplejson
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
|
from envparse import env
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.staticfiles import finders
|
from django.contrib.staticfiles import finders
|
||||||
@@ -20,6 +23,7 @@ from django.urls import reverse_lazy
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from PyRIGS import decorators
|
from PyRIGS import decorators
|
||||||
from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related
|
from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related
|
||||||
@@ -391,7 +395,18 @@ class CreateForumThread(generic.base.RedirectView):
|
|||||||
|
|
||||||
params = {
|
params = {
|
||||||
'title': str(event),
|
'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'
|
'category': 'rig-info'
|
||||||
}
|
}
|
||||||
return 'https://forum.nottinghamtec.co.uk/new-topic' + "?" + urllib.parse.urlencode(params)
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user