diff --git a/src/_main_/utils/constants.py b/src/_main_/utils/constants.py index bfec53ecb..4ad69c458 100644 --- a/src/_main_/utils/constants.py +++ b/src/_main_/utils/constants.py @@ -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 @@ -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.", diff --git a/src/api/services/action.py b/src/api/services/action.py index 7886b8242..ceead7d12 100644 --- a/src/api/services/action.py +++ b/src/api/services/action.py @@ -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 @@ -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, @@ -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( @@ -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 diff --git a/src/api/services/admin.py b/src/api/services/admin.py index 03d7a7d01..a1c3a366e 100644 --- a/src/api/services/admin.py +++ b/src/api/services/admin.py @@ -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 @@ -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) @@ -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: @@ -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", @@ -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( diff --git a/src/api/services/event.py b/src/api/services/event.py index c367f01b9..79c60bb9e 100644 --- a/src/api/services/event.py +++ b/src/api/services/event.py @@ -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 @@ -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 @@ -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, @@ -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( diff --git a/src/api/services/team.py b/src/api/services/team.py index 2558767d4..1d588ad56 100644 --- a/src/api/services/team.py +++ b/src/api/services/team.py @@ -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 @@ -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: @@ -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, { diff --git a/src/api/services/testimonial.py b/src/api/services/testimonial.py index e90c989c3..ad607bd14 100644 --- a/src/api/services/testimonial.py +++ b/src/api/services/testimonial.py @@ -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 @@ -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, @@ -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( diff --git a/src/api/services/userprofile.py b/src/api/services/userprofile.py index 04a3f15d2..5fb65b267 100644 --- a/src/api/services/userprofile.py +++ b/src/api/services/userprofile.py @@ -4,7 +4,7 @@ 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 @@ -12,6 +12,7 @@ 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 @@ -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 @@ -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: diff --git a/src/api/services/vendor.py b/src/api/services/vendor.py index 18021e643..f89eb8dbc 100644 --- a/src/api/services/vendor.py +++ b/src/api/services/vendor.py @@ -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 @@ -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, @@ -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( diff --git a/src/api/store/vendor.py b/src/api/store/vendor.py index d71a62259..d819c780c 100644 --- a/src/api/store/vendor.py +++ b/src/api/store/vendor.py @@ -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) @@ -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() @@ -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})") diff --git a/src/api/utils/constants.py b/src/api/utils/constants.py index a3a36b87d..0844611de 100644 --- a/src/api/utils/constants.py +++ b/src/api/utils/constants.py @@ -18,3 +18,16 @@ CADMIN_TESTIMONIAL_NUDGE_TEMPLATE="cadmin-shared-testimonial-nudge-temp-alias" THANK_YOU_FOR_GETTING_IN_TOUCH_TEMPLATE="campaign-get-in-touch-template-user" CAMPAIGN_CONTACT_MESSAGE_TEMPLATE="campaign-get-in-touch-template-admin" + +# new +CONTACT_TEAM_ADMIN_EMAIL_TEMPLATE = "contact-team-admin-email-template-id" +CONTACT_ADMIN_EMAIL_TEMPLATE = "contact-admin-email-template-id" +VENDOR_SUBMISSION_EMAIL_TEMPLATE = "vendor-submission-email-template-id" +ACTION_SUBMISSION_EMAIL_TEMPLATE = "action-submission-email-template-id" +EVENT_SUBMISSION_EMAIL_TEMPLATE = "event-submission-email-template-id" +EVENT_RSVPS_EMAIL_TEMPLATE = "event-rsvps-email-template-id" +TESTIMONIAL_SUBMISSION_EMAIL_TEMPLATE = "testimonial-submission-email-template-id" +NEW_ADMIN_EMAIL_TEMPLATE = "new-admin-email-template-id" +NEW_USER_REGISTRATION_EMAIL_TEMPLATE = "new-user-registration-email-template-id" +TEAM_INVITATION_EMAIL_TEMPLATE = "team-invitation-email-template-id" +COMMUNITY_INVITATION_EMAIL_TEMPLATE = "community-invitation-email-template-id" \ No newline at end of file diff --git a/src/task_queue/nudges/cadmin_testimonial_nudge.py b/src/task_queue/nudges/cadmin_testimonial_nudge.py index a0d206641..86a45257d 100644 --- a/src/task_queue/nudges/cadmin_testimonial_nudge.py +++ b/src/task_queue/nudges/cadmin_testimonial_nudge.py @@ -1,6 +1,6 @@ from datetime import datetime from _main_.utils.common import encode_data_for_URL, serialize_all -from _main_.utils.constants import ADMIN_URL_ROOT, COMMUNITY_URL_ROOT +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 from _main_.utils.feature_flag_keys import TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY from _main_.utils.massenergize_logger import log @@ -8,7 +8,7 @@ from api.utils.constants import CADMIN_TESTIMONIAL_NUDGE_TEMPLATE from database.models import Community, CommunityAdminGroup, FeatureFlag, Testimonial from task_queue.helpers import get_summary -from task_queue.nudges.nudge_utils import ME_DEFAULT_IMAGE, get_admin_email_list, update_last_notification_dates +from task_queue.nudges.nudge_utils import get_admin_email_list, update_last_notification_dates from dateutil.relativedelta import relativedelta from django.db.models import Q from django.utils import timezone @@ -73,7 +73,7 @@ def send_nudge(data, community, admin): data = { "testimonials": to_send, "community_name": community.name, - "community_logo": community.logo.file.url if community.logo else ME_DEFAULT_IMAGE, + "community_logo": community.logo.file.url if community.logo else ME_LOGO_PNG, "name": name, } login_method = user_info.get("login_method") if user_info else None diff --git a/src/task_queue/nudges/nudge_utils.py b/src/task_queue/nudges/nudge_utils.py index 09990e234..ebc124db2 100644 --- a/src/task_queue/nudges/nudge_utils.py +++ b/src/task_queue/nudges/nudge_utils.py @@ -13,7 +13,6 @@ DAILY = "per_day" EASTERN_TIME_ZONE = custom_timezone_info("US/Eastern") -ME_DEFAULT_IMAGE = "https://www.massenergize.org/wp-content/uploads/2021/07/cropped-me-logo-transp.png" LIMIT = 5 diff --git a/src/website/templates/action_submitted_email.html b/src/website/templates/action_submitted_email.html index c38b32821..2fb11702e 100644 --- a/src/website/templates/action_submitted_email.html +++ b/src/website/templates/action_submitted_email.html @@ -90,7 +90,7 @@