emfcamp / Website

The Electromagnetic Field web site
http://www.emfcamp.org
GNU Affero General Public License v3.0
41 stars 83 forks source link

api.schedule: add C3VOCPublishingWebhook #1770

Closed Kunsi closed 1 month ago

Kunsi commented 1 month ago

This will allow c3voc to send us video information automatically upon release of videos, as documented here: https://github.com/voc/voctopublish/blob/main/voctopublish/api_client/webhook_client.py#L28-L56

Kunsi commented 1 month ago

Tested:

# no json content-type
/home/kunsi➤ curl -X POST -H"Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook
{
    "message": "The server does not support the media type transmitted in the request."
}

# no json data
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.
138.22:2342/api/c3voc/publishing-webhook
{
    "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"
}

# empty json
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook --data '{}'
{
    "message": "The request was well-formed but was unable to be followed due to semantic errors."
}

# no master ticket
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook --data '{"is_master": false, "fahrplan": {"conference": "emf2024", "id": 12}}'
{
    "message": "The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request."
}

# sets youtube url only
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook --data '{"is_master": true, "fahrplan": {"conference": "emf2024", "id": 14}, "voctoweb": {"enabled": false}, "youtube": {"enabled": true, "urls": ["https://www.youtube.com/watch?v=hsoiHKaqG2s"]}}'

# sets both youtube url and media.ccc.de url
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook --data '{"is_master": true, "fahrplan": {"conference": "emf2024", "id": 14}, "voctoweb": {"enabled": true, "frontend_url": "https://media.ccc.de/v/eh21-61-state-of-bahn-reisendeninformation"}, "youtube": {"enabled": true, "urls": ["https://www.youtube.com/watch?v=hsoiHKaqG2s"]}}'

# unsets youtube url
/home/kunsi➤ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer video-api-token" http://172.19.138.22:2342/api/c3voc/publishing-webhook --data '{"is_master": true, "fahrplan": {"conference": "emf2024", "id": 14}, "voctoweb": {"enabled": true, "frontend_url": "https://media.ccc.de/v/eh21-61-state-of-bahn-reisendeninformation"}, "youtube": {"enabled": false}}'
jayaddison commented 1 month ago

Commencing some local testing of this here (the code looks good to me)

jayaddison commented 1 month ago

Since we display the URLs on the relevant event pages, and since both media.ccc.de and youtube.com redirect to HTTPS by default, let's add validation of the URLs before storing them in the database.

                if not c3voc_url.startswith('https://media.ccc.de/'):
                    abort(403, message='Please ensure that the URL points to the media.ccc.de HTTPS service.')

or something along those lines

jayaddison commented 1 month ago

(ah: and one more thing: maybe some of the line-lengths could be reduced; but again, a nitpicky detail)

jayaddison commented 1 month ago

Another one-more-thing: we should probably add some test coverage for this. I'm prety convinced from manually testing it that it works well, but for the longer-term, some automated coverage would be nice. Borrowing some of the existing test code for the PATCH endpoint could provide a base for that.

Kunsi commented 1 month ago

I think my tests cover all the cases we'd want to test. Let me know if i missed any.