Skip to content

Commit

Permalink
api.schedule: add C3VOCPublishingWebhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Aug 31, 2024
1 parent 888fb8b commit c5b1399
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions apps/api/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from . import api
from main import db
from models import event_year
from models.cfp import Proposal
from models.ical import CalendarEvent
from models.admin_message import AdminMessage
Expand Down Expand Up @@ -169,6 +170,56 @@ def post(self, proposal_type):
return [t.id for t in res]


class C3VOCPublishingWebhook(Resource):
method_decorators = {"post": [_require_video_api_key]}

def post(self):
if not request.is_json:
abort(415)

payload = request.get_json()

try:
conference = payload["fahrplan"]["conference"]
proposal_id = payload["fahrplan"]["id"]
except KeyError:
abort(422)

if not payload["is_master"]:
# c3voc *should* only send us information about the master
# encoding getting published. Aborting early ensures we don't
# accidentially delete video information from the database.
abort(406)

if conference != f"emf{event_year()}":
abort(422)

proposal = Proposal.query.get_or_404(proposal_id)

if payload["voctoweb"]["enabled"]:
proposal.c3voc_url = payload["voctoweb"]["frontend_url"]
proposal.video_recording_lost = False
else:
# This allows c3voc to notify us if videos got depublished
# as well. We do not explicitely set 'video_recording_lost'
# here because the video might only need fixing audio or
# such.
proposal.c3voc_url = ""

if payload["youtube"]["enabled"]:
# c3voc will send us a list, even though we only have one
# video.
proposal.youtube_url = payload["youtube"]["urls"][0]
proposal.video_recording_lost = False
else:
proposal.youtube_url = ""

db.session.add(proposal)
db.session.commit()

return "OK", 204


def renderScheduleMessage(message):
return {"id": message.id, "body": message.message}

Expand All @@ -186,3 +237,4 @@ def get(self):
api.add_resource(FavouriteExternal, "/external/<int:event_id>/favourite")
api.add_resource(ScheduleMessage, "/schedule_messages")
api.add_resource(UpdateLotteryPreferences, "/schedule/tickets/<proposal_type>/preferences")
api.add_resource(C3VOCPublishingWebhook, "/c3voc/publishing-webhook")

0 comments on commit c5b1399

Please sign in to comment.