From 2577fe3b041b415a957aaad96f1f6588bbc2f823 Mon Sep 17 00:00:00 2001 From: Daniel Smith <56164590+DanielRyanSmith@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:21:21 +0000 Subject: [PATCH] Use the origin trial display name in trial extension emails (#4679) * use OT name for extension email * update validation checks * changes suggested by @jrobbins --------- Co-authored-by: DanielRyanSmith --- internals/notifier.py | 21 +++++++++++---------- internals/notifier_helpers.py | 14 +++++++++++--- internals/notifier_test.py | 8 +++++--- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/internals/notifier.py b/internals/notifier.py index 30add6f98e57..35a0b2b7e3b9 100644 --- a/internals/notifier.py +++ b/internals/notifier.py @@ -845,21 +845,22 @@ class OTExtensionApprovedHandler(basehandlers.FlaskHandler): def process_post_data(self, **kwargs): self.require_task_header() feature = self.get_param('feature') - if feature is None: - self.abort(400, 'No feature provided.') gate_id = self.get_param('gate_id') - if gate_id is None: - self.abort(400, 'Extension gate ID not provided.') requester_email = self.get_param('requester_email') - if not requester_email: - self.abort(400, 'Extension requester\'s email address not provided.') + ot_display_name = self.get_param('ot_display_name') logging.info('Starting to notify about successful origin trial extension.') - send_emails([self.build_email(feature, requester_email, gate_id)]) + send_emails([self.build_email( + feature, requester_email, gate_id, ot_display_name)]) return {'message': 'OK'} def build_email( - self, feature: FeatureEntry, requester_email: str, gate_id: int): + self, + feature: FeatureEntry, + requester_email: str, + gate_id: int, + ot_display_name: str + ): body_data = { 'feature': feature, 'id': feature['id'], @@ -871,8 +872,8 @@ def build_email( return { 'to': requester_email, 'cc': [OT_SUPPORT_EMAIL], - 'subject': ('Origin trial extension approved and ready to be initiated: ' - f'{feature["name"]}'), + 'subject': ('Origin trial extension approved and ready to be ' + f'initiated: {ot_display_name}'), 'reply_to': None, 'html': body, } diff --git a/internals/notifier_helpers.py b/internals/notifier_helpers.py index 40397f676fad..48d2169ece17 100644 --- a/internals/notifier_helpers.py +++ b/internals/notifier_helpers.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging from typing import TYPE_CHECKING import settings from api import converters @@ -215,13 +216,20 @@ def send_ot_creation_notification(stage: Stage): def send_trial_extension_approved_notification( fe: 'FeatureEntry', stage: Stage, gate_id: int) -> None: """Notify that a trial extension is ready to be finalized.""" - # If we don't have an OT owner email, don't send the email out. - # This should always be set, and is collected during the extension request. - if not stage.ot_owner_email: + # If we don't have an OT owner email or stage ID, don't send the email out. + # These should always be set, and are collected during the extension request. + if not stage.ot_owner_email or not stage.ot_stage_id: + return + + ot_stage: Stage|None = Stage.get_by_id(stage.ot_stage_id) + if ot_stage is None: + logging.error('No origin trial stage found for given OT stage ID', + stage.ot_stage_id) return params = { 'feature': converters.feature_entry_to_json_verbose(fe), + 'ot_display_name': ot_stage.ot_display_name, 'requester_email': stage.ot_owner_email, 'gate_id': gate_id, } diff --git a/internals/notifier_test.py b/internals/notifier_test.py index 955485ab1ec1..73795da285e9 100644 --- a/internals/notifier_test.py +++ b/internals/notifier_test.py @@ -1139,7 +1139,8 @@ class OTExtensionApprovedHandlerTest(testing_config.CustomTestCase): def setUp(self): self.feature = FeatureEntry( id=1, name='A feature', summary='summary', category=1) - self.ot_stage = Stage(id=2, feature_id=1, stage_type=150) + self.ot_stage = Stage(id=2, feature_id=1, stage_type=150, + ot_display_name='OT Display Name') self.extension_stage = Stage( feature_id=1, ot_stage_id=2, stage_type=151, milestones=MilestoneSet(desktop_last=106), @@ -1165,12 +1166,13 @@ def test_make_extension_approved_email(self): handler = notifier.OTExtensionApprovedHandler() email_task = handler.build_email(feature_dict, self.extension_stage.ot_owner_email, - self.extension_gate.key.integer_id()) + self.extension_gate.key.integer_id(), + self.ot_stage.ot_display_name) # TESTDATA.make_golden(email_task['html'], 'test_make_extension_approved_email.html') self.assertEqual( email_task['subject'], ('Origin trial extension approved and ready to be initiated: ' - 'A feature')) + 'OT Display Name')) self.assertEqual(email_task['html'], TESTDATA['test_make_extension_approved_email.html'])