Skip to content

feat(nimbus): Show rejection message #12646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions experimenter/experimenter/experiments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,28 @@ def should_show_remote_settings_pending(self, reviewer):
self.PublishStatus.WAITING,
) and self.can_review(reviewer)

@property
def rejection_block(self):
rejection = self.changes.latest_rejection()
if not rejection:
return None

flow_key = None
if rejection.old_status == self.Status.DRAFT:
flow_key = "LAUNCH_EXPERIMENT"
elif rejection.old_status == self.Status.LIVE:
if rejection.old_status_next == self.Status.LIVE:
flow_key = "END_ENROLLMENT"
else:
flow_key = "END_EXPERIMENT"

Comment on lines +740 to +747
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you know, we should've done this more like

    class REVIEW_REQUEST_MESSAGES(Enum):
        END_EXPERIMENT = "end this experiment"
        END_ENROLLMENT = "end enrollment for this experiment"
        LAUNCH_EXPERIMENT = "launch this experiment"


    if rejection.old_status == self.Status.Draft:
        action = NimbusUIConstants.REVIEW_REQUEST_MESSAGES.LAUNCH_EXPERIMENT
    ...

instead of using a dict with constant keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup good point, I am adding more in the rollouts one, I can fix in that one

return {
"action": NimbusUIConstants.REVIEW_REQUEST_MESSAGES[flow_key],
"email": rejection.changed_by.email,
"date": rejection.changed_on,
"message": rejection.message,
}

def review_messages(self):
if self.status_next == self.Status.COMPLETE:
return NimbusUIConstants.REVIEW_REQUEST_MESSAGES["END_EXPERIMENT"]
Expand Down
51 changes: 51 additions & 0 deletions experimenter/experimenter/experiments/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,57 @@ def test_review_messages_and_action_type(self, lifecycle, expected_message):
experiment = NimbusExperimentFactory.create_with_lifecycle(lifecycle)
self.assertEqual(experiment.review_messages(), expected_message)

@parameterized.expand(
[
(
NimbusExperiment.Status.DRAFT,
None,
"LAUNCH_EXPERIMENT",
),
(
NimbusExperiment.Status.LIVE,
NimbusExperiment.Status.LIVE,
"END_ENROLLMENT",
),
(
NimbusExperiment.Status.LIVE,
NimbusExperiment.Status.COMPLETE,
"END_EXPERIMENT",
),
]
)
def test_rejection_block_from_rejection_changelog(
self,
status,
status_next,
expected_flow_key,
):
experiment = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.CREATED
)

experiment.status = status
experiment.status_next = status_next

for publish_status in (
NimbusExperiment.PublishStatus.REVIEW,
NimbusExperiment.PublishStatus.IDLE,
):
experiment.publish_status = publish_status
experiment.save()
generate_nimbus_changelog(experiment, experiment.owner, "test message")

block = experiment.rejection_block
self.assertIsNotNone(block)
self.assertEqual(
block["action"], NimbusUIConstants.REVIEW_REQUEST_MESSAGES[expected_flow_key]
)
self.assertEqual(
block["email"], experiment.changes.latest_rejection().changed_by.email
)
self.assertEqual(block["date"], experiment.changes.latest_rejection().changed_on)
self.assertEqual(block["message"], "test message")


class TestNimbusBranch(TestCase):
def test_str(self):
Expand Down
14 changes: 13 additions & 1 deletion experimenter/experimenter/nimbus_ui_new/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,21 @@ class ReviewToDraftForm(UpdateStatusForm):
status = NimbusExperiment.Status.DRAFT
status_next = NimbusExperiment.Status.DRAFT
publish_status = NimbusExperiment.PublishStatus.IDLE
changelog_message = forms.CharField(
required=False, label="Changelog Message", max_length=1000
)

cancel_message = forms.CharField(
required=False, label="Cancel Message", max_length=1000
)

def get_changelog_message(self):
return f"{self.request.user} cancelled the review"
if self.cleaned_data.get("changelog_message"):
return (
f"{self.request.user} rejected the review with reason: "
f"{self.cleaned_data['changelog_message']}"
)
return f"{self.request.user} {self.cleaned_data['cancel_message']}"


class ReviewToApproveForm(UpdateStatusForm):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{% load nimbus_extras %}

<div id="launch-controls">
{% with rejection=experiment.rejection_block %}
{% if rejection %}
<div class="alert alert-warning"
id="rejection-reason"
data-testid="rejection-notice">
<div class="text-body">
<p class="mb-2">
The request to {{ rejection.action }} was <strong>Rejected</strong> due to:
</p>
<p class="mb-2">{{ rejection.email }} on {{ rejection.date|date:"F j, Y" }}:</p>
<p class="bg-white rounded border p-2 mb-0">{{ rejection.message }}</p>
</div>
</div>
{% endif %}
{% endwith %}
<form>
{% csrf_token %}
<!-- Draft Mode Controls -->
Expand Down
34 changes: 31 additions & 3 deletions experimenter/experimenter/nimbus_ui_new/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,41 @@ def test_preview_to_draft_form(self):
self.assertIn("moved the experiment back to Draft", changelog.message)
self.mock_preview_task.assert_called_once_with(countdown=5)

def test_review_to_draft_form(self):
def test_review_to_draft_form_with_changelog_message(self):
self.experiment.status = NimbusExperiment.Status.DRAFT
self.experiment.status_next = NimbusExperiment.Status.LIVE
self.experiment.publish_status = NimbusExperiment.PublishStatus.REVIEW
self.experiment.save()

form = ReviewToDraftForm(data={}, instance=self.experiment, request=self.request)
form = ReviewToDraftForm(
data={"changelog_message": "Needs further updates."},
instance=self.experiment,
request=self.request,
)
self.assertTrue(form.is_valid(), form.errors)

experiment = form.save()
self.assertEqual(experiment.status, NimbusExperiment.Status.DRAFT)
self.assertEqual(experiment.status_next, NimbusExperiment.Status.DRAFT)
self.assertEqual(experiment.publish_status, NimbusExperiment.PublishStatus.IDLE)

changelog = experiment.changes.latest("changed_on")
self.assertEqual(changelog.changed_by, self.user)
self.assertIn(
"rejected the review with reason: Needs further updates.", changelog.message
)

def test_review_to_draft_form_with_cancel_message(self):
self.experiment.status = NimbusExperiment.Status.DRAFT
self.experiment.status_next = NimbusExperiment.Status.LIVE
self.experiment.publish_status = NimbusExperiment.PublishStatus.REVIEW
self.experiment.save()

form = ReviewToDraftForm(
data={"cancel_message": "Review was withdrawn by the user."},
instance=self.experiment,
request=self.request,
)
self.assertTrue(form.is_valid(), form.errors)

experiment = form.save()
Expand All @@ -688,7 +716,7 @@ def test_review_to_draft_form(self):

changelog = experiment.changes.latest("changed_on")
self.assertEqual(changelog.changed_by, self.user)
self.assertIn("cancelled the review", changelog.message)
self.assertIn(f"{self.user} Review was withdrawn by the user.", changelog.message)

def test_review_to_approve_form(self):
self.experiment.status = NimbusExperiment.Status.DRAFT
Expand Down