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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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"

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
50 changes: 50 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,56 @@ 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
assert block is not None
assert (
block["action"]
== NimbusUIConstants.REVIEW_REQUEST_MESSAGES[expected_flow_key]
)
assert block["email"] == experiment.changes.latest_rejection().changed_by.email
assert block["date"] == experiment.changes.latest_rejection().changed_on
assert block["message"] == "test message"


class TestNimbusBranch(TestCase):
def test_str(self):
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