Skip to content

Commit 2601d0b

Browse files
committed
Fix including policies text in emails of decisions coming from Cinder with notes (#23451)
* Fix including policies text in emails of decisions coming from Cinder with notes When a decision has notes there could be another activity created before that holds the private comments, so we should avoid grabbing that when generating the context for the email, as it would cause the policies to not be included in the email. * Don't change ordering logic, just exclude private comment action
1 parent a25748b commit 2601d0b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/olympia/abuse/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,9 @@ def send_notifications(self):
13911391
return
13921392

13931393
action_helper = self.get_action_helper()
1394-
log_entry = self.activities.last()
1394+
log_entry = self.activities.exclude(
1395+
action=amo.LOG.REVIEWER_PRIVATE_COMMENT.id
1396+
).last()
13951397
has_attachment = AttachmentLog.objects.filter(
13961398
activity_log__contentdecisionlog__decision=self
13971399
).exists()

src/olympia/abuse/tests/test_models.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,54 @@ def test_execute_action_disable_addon(self):
31223122
assert 'An attachment was provided.' not in mail.outbox[0].body
31233123
assert 'To respond or view the file,' not in mail.outbox[0].body
31243124

3125+
def test_execute_action_disable_addon_from_cinder_without_private_notes(self):
3126+
addon = addon_factory(users=[user_factory()])
3127+
decision = ContentDecision.objects.create(
3128+
addon=addon,
3129+
action=DECISION_ACTIONS.AMO_DISABLE_ADDON,
3130+
reviewer_user=None,
3131+
)
3132+
policy = CinderPolicy.objects.create(
3133+
uuid='1234',
3134+
name='Bad policy',
3135+
text='This is bad',
3136+
parent=CinderPolicy.objects.create(
3137+
uuid='p4r3nt',
3138+
name='Parent',
3139+
text='Parent policy text',
3140+
),
3141+
)
3142+
decision.policies.add(policy)
3143+
assert decision.action_date is None
3144+
decision.execute_action()
3145+
self._test_execute_action_disable_addon_outcome(decision)
3146+
assert 'Parent, specifically Bad policy: This is bad' in mail.outbox[0].body
3147+
3148+
def test_execute_action_disable_addon_from_cinder_with_private_notes(self):
3149+
addon = addon_factory(users=[user_factory()])
3150+
decision = ContentDecision.objects.create(
3151+
addon=addon,
3152+
action=DECISION_ACTIONS.AMO_DISABLE_ADDON,
3153+
reviewer_user=None,
3154+
private_notes='some private notes',
3155+
)
3156+
policy = CinderPolicy.objects.create(
3157+
uuid='1234',
3158+
name='Bad policy',
3159+
text='This is bad',
3160+
parent=CinderPolicy.objects.create(
3161+
uuid='p4r3nt',
3162+
name='Parent',
3163+
text='Parent policy text',
3164+
),
3165+
)
3166+
decision.policies.add(policy)
3167+
assert decision.action_date is None
3168+
decision.execute_action()
3169+
self._test_execute_action_disable_addon_outcome(decision)
3170+
assert 'Parent, specifically Bad policy: This is bad' in mail.outbox[0].body
3171+
assert 'some private notes' not in mail.outbox[0].body
3172+
31253173
def _test_execute_action_reject_version_outcome(self, decision):
31263174
decision.send_notifications()
31273175
assert 'appeal' in mail.outbox[0].body

0 commit comments

Comments
 (0)