From 10d085b7c8c2027b3e529e634d8f158b6a1dac44 Mon Sep 17 00:00:00 2001 From: Brad Hubbard-Nelson Date: Fri, 19 May 2023 15:27:03 -0400 Subject: [PATCH 1/4] Fix recipient email addresses --- src/api/tests/test_mou_reminder.py | 6 +++--- src/api/utils/constants.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/tests/test_mou_reminder.py b/src/api/tests/test_mou_reminder.py index 572454d3b..46a28b960 100644 --- a/src/api/tests/test_mou_reminder.py +++ b/src/api/tests/test_mou_reminder.py @@ -28,7 +28,7 @@ def test_send_admin_mou_notification( # Create an admin who should receive a notification (last notified more than a month ago) admin1 = UserProfile.objects.create( full_name="Akwesi", - email="akwesi@me.org", + email="akwesi@massenergize.org", is_deleted=False, is_community_admin=True, ) @@ -36,7 +36,7 @@ def test_send_admin_mou_notification( # Create an admin who should not receive a notification (last notified less than a month ago) admin2 = UserProfile.objects.create( full_name="Brad", - email="brad@me.org", + email="brad@massenergize.org", is_deleted=False, is_community_admin=True, ) @@ -44,7 +44,7 @@ def test_send_admin_mou_notification( # Create an admin who should receive a notification (never signed MOU) admin3 = UserProfile.objects.create( full_name="Tahiru", - email="tahiru@me.org", + email="tahiru@massenergize.org", is_deleted=False, is_community_admin=True, ) diff --git a/src/api/utils/constants.py b/src/api/utils/constants.py index 868c9745b..924323f97 100644 --- a/src/api/utils/constants.py +++ b/src/api/utils/constants.py @@ -1,6 +1,6 @@ from _main_.settings import IS_PROD, IS_LOCAL WHEN_USER_AUTHENTICATED_SESSION_EXPIRES = "WHEN_USER_AUTHENTICATED_SESSION_EXPIRES" -ME_SUPPORT_TEAM_EMAIL = "support@me.org" +ME_SUPPORT_TEAM_EMAIL = "support@massenergize.org" # API user types STANDARD_USER = 'standard_user' From f293a4bfd0d47f7340810d910f5506fb3af321ab Mon Sep 17 00:00:00 2001 From: Brad Hubbard-Nelson Date: Sat, 20 May 2023 13:21:27 -0400 Subject: [PATCH 2/4] Doublecheck not to nudge users when not in Prod --- .../events_nudge/user_event_nudge.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/task_queue/events_nudge/user_event_nudge.py b/src/task_queue/events_nudge/user_event_nudge.py index 2e8236ef6..402299d44 100644 --- a/src/task_queue/events_nudge/user_event_nudge.py +++ b/src/task_queue/events_nudge/user_event_nudge.py @@ -8,7 +8,7 @@ from django.db.models import Q from dateutil.relativedelta import relativedelta from database.utils.common import get_json_if_not_none - +from _main_.settings import IS_PROD, RUN_SERVER_LOCALLY from database.utils.settings.model_constants.events import EventConstants from django.utils import timezone @@ -193,7 +193,9 @@ def send_automated_nudge(events, user, community): user_is_ready_for_nudge = should_user_get_nudged(user) if user_is_ready_for_nudge: - print("sending nudge") + if not IS_PROD: + print(str(user) + ' will be nudged about ' + str(events)) + is_sent = send_events_report_email(name, email, events, community) if not is_sent: print( f"**** Failed to send email to {name} for community {community.name} ****") @@ -265,15 +267,21 @@ def prepare_user_events_nudge(email=None, community_id=None): for community in communities: if flag.audience == "EVERYONE" or community in allowed_communities: - print(community) + if not IS_PROD: + print("Nudging users in "+str(community)) + events = get_community_events(community.id) users = get_community_users(community.id) for user in users: - print(user) + # if not in Prod, only send mail if user marked as being connected with product team + events = get_user_events(user.notification_dates, events) - print(events) - send_automated_nudge(events, user, community) - + if IS_PROD and not RUN_SERVER_LOCALLY or user.is_super_admin or user.other_info and user.other_info.get('sw-team'): + send_automated_nudge(events, user, community) + else: + print(str(user) + ' would be notified about ' + str(events)) + + # Only update user notification date is an email was actually sent # update_user_notification_dates(communities, flag) From 57a3c84d593a9f409aefb05b642937f49fe0161c Mon Sep 17 00:00:00 2001 From: Brad Hubbard-Nelson Date: Mon, 16 Oct 2023 14:32:10 -0400 Subject: [PATCH 3/4] Fix broken tests --- src/api/store/action.py | 3 ++- src/api/store/event.py | 1 + src/api/store/vendor.py | 7 ++++--- src/api/tests/test_teams.py | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/store/action.py b/src/api/store/action.py index 671fd0eb7..032740927 100644 --- a/src/api/store/action.py +++ b/src/api/store/action.py @@ -88,7 +88,8 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M if community_id and not args.get('is_global', False): community = Community.objects.get(id=community_id) new_action.community = community - + + user_media_upload = None if images: #now, images will always come as an array of ids if user_submitted: name = f'ImageFor {new_action.title} Action' diff --git a/src/api/store/event.py b/src/api/store/event.py index 87d51fb1c..0f95cb653 100644 --- a/src/api/store/event.py +++ b/src/api/store/event.py @@ -305,6 +305,7 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma if community: new_event.community = community + user_media_upload = None if image: #now, images will always come as an array of ids if user_submitted: name= f'ImageFor {new_event.name} Event' diff --git a/src/api/store/vendor.py b/src/api/store/vendor.py index a387ac521..4e72a85bc 100644 --- a/src/api/store/vendor.py +++ b/src/api/store/vendor.py @@ -87,6 +87,7 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor, if communities: new_vendor.communities.set(communities) + user_media_upload = None if images: if user_submitted: name=f"ImageFor {new_vendor.name} Vendor" @@ -196,11 +197,11 @@ def update_vendor(self, context: Context, args, user_submitted) -> Tuple[dict, M media = Media.objects.filter(id = image[0]).first() vendor.logo = media - if vendor.image: + if vendor.logo: old_image_info, can_save_info = get_media_info(vendor.logo) if can_save_info: - vendor.image.user_upload.info.update({**old_image_info,**image_info}) - vendor.image.user_upload.save() + vendor.logo.user_upload.info.update({**old_image_info,**image_info}) + vendor.logo.user_upload.save() if onboarding_contact_email: diff --git a/src/api/tests/test_teams.py b/src/api/tests/test_teams.py index d40d80de1..5d2eff334 100644 --- a/src/api/tests/test_teams.py +++ b/src/api/tests/test_teams.py @@ -207,7 +207,6 @@ def test_stats(self): UserActionRel.objects.create(user=self.USER2, action=action2, status="DONE", real_estate_unit=reu, date_completed="2021-09-01") stats_response = self.client.post('/api/teams.stats', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() - print(stats_response) self.assertTrue(stats_response["success"]) self.assertIs(1, len(stats_response['data'])) From 8bfd23ea4580fa6e68bce98b65d624758071d28e Mon Sep 17 00:00:00 2001 From: Brad Hubbard-Nelson Date: Mon, 16 Oct 2023 16:12:30 -0400 Subject: [PATCH 4/4] CC Errors fixed from testing --- src/carbon_calculator/carbonCalculator.py | 14 +++++++++++++- src/carbon_calculator/queries.py | 9 +++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/carbon_calculator/carbonCalculator.py b/src/carbon_calculator/carbonCalculator.py index 157e34c8e..50629c00f 100644 --- a/src/carbon_calculator/carbonCalculator.py +++ b/src/carbon_calculator/carbonCalculator.py @@ -27,7 +27,7 @@ from .foodWaste import EvalLowCarbonDiet, EvalReduceWaste, EvalCompost from .landscaping import EvalReduceLawnSize, EvalReduceLawnCare, EvalRakeOrElecBlower, EvalElectricMower -CALCULATOR_VERSION = "4.0.2" +CALCULATOR_VERSION = "4.0.3" QUESTIONS_DATA = BASE_DIR + "/carbon_calculator/content/Questions.csv" ACTIONS_DATA = BASE_DIR + "/carbon_calculator/content/Actions.csv" DEFAULTS_DATA = BASE_DIR + "/carbon_calculator/content/defaults.csv" @@ -417,6 +417,18 @@ def __init__(self,name): self.text = "" # "Explanation for the calculated results." self.picture = "" + status, actionInfo = QuerySingleAction(self.name) + if status == VALID_QUERY: + self.id = actionInfo["id"] + self.title = actionInfo["title"] + self.description = actionInfo["description"] + self.helptext = actionInfo["helptext"] + self.questions = actionInfo["questionInfo"] # question with list of valid responses. + self.average_points = actionInfo["average_points"] + self.picture = actionInfo["picture"] + self.initialized = True + + def Query(self): status, actionInfo = QuerySingleAction(self.name) if not self.id and status == VALID_QUERY: diff --git a/src/carbon_calculator/queries.py b/src/carbon_calculator/queries.py index aed506058..e96e93c60 100644 --- a/src/carbon_calculator/queries.py +++ b/src/carbon_calculator/queries.py @@ -76,10 +76,11 @@ def QuerySingleAction(name,event_tag=""): questionInfo = [] for question in q.questions: - qq = CalculatorQuestion(question, event_tag) - # a question with no text is not to be included; this is how depending on the event_tag some questions would not be asked. - if len(qq.questionText)>0: - questionInfo.append(jsons.dump(qq)) + if question != '': + qq = CalculatorQuestion(question, event_tag) + # a question with no text is not to be included; this is how depending on the event_tag some questions would not be asked. + if len(qq.questionText)>0: + questionInfo.append(jsons.dump(qq)) picture = "" if q.picture: