diff --git a/api/reviews_api.py b/api/reviews_api.py index 2c2fc155292a..d6571d4a94bf 100644 --- a/api/reviews_api.py +++ b/api/reviews_api.py @@ -26,7 +26,7 @@ from internals import approval_defs, notifier_helpers from internals.core_enums import * from internals.core_models import FeatureEntry, Stage -from internals.review_models import Gate, Vote +from internals.review_models import Gate, Vote, Amendment, Activity def get_user_feature_and_gate(handler, kwargs) -> Tuple[ @@ -84,7 +84,21 @@ def do_post(self, **kwargs) -> dict[str, str]: fe, stage, gate_id) if new_state in (Vote.REVIEW_REQUESTED, Vote.NA_REQUESTED): + old_assignees = gate.assignee_emails[:] approval_defs.auto_assign_reviewer(gate) + new_assignees = gate.assignee_emails[:] + if old_assignees != new_assignees: + amendment = Amendment( + field_name='review_assignee', + old_value=', '.join(old_assignees), + new_value=', '.join(new_assignees)) + activity = Activity( + feature_id=fe.key.integer_id(), gate_id=gate_id, + author=user.email(), amendments=[amendment]) + activity.put() + # Note: We don't notify assignee about autoassignment, because they + # will get a notification of review state change anyway. + notifier_helpers.notify_approvers_of_reviews( fe, gate, new_state, user.email()) else: diff --git a/internals/notifier_helpers.py b/internals/notifier_helpers.py index c10c1c2b670e..1e71759cb303 100644 --- a/internals/notifier_helpers.py +++ b/internals/notifier_helpers.py @@ -173,6 +173,13 @@ def notify_assignees( } cloud_tasks_helpers.enqueue_task('/tasks/email-assigned', params) + amendment = Amendment( + field_name='review_assignee', + old_value=', '.join(old_assignees), new_value=', '.join(new_assignees)) + gate_id = gate.key.integer_id() + activity = Activity(feature_id=fe.key.integer_id(), gate_id=gate_id, + author=triggering_user_email, amendments=[amendment]) + activity.put() def notify_subscribers_of_new_comments(fe: 'FeatureEntry', gate: Gate, diff --git a/internals/review_models.py b/internals/review_models.py index 6105b8c3b9dc..1328a16fc265 100644 --- a/internals/review_models.py +++ b/internals/review_models.py @@ -200,7 +200,7 @@ class Amendment(ndb.Model): new_value = ndb.TextProperty() -class Activity(ndb.Model): # copy from Comment +class Activity(ndb.Model): """An activity log entry (comment + amendments) on a gate or feature.""" feature_id = ndb.IntegerProperty(required=True) gate_id = ndb.IntegerProperty() # The gate commented on, or general comment.