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

feat: Add session state change emails #7196

Merged
merged 6 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions app/api/helpers/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MONTHLY_PAYMENT_EMAIL,
MONTHLY_PAYMENT_FOLLOWUP_EMAIL,
NEW_SESSION,
SESSION_ACCEPT_REJECT,
SESSION_STATE_CHANGE,
TEST_MAIL,
TICKET_CANCELLED,
TICKET_PURCHASED,
Expand All @@ -32,6 +32,9 @@
from app.models.user import User
from app.settings import get_settings

logger = logging.getLogger(__name__)
# pytype: disable=attribute-error


def check_smtp_config(smtp_encryption):
"""
Expand Down Expand Up @@ -168,22 +171,39 @@ def send_email_new_session(email, event_name, link):
)


def send_email_session_accept_reject(email, session, link):
def send_email_session_state_change(email, session):
"""email for new session"""
session_name = session.title
session_acceptance = session.state
event = session.event

settings = get_settings()
app_name = settings['app_name']
frontend_url = settings['frontend_url']
session_link = "{}/events/{}/sessions/{}".format(
frontend_url, event.identifier, session.id
)
event_link = f"{frontend_url}/e/{event.identifier}"

context = {
'session_name': session.title,
'session_link': session_link,
'session_state': session.state,
'event_name': event.name,
'event_link': event_link,
'app_name': app_name,
'frontend_link': frontend_url,
}

try:
mail = MAILS[SESSION_STATE_CHANGE][session.state]
except KeyError:
logger.error('No mail found for session state change: ' + session.state)
return

send_email(
to=email,
action=SESSION_ACCEPT_REJECT,
subject=MAILS[SESSION_ACCEPT_REJECT]['subject'].format(
session_name=session_name, acceptance=session_acceptance
),
html=MAILS[SESSION_ACCEPT_REJECT]['message'].format(
email=email,
session_name=session_name,
acceptance=session_acceptance,
link=link,
),
action=SESSION_STATE_CHANGE,
subject=mail['subject'].format(**context),
html=mail['message'].format(**context),
)

iamareebjamal marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
18 changes: 9 additions & 9 deletions app/api/helpers/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_monthly_payment_follow_up_notification_actions,
get_monthly_payment_notification_actions,
get_new_session_notification_actions,
get_session_accept_reject_notification_actions,
get_session_state_change_notification_actions,
get_ticket_purchased_attendee_notification_actions,
get_ticket_purchased_notification_actions,
get_ticket_purchased_organizer_notification_actions,
Expand All @@ -27,7 +27,7 @@
MONTHLY_PAYMENT_FOLLOWUP_NOTIF,
MONTHLY_PAYMENT_NOTIF,
NEW_SESSION,
SESSION_ACCEPT_REJECT,
SESSION_STATE_CHANGE,
TICKET_CANCELLED,
TICKET_CANCELLED_ORGANIZER,
TICKET_PURCHASED,
Expand Down Expand Up @@ -73,9 +73,9 @@ def send_notif_new_session_organizer(user, event_name, link, session_id):
send_notification(user, title, message, actions)


def send_notif_session_accept_reject(user, session_name, acceptance, link, session_id):
def send_notif_session_state_change(user, session_name, acceptance, link, session_id):
"""
Send notification to the session creator about a session being accepted or rejected.
Send notification to the session creator about a session status being changed.
:param user:
:param session_name:
:param acceptance:
Expand All @@ -84,11 +84,11 @@ def send_notif_session_accept_reject(user, session_name, acceptance, link, sessi
:return:
"""
message_settings = MessageSettings.query.filter_by(
action=SESSION_ACCEPT_REJECT
action=SESSION_STATE_CHANGE
).first()
if not message_settings or message_settings.notification_status == 1:
actions = get_session_accept_reject_notification_actions(session_id, link)
notification = NOTIFS[SESSION_ACCEPT_REJECT]
actions = get_session_state_change_notification_actions(session_id, link)
notification = NOTIFS[SESSION_STATE_CHANGE]
title = notification['title'].format(
session_name=session_name, acceptance=acceptance
)
Expand Down Expand Up @@ -156,7 +156,7 @@ def send_notif_monthly_fee_payment(
:return:
"""
message_settings = MessageSettings.query.filter_by(
action=SESSION_ACCEPT_REJECT
action=SESSION_STATE_CHANGE
).first()
if not message_settings or message_settings.notification_status == 1:
actions = get_monthly_payment_notification_actions(event_id, link)
Expand Down Expand Up @@ -184,7 +184,7 @@ def send_followup_notif_monthly_fee_payment(
:return:
"""
message_settings = MessageSettings.query.filter_by(
action=SESSION_ACCEPT_REJECT
action=SESSION_STATE_CHANGE
).first()
if not message_settings or message_settings.notification_status == 1:
actions = get_monthly_payment_follow_up_notification_actions(event_id, link)
Expand Down
76 changes: 68 additions & 8 deletions app/api/helpers/system_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
PASSWORD_CHANGE,
PASSWORD_RESET,
PASSWORD_RESET_AND_VERIFY,
SESSION_ACCEPT_REJECT,
SESSION_SCHEDULE,
SESSION_STATE_CHANGE,
TEST_MAIL,
TICKET_CANCELLED,
TICKET_PURCHASED,
Expand Down Expand Up @@ -52,14 +52,74 @@
+ u"<br/> Visit this link to fill up details: {link}"
),
},
SESSION_ACCEPT_REJECT: {
SESSION_STATE_CHANGE: {
'recipient': 'Speaker',
'subject': u'Session {session_name} has been {acceptance}',
'message': (
u"Hi {email},<br/>"
+ u"The session <strong>{session_name}</strong> has been <strong>{acceptance}</strong> by the organizer. "
+ u"<br/> Visit this link to view the session: {link}"
),
'pending': {
'subject': 'Your speaker submission for {event_name} titled {session_name}',
'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"We have received your submission {session_name} for {event_name}<br/><br/>"
"Your proposal will be reviewed by the event organizers and review team. The current status of your session is now \"Pending\".<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (150 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
'accepted': {
'subject': 'Accepted! Congratulations Your submission for {event_name} titled {session_name} has been Accepted',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (124 > 90 characters)

'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"Your session status for the submission {session_name} for {event_name} was changed to \"Accepted\". Congratulations!<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (140 > 90 characters)

"Your proposal will be scheduled by the event organizers and review team. Please (re)confirm your participation with the organizers of the event, if required.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (181 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
'confirmed': {
'subject': 'Confirmed! Congratulations Your submission for {event_name} titled {session_name} has been Confirmed',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (126 > 90 characters)

'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"Your session status for the submission {session_name} for {event_name} was changed to \"Confirmed\". Congratulations!<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (141 > 90 characters)

"Your proposal will be scheduled by the event organizers and review team. Please inform the event organizers in case there are any changes to your participation.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (184 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
'rejected': {
'subject': 'Not Accepted. Your submission for {event_name} titled {session_name} was not accepted',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (111 > 90 characters)

'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"Unfortunately your submission {session_name} for {event_name} was not accepted. Your session status was changed to \"Rejected\".<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (152 > 90 characters)

"The status change was done by event organizers. If there are questions about this change please contact the organizers.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (143 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
'canceled': {
'subject': 'Canceled! Your submission for {event_name} titled {session_name} has been Canceled',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (108 > 90 characters)

'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"Your session status for the submission {session_name} for {event_name} was changed to \"Canceled\".<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (123 > 90 characters)

"The status change was done by event organizers. If there are questions about this change please contact the organizers.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (143 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
'withdrawn': {
'subject': 'Withdrawn! Your submission for {event_name} titled {session_name} has been Withdrawn',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (110 > 90 characters)

'message': "Hello,<br/><br/>"
"This is an automatic message from {app_name}.<br/><br/>"
"Your session status for the submission {session_name} for {event_name} was changed to \"Withdrawn\".<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (124 > 90 characters)

"The status change was done by event organizers. If there are questions about this change please contact the organizers.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (143 > 90 characters)

"You can also check the status and details of your submission on the session page {session_link}. You need to be logged in to view it.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (157 > 90 characters)

"More details about the event are on the event page at {event_link}.<br/><br/>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

"Thank you.<br/>"
"<a href='{frontend_link}'>{app_name}</a>",
},
},
SESSION_SCHEDULE: {
'recipient': 'Owner, Organizer, Speaker',
Expand Down
8 changes: 4 additions & 4 deletions app/api/helpers/system_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
NEW_SESSION,
NEXT_EVENT,
PASSWORD_CHANGE,
SESSION_ACCEPT_REJECT,
SESSION_SCHEDULE,
SESSION_STATE_CHANGE,
TICKET_CANCELLED,
TICKET_CANCELLED_ORGANIZER,
TICKET_PURCHASED,
Expand Down Expand Up @@ -201,9 +201,9 @@ def get_next_event_notification_actions(event_id, link):
return [view_event_action]


def get_session_accept_reject_notification_actions(session_id, link):
def get_session_state_change_notification_actions(session_id, link):
"""
Get the actions associated with a notification of a session getting accepted/rejected.
Get the actions associated with a notification of a session status being changed.
:param session_id: id of the session.
:param link: link to view the session.
:return: actions
Expand Down Expand Up @@ -363,7 +363,7 @@ def get_invite_papers_notification_actions(cfs_link, submit_link):
'message': u"Here are upcoming events: {up_coming_events}.",
'recipient': 'Owner, Organizer, Speaker',
},
SESSION_ACCEPT_REJECT: {
SESSION_STATE_CHANGE: {
'title': u'Session {session_name} has been {acceptance}',
'message': u"The session <strong>{session_name}</strong> has been"
+ u" <strong>{acceptance}</strong> by the Organizer.",
Expand Down
4 changes: 2 additions & 2 deletions app/api/helpers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def send_email_task_sendgrid(payload, headers, smtp_config):
message.add_attachment(attachment)
sendgrid_client = SendGridAPIClient(get_settings()['sendgrid_key'])
logging.info(
'Sending an email regarding {} on behalf of {}'.format(
payload["subject"], payload["from"]
'Sending an email to {} regarding "{}" on behalf of {}'.format(
payload['to'], payload["subject"], payload["from"]
)
)
try:
Expand Down
4 changes: 2 additions & 2 deletions app/api/schema/message_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PASSWORD_RESET = 'Reset Password'
PASSWORD_CHANGE = 'Change Password'
EVENT_ROLE = 'Event Role Invitation'
SESSION_ACCEPT_REJECT = 'Session Accept or Reject'
SESSION_STATE_CHANGE = 'Session State Change'
SESSION_SCHEDULE = 'Session Schedule Change'
EVENT_PUBLISH = 'Event Published'
AFTER_EVENT = 'After Event'
Expand Down Expand Up @@ -60,7 +60,7 @@ class Meta:
USER_REGISTER,
PASSWORD_RESET,
EVENT_ROLE,
SESSION_ACCEPT_REJECT,
SESSION_STATE_CHANGE,
SESSION_SCHEDULE,
NEXT_EVENT,
EVENT_PUBLISH,
Expand Down
61 changes: 33 additions & 28 deletions app/api/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from app.api.helpers.db import get_count, safe_query, safe_query_kwargs, save_to_db
from app.api.helpers.errors import ForbiddenError
from app.api.helpers.files import make_frontend_url
from app.api.helpers.mail import send_email_new_session, send_email_session_accept_reject
from app.api.helpers.mail import send_email_new_session, send_email_session_state_change
from app.api.helpers.notification import (
send_notif_new_session_organizer,
send_notif_session_accept_reject,
send_notif_session_state_change,
)
from app.api.helpers.permission_manager import has_access
from app.api.helpers.query import event_query
Expand Down Expand Up @@ -259,7 +259,14 @@ def before_update_object(self, session, data, view_kwargs):

if new_state and new_state != session.state:
# State change detected. Verify that state change is allowed
g.send_email = new_state == 'accepted' or new_state == 'rejected'
g.send_email = new_state in [
'accepted',
'rejected',
'confirmed',
'rejected',
'canceled',
'withdrawn',
]
key = 'speaker'
if is_organizer:
key = 'organizer'
Expand Down Expand Up @@ -294,32 +301,8 @@ def after_update_object(self, session, data, view_kwargs):
""" Send email if session accepted or rejected """

if data.get('send_email', None) and g.get('send_email'):
event = session.event
# Email for speaker
speakers = session.speakers
for speaker in speakers:
frontend_url = get_settings()['frontend_url']
link = "{}/events/{}/sessions/{}".format(
frontend_url, event.identifier, session.id
)
if not speaker.is_email_overridden:
send_email_session_accept_reject(speaker.email, session, link)
send_notif_session_accept_reject(
speaker, session.title, session.state, link, session.id
)
notify_for_session(session)

# Email for owner
if session.event.get_owner():
owner = session.event.get_owner()
owner_email = owner.email
frontend_url = get_settings()['frontend_url']
link = "{}/events/{}/sessions/{}".format(
frontend_url, event.identifier, session.id
)
send_email_session_accept_reject(owner_email, session, link)
send_notif_session_accept_reject(
owner, session.title, session.state, link, session.id
)
if 'state' in data:
entry_count = SessionsSpeakersLink.query.filter_by(session_id=session.id)
if entry_count.count() == 0:
Expand Down Expand Up @@ -355,6 +338,28 @@ def after_update_object(self, session, data, view_kwargs):
}


def notify_for_session(session):
event = session.event
frontend_url = get_settings()['frontend_url']
link = "{}/events/{}/sessions/{}".format(frontend_url, event.identifier, session.id)
# Email for speaker
speakers = session.speakers
for speaker in speakers:
if not speaker.is_email_overridden:
send_email_session_state_change(speaker.email, session)
send_notif_session_state_change(
speaker.user, session.title, session.state, link, session.id
)

# Email for owner
if session.event.get_owner():
owner = session.event.get_owner()
send_email_session_state_change(owner.email, session)
send_notif_session_state_change(
owner, session.title, session.state, link, session.id
)


class SessionRelationshipRequired(ResourceRelationship):
"""
Session Relationship
Expand Down
2 changes: 1 addition & 1 deletion app/models/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PASSWORD_CHANGE = 'Change Password'
EVENT_ROLE = 'Event Role Invitation'
USER_EVENT_ROLE = 'User Event Role Invitation'
SESSION_ACCEPT_REJECT = 'Session Accept or Reject'
SESSION_STATE_CHANGE = 'Session State Change'
SESSION_SCHEDULE = 'Session Schedule Change'
EVENT_PUBLISH = 'Event Published'
AFTER_EVENT = 'After Event'
Expand Down
Loading