Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video recordings] Send email notifications to speakers when video recordings are first published. #1741

Closed
19 changes: 19 additions & 0 deletions apps/api/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from flask_restful import Resource, abort

from . import api
from apps.cfp_review.base import send_email_for_proposal
from apps.common.email import from_email
from main import db
from models.cfp import Proposal
from models.ical import CalendarEvent
Expand Down Expand Up @@ -41,6 +43,10 @@ def patch(self, proposal_id):
if not payload:
abort(400)

if proposal.video_recording_lost:
# Prevent updates to video recordings already flagged as lost
abort(400)

ALLOWED_ATTRIBUTES = {
"youtube_url",
"thumbnail_url",
Expand All @@ -50,13 +56,26 @@ def patch(self, proposal_id):
if set(payload.keys()) - ALLOWED_ATTRIBUTES:
abort(400)

if "video_recording_lost" in payload and len(payload) > 1:
# Flagging a recording lost is mutually exclusive with other edits
abort(400)

was_published = proposal.is_video_published
for attribute in ALLOWED_ATTRIBUTES:
if attribute in payload:
setattr(proposal, attribute, payload[attribute] or "")
is_published = proposal.is_video_published

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

if was_published is False and is_published is True:
send_email_for_proposal(
proposal,
reason="video-recording-published",
from_address=from_email("SPEAKERS_EMAIL"),
russss marked this conversation as resolved.
Show resolved Hide resolved
)

return {
"id": proposal.id,
"slug": proposal.slug,
Expand Down
7 changes: 7 additions & 0 deletions apps/cfp_review/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ def send_email_for_proposal(proposal, reason="still-considered", from_address=No
)
template = "emails/cfp-slot-moved.txt"

elif reason == "video-recording-published":
subject = "Your EMF %s video recording has been published ('%s')" % (
proposal.human_type,
proposal.title,
)
template = "emails/video-recording-published.txt"

else:
raise Exception("Unknown cfp proposal email type %s" % reason)

Expand Down
4 changes: 4 additions & 0 deletions models/cfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ class Proposal(BaseModel):
thumbnail_url = db.Column(db.String)
video_recording_lost = db.Column(db.Boolean, default=False)

@property
def is_video_published(self) -> bool:
return any([self.c3voc_url, self.youtube_url])

type_might_require_ticket = False
tickets = db.relationship("EventTicket", backref="proposal")

Expand Down
10 changes: 10 additions & 0 deletions templates/emails/video-recording-published.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "emails/base.txt" %}
{% block body %}
Hi {{ proposal.user.name }},

The video recording for your EMF {{ proposal.human_type }} '{{ proposal.title }}' has been edited and published.
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

The video and direct links to it can be found at: https://www.emfcamp.org/schedule/{{ event_year }}/{{ proposal.id }}

Thank you again for participating in EMF {{ event_year }}!
{% endblock %}