Skip to content

Commit

Permalink
Use the origin trial display name in trial extension emails (#4679)
Browse files Browse the repository at this point in the history
* use OT name for extension email

* update validation checks

* changes suggested by @jrobbins

---------

Co-authored-by: DanielRyanSmith <[email protected]>
  • Loading branch information
DanielRyanSmith and DanielRyanSmith authored Jan 13, 2025
1 parent 6007373 commit 2577fe3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
21 changes: 11 additions & 10 deletions internals/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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,
}
Expand Down
14 changes: 11 additions & 3 deletions internals/notifier_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
8 changes: 5 additions & 3 deletions internals/notifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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'])

Expand Down

0 comments on commit 2577fe3

Please sign in to comment.