Skip to content

Commit

Permalink
Feat: Update ME Logo and Move Email Templates to Postmark (#1194)
Browse files Browse the repository at this point in the history
* team admin contact email setup in postmark

* contact admin email template using postmark

* refactor: Update community logo fallback to use ME_LOGO_PNG

* feat: Update vendor submission email handling and add new email templates

* feat: Refactor email handling to use new templates and update logo usage

* refactor: Update action submitted email template to use dynamic logo variable

* feat: Update testimonial submission email handling to use new template and include logo

* feat: Implement new admin email template and include logo in welcome emails

* feat: Add logo variable to event submission email content

* feat: Add new email template constants for testimonials and admin notifications

* feat: Add new email template constants for user registration and team/community invitations

* fix: Update ME_LOGO_PNG to the latest logo URL for consistency across the application

* feat: Refactor invitation and registration email handling to use new email templates with attachments

* refactor: Update VendorStore to improve community handling and error logging

* refactor: Remove redundant error print statement in VendorStore for cleaner error logging

* refactor: Update ME_LOGO_PNG to use environment variable and clean up unused email subject lines in AdminService
  • Loading branch information
abdullai-t authored Dec 16, 2024
1 parent 7941e57 commit b60c93d
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 64 deletions.
3 changes: 1 addition & 2 deletions src/_main_/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

STATES = load_json(BASE_DIR + "/database/raw_data/other/states.json")

ME_LOGO_PNG = "https://www.massenergize.org/wp-content/uploads/2021/07/cropped-me-logo-transp.png"
ME_LOGO_PNG = os.environ.get("ME_DEFAULT_LOGO_URL")

DEFAULT_PAGINATION_LIMIT = 25

Expand All @@ -64,7 +64,6 @@

PUBLIC_EMAIL_DOMAINS=["gmail.com", "yahoo.com", "hotmail.com", "outlook.com", "aol.com"]

import random

INSPIRATIONAL_MESSAGES = [
"Together, we can make a difference for our planet.",
Expand Down
16 changes: 10 additions & 6 deletions src/api/services/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from _main_.utils.pagination import paginate
from api.store.action import ActionStore
from _main_.utils.context import Context
from _main_.utils.constants import ADMIN_URL_ROOT
from _main_.utils.constants import ADMIN_URL_ROOT, ME_LOGO_PNG
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments, send_massenergize_rich_email
from api.utils.constants import ACTION_SUBMISSION_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from .utils import send_slack_message
from api.store.utils import get_user_or_die
Expand Down Expand Up @@ -57,7 +58,7 @@ def create_action(self, context: Context, args, user_submitted=False) -> Tuple[d
else:
return None, CustomMassenergizeError('Action submission incomplete')

subject = 'User Action Submitted'
# subject = 'User Action Submitted'

content_variables = {
'name': first_name,
Expand All @@ -67,10 +68,13 @@ def create_action(self, context: Context, args, user_submitted=False) -> Tuple[d
'email': email,
'title': action.title,
'body': action.featured_summary,
'me_logo':ME_LOGO_PNG
}
# sent from MassEnergize to cadmins
send_massenergize_rich_email(
subject, admin_email, 'action_submitted_email.html', content_variables, None)
# send_massenergize_rich_email(
# subject, admin_email, 'action_submitted_email.html', content_variables, None)
send_massenergize_email_with_attachments(ACTION_SUBMISSION_EMAIL_TEMPLATE, content_variables, [admin_email], None, None, None)


if IS_PROD or IS_CANARY:
send_slack_message(
Expand All @@ -82,7 +86,7 @@ def create_action(self, context: Context, args, user_submitted=False) -> Tuple[d
"subject": action.title,
"message": action.featured_summary,
"url": f"{ADMIN_URL_ROOT}/admin/edit/{action.id}/action",
"community": community_name
"community": community_name,
})

return serialize(action), None
Expand Down
32 changes: 17 additions & 15 deletions src/api/services/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from _main_.utils.common import serialize
from _main_.utils.pagination import paginate
from api.store.admin import AdminStore
from _main_.utils.constants import ADMIN_URL_ROOT, COMMUNITY_URL_ROOT
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.constants import ADMIN_URL_ROOT, COMMUNITY_URL_ROOT, ME_LOGO_PNG
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments, send_massenergize_rich_email
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from api.utils.constants import CONTACT_ADMIN_EMAIL_TEMPLATE, NEW_ADMIN_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from .utils import send_slack_message
from _main_.utils.massenergize_logger import log
Expand All @@ -24,16 +25,17 @@ def add_super_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
if err:
return None, err

subject = 'Welcome to the MassEnergize Team'
content_variables = {
'name': admin.full_name,
'adminlink': ADMIN_URL_ROOT,
'admintype': 'Super',
'admintext': "Now that you are a super admin, you have access the MassEnergize admin website at %s. You have full control over the content of our sites, can publish new communities and add new admins" % (ADMIN_URL_ROOT)
'admintext': "Now that you are a super admin, you have access the MassEnergize admin website at %s. You have full control over the content of our sites, can publish new communities and add new admins" % (ADMIN_URL_ROOT),
"me_logo": ME_LOGO_PNG,
"subject": "Welcome to the MassEnergize Team"
}
# sent from MassEnergize to cadmins
send_massenergize_rich_email(
subject, admin.email, 'new_admin_email.html', content_variables, None)

send_massenergize_email_with_attachments(NEW_ADMIN_EMAIL_TEMPLATE, content_variables, [admin.email], None, None, None)

return serialize(admin, full=True), None
except Exception as e:
log.exception(e)
Expand Down Expand Up @@ -65,11 +67,11 @@ def add_community_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError
"community_name": res["community_name"],
'sandbox_link': f"{COMMUNITY_URL_ROOT}/{res['subdomain']}?sandbox=true",
'portal_link': f"{COMMUNITY_URL_ROOT}/{res['subdomain']}",
'admin_type': 'Community'
'admin_type': 'Community',
"me_logo": ME_LOGO_PNG,
"subject": "Welcome to the MassEnergize Team"
}
#sent from MassEnergize support
send_massenergize_rich_email(
subject, res["email"], 'new_admin_email.html', content_variables, None)
send_massenergize_email_with_attachments(NEW_ADMIN_EMAIL_TEMPLATE, content_variables, [res["email"]], None, None, None)
res["user"] = serialize(res.get("user"))
return res, None
except Exception as e:
Expand Down Expand Up @@ -103,8 +105,6 @@ def message_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
if not first_name or first_name == "":
first_name = admin_name

subject = 'A message was sent to the Community Admin for ' + message.community.name

content_variables = {
'name': first_name,
'message_url': f"{ADMIN_URL_ROOT}/admin/edit/{message.id}/message",
Expand All @@ -113,9 +113,11 @@ def message_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
"email": message.email,
"subject": message.title,
"message_body": message.body,
"me_logo": ME_LOGO_PNG
}
# sent from MassEnergize to cadmins
send_massenergize_rich_email(subject, admin_email, 'contact_admin_email.html', content_variables, None)

send_massenergize_email_with_attachments(CONTACT_ADMIN_EMAIL_TEMPLATE, content_variables, [admin_email], None, None, None)


if IS_PROD or IS_CANARY:
send_slack_message(
Expand Down
20 changes: 13 additions & 7 deletions src/api/services/event.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from datetime import date
from _main_.utils.massenergize_errors import MassEnergizeAPIError, CustomMassenergizeError
from _main_.utils.common import serialize, serialize_all
from _main_.utils.pagination import paginate
from api.store.event import EventStore
from _main_.utils.constants import ADMIN_URL_ROOT, COMMUNITY_URL_ROOT, ME_LOGO_PNG
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments
from api.utils.api_utils import get_sender_email
from api.utils.constants import EVENT_RSVPS_EMAIL_TEMPLATE, EVENT_SUBMISSION_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from .utils import send_slack_message
from api.store.utils import get_user_or_die
Expand Down Expand Up @@ -110,8 +110,12 @@ def rsvp_update(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
}


send_massenergize_rich_email(
subject, user_email, 'event_rsvp_email.html', content_variables, from_email)
# send_massenergize_rich_email(
# subject, user_email, 'event_rsvp_email.html', content_variables, from_email)

send_massenergize_email_with_attachments(
EVENT_RSVPS_EMAIL_TEMPLATE,
content_variables, [user_email], None, None, None)


return serialize(event_attendee), None
Expand Down Expand Up @@ -181,7 +185,7 @@ def create_event(self, context, args, user_submitted=False) -> Tuple[dict, MassE
else:
return None, CustomMassenergizeError('Event submission incomplete')

subject = 'User Event Submitted'
# subject = 'User Event Submitted'

content_variables = {
'name': first_name,
Expand All @@ -191,10 +195,12 @@ def create_event(self, context, args, user_submitted=False) -> Tuple[dict, MassE
'email': email,
'title': event.name,
'body': event.description,
'me_logo':ME_LOGO_PNG
}
# sent from MassEnergize to cadmins
send_massenergize_rich_email(
subject, admin_email, 'event_submitted_email.html', content_variables, None)
# send_massenergize_rich_email(subject, admin_email, 'event_submitted_email.html', content_variables, None)
send_massenergize_email_with_attachments(EVENT_SUBMISSION_EMAIL_TEMPLATE, content_variables, [admin_email], None, None, None)


if IS_PROD or IS_CANARY:
send_slack_message(
Expand Down
17 changes: 10 additions & 7 deletions src/api/services/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from _main_.utils.pagination import paginate
from api.store.team import TeamStore
from api.store.message import MessageStore
from api.utils.api_utils import get_sender_email
from api.utils.constants import CONTACT_TEAM_ADMIN_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from database.models import TeamMember
from _main_.utils.context import Context
from _main_.utils.constants import ADMIN_URL_ROOT
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.constants import ADMIN_URL_ROOT, ME_LOGO_PNG
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from .utils import send_slack_message
from _main_.utils.massenergize_logger import log
Expand Down Expand Up @@ -122,7 +122,7 @@ def message_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
admin_email = community.owner_email
admin_name = community.owner_name

subject = 'A message was sent to the Team Admin for ' + team.name + ' in ' + community.name
# subject = 'A message was sent to the Team Admin for ' + team.name + ' in ' + community.name
team_members = TeamMember.objects.filter(team=team)
for member in team_members:
if member.is_admin:
Expand All @@ -141,10 +141,13 @@ def message_admin(self, context, args) -> Tuple[dict, MassEnergizeAPIError]:
"email": message.email,
"subject": message.title,
"message_body": message.body,
"me_logo":ME_LOGO_PNG
}
send_massenergize_rich_email(
subject, user.email, 'contact_team_admin_email.html', content_variables, None)

# send_massenergize_rich_email(
# subject, user.email, 'contact_team_admin_email.html', content_variables, None)

send_massenergize_email_with_attachments(CONTACT_TEAM_ADMIN_EMAIL_TEMPLATE, content_variables, [user.email], None, None, None)

if IS_PROD or IS_CANARY:
send_slack_message(
SLACK_SUPER_ADMINS_WEBHOOK_URL, {
Expand Down
14 changes: 9 additions & 5 deletions src/api/services/testimonial.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from _main_.utils.massenergize_errors import MassEnergizeAPIError, CustomMassenergizeError
from _main_.utils.constants import ADMIN_URL_ROOT
from _main_.utils.constants import ADMIN_URL_ROOT, ME_LOGO_PNG
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from _main_.utils.common import serialize, serialize_all
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments, send_massenergize_rich_email
from _main_.utils.pagination import paginate
from api.utils.api_utils import get_sender_email
from api.utils.constants import TESTIMONIAL_SUBMISSION_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from .utils import send_slack_message
from api.store.testimonial import TestimonialStore
Expand Down Expand Up @@ -55,7 +56,7 @@ def create_testimonial(self, context, args, user_submitted=False) -> Tuple[dict,
else:
return None, CustomMassenergizeError('Testimonial submission incomplete')

subject = 'User Testimonial Submitted'
# subject = 'User Testimonial Submitted'

content_variables = {
'name': first_name,
Expand All @@ -65,9 +66,12 @@ def create_testimonial(self, context, args, user_submitted=False) -> Tuple[dict,
'email': email,
'title': testimonial.title,
'body': testimonial.body,
'me_logo':ME_LOGO_PNG
}
send_massenergize_rich_email(
subject, admin_email, 'testimonial_submitted_email.html', content_variables, None)

send_massenergize_email_with_attachments(
TESTIMONIAL_SUBMISSION_EMAIL_TEMPLATE,
content_variables, [admin_email], None, None, None)

if IS_PROD or IS_CANARY:
send_slack_message(
Expand Down
14 changes: 9 additions & 5 deletions src/api/services/userprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from api.decorators import login_required
from api.store.userprofile import UserStore
from _main_.utils.context import Context
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments, send_massenergize_rich_email
from _main_.utils.constants import COMMUNITY_URL_ROOT, ME_LOGO_PNG
import os, csv
import re
from _main_.utils.massenergize_logger import log
from typing import Tuple
from api.utils.api_utils import get_sender_email

from api.utils.constants import COMMUNITY_INVITATION_EMAIL_TEMPLATE, NEW_USER_REGISTRATION_EMAIL_TEMPLATE, TEAM_INVITATION_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items


Expand Down Expand Up @@ -103,9 +104,11 @@ def _send_invitation_email(user_info, mess):
'privacylink': f"{homelink}/policies?name=Privacy%20Policy"
}

#send_massenergize_rich_email(subject, email, email_template, content_variables, cadmin_email)
send_massenergize_rich_email(subject, email, email_template, content_variables)

if team_name:
send_massenergize_email_with_attachments(TEAM_INVITATION_EMAIL_TEMPLATE, content_variables, [email], None, None, None)
else:
send_massenergize_email_with_attachments(COMMUNITY_INVITATION_EMAIL_TEMPLATE, content_variables, [email], None, None, None)

class UserService:
"""
Service Layer for all the users
Expand Down Expand Up @@ -237,7 +240,8 @@ def create_user(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIErro
'privacylink': f"{homelink}/policies?name=Privacy%20Policy"
}

send_massenergize_rich_email(subject, user.email, 'user_registration_email.html', content_variables, from_email)
# send_massenergize_rich_email(subject, user.email, 'user_registration_email.html', content_variables, from_email)
send_massenergize_email_with_attachments(NEW_USER_REGISTRATION_EMAIL_TEMPLATE, content_variables, [user.email], None, None, from_email)
user = serialize(user, full=True)
return {**user, "is_new":True }, None
except Exception as e:
Expand Down
15 changes: 10 additions & 5 deletions src/api/services/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from _main_.utils.pagination import paginate
from api.store.vendor import VendorStore
from _main_.utils.context import Context
from _main_.utils.constants import ADMIN_URL_ROOT
from _main_.utils.constants import ADMIN_URL_ROOT, ME_LOGO_PNG
from _main_.settings import SLACK_SUPER_ADMINS_WEBHOOK_URL, IS_PROD, IS_CANARY
from _main_.utils.emailer.send_email import send_massenergize_rich_email
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments, send_massenergize_rich_email
from api.utils.api_utils import get_sender_email
from api.utils.constants import VENDOR_SUBMISSION_EMAIL_TEMPLATE
from api.utils.filter_functions import sort_items
from .utils import send_slack_message
from api.store.utils import get_user_or_die, get_community_or_die
Expand Down Expand Up @@ -64,7 +65,7 @@ def create_vendor(self, context, args, user_submitted=False) -> Tuple[dict, Mass
else:
return None, CustomMassenergizeError('Vendor submission incomplete')

subject = 'User Service Provider Submitted'
# subject = 'User Service Provider Submitted'

content_variables = {
'name': first_name,
Expand All @@ -74,9 +75,13 @@ def create_vendor(self, context, args, user_submitted=False) -> Tuple[dict, Mass
'email': email,
'title': vendor.name,
'body': vendor.description,
'me_logo':ME_LOGO_PNG
}
send_massenergize_rich_email(
subject, admin_email, 'vendor_submitted_email.html', content_variables, None)
# send_massenergize_rich_email(
# subject, admin_email, 'vendor_submitted_email.html', content_variables, None)

send_massenergize_email_with_attachments(VENDOR_SUBMISSION_EMAIL_TEMPLATE, content_variables, [admin_email], None, None, None)


if IS_PROD or IS_CANARY:
send_slack_message(
Expand Down
8 changes: 1 addition & 7 deletions src/api/store/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
args['location'] = None

new_vendor = Vendor.objects.create(**args)

if communities:
new_vendor.communities.set(communities)

Expand All @@ -92,7 +91,7 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
if user_submitted:
name=f"ImageFor {new_vendor.name} Vendor"
logo = Media.objects.create(name=name, file=images)
user_media_upload = makeUserUpload(media = logo,info=image_info,communities=new_vendor.communities)
user_media_upload = makeUserUpload(media = logo,info=image_info,communities=new_vendor.communities.all())

else:
logo = Media.objects.filter(pk = images[0]).first()
Expand All @@ -119,14 +118,9 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,

if website:
new_vendor.more_info = {'website': website}

new_vendor.save()



if tags:
new_vendor.tags.set(tags)

new_vendor.save()
# ----------------------------------------------------------------
Spy.create_vendor_footage(vendors = [new_vendor], context = context, actor = new_vendor.user, type = FootageConstants.create(), notes =f"Vendor ID({new_vendor.id})")
Expand Down
Loading

0 comments on commit b60c93d

Please sign in to comment.