def email_magic_link() -> Response: form = EmailAddressForm() if form.validate_on_submit(): token, expiry = get_magic_link_token_and_expiry(form.email.data) url = url_for("views.email_magic_link_login", magic_link_token=token, _external=True) mail.send_mail( to=[form.email.data], template="email/magic-link", magic_link=url, magic_link_expiration=expiry, ) return redirect(url_for("views.email_magic_link_done")) return render_template("email_magic_link.html", form=form)
def anonymize_talk(talk_id: int) -> Response: talk = Talk.query.get_or_404(talk_id) if request.method == "GET" and talk.is_anonymized: # the TalkForm uses the regular fields; if we've already # anonymized, an admin is looking at a past anonymization, # so show that instead of the original versions talk.title = talk.anonymized_title talk.description = talk.anonymized_description talk.outline = talk.anonymized_outline talk.take_aways = talk.anonymized_take_aways form = TalkForm(obj=talk) if form.validate_on_submit(): talk.anonymized_title = form.title.data talk.anonymized_description = form.description.data talk.anonymized_outline = form.outline.data talk.anonymized_take_aways = form.take_aways.data talk.is_anonymized = True talk.has_anonymization_changes = ( talk.anonymized_title != talk.title or talk.anonymized_description != talk.description or talk.anonymized_outline != talk.outline or talk.anonymized_take_aways != talk.take_aways) db.session.add(talk) db.session.commit() db.session.refresh(talk) speakers = [ talk_speaker.user for talk_speaker in talk.speakers if talk_speaker.state == InvitationStatus.CONFIRMED ] if talk.has_anonymization_changes: mail.send_mail( to=[speaker.email for speaker in speakers], template="email/talk-anonymized", talk_id=talk.talk_id, title=talk.title, ) if request.form.get("save-and-next"): return redirect(url_for("manage.anonymize_talks")) else: return redirect( url_for("manage.preview_anonymized_talk", talk_id=talk.talk_id)) return render_template("manage/anonymize_talk.html", form=form, talk=talk)
def test_send_mail(app: Application) -> None: with app.app_context(), app.test_request_context(): with mail.mail.record_messages() as outbox: mail.send_mail( to=["*****@*****.**"], template="email-template", # in yakbak/tests/templates variables="replacements", ) assert len(outbox) == 1 msg = outbox[0] assert msg.subject == "The Email Subject" assert msg.sender == "*****@*****.**" assert msg.recipients == ["*****@*****.**"] assert msg.body == "This is the email. It has replacements!"
def edit_speakers(talk_id: int) -> Response: talk = load_talk(talk_id) actions = { InvitationStatus.PENDING: [("Uninvite", "danger", "views.uninvite_speaker")], InvitationStatus.CONFIRMED: [], InvitationStatus.REJECTED: [], InvitationStatus.DELETED: [("Reinvite", "primary", "views.reinvite_speaker")], } speaker_emails = [s.user.email for s in talk.speakers] form = SpeakerEmailForm(speaker_emails) if form.validate_on_submit(): email = form.email.data try: user = User(fullname=email, email=email) db.session.add(user) db.session.commit() except IntegrityError: db.session.rollback() user = User.query.filter_by(email=email).one() try: talk.add_speaker(user, InvitationStatus.PENDING) db.session.commit() except IntegrityError: db.session.rollback() mail.send_mail(to=[email], template="email/co-presenter-invite", talk=talk) return redirect(url_for("views.edit_speakers", talk_id=talk.talk_id)) return render_template("edit_speakers.html", talk=talk, actions=actions, form=form)
def conduct_report() -> Response: """Add a new code of conduct report for the given talk. When a report is generated, store it in the database and email the conduct team. """ form = ConductReportForm() if not form.validate_on_submit(): flash(" ".join(( "Unable to report a code of conduct issue.", "If you continue to receive this message, please contact", f"{g.conference.conduct_email}.", ))) return redirect(request.referrer) # If we can't find the talk, something's gone very wrong. This # codepath should not be executed in normal use, as the form should # always contain a valid talk id. try: talk = Talk.query.get(form.talk_id.data) except NoResultFound: abort(400) report = ConductReport(talk=talk, text=form.text.data) # A bit of a silly guard, but on the off chance a bug is introduced # here or in the form code, I'd rather the explicit comparison to # `True` than the looser comparison to anything truthy. if form.anonymous.data is not True: report.user = g.user db.session.add(report) db.session.commit() mail.send_mail(to=[g.conference.conduct_email], template="email/conduct-report") flash("Thank you for your report. Our team will review it shortly.") return redirect(request.referrer)