Skip to content

Commit

Permalink
MPP-3119: use flag_is_active_in_task and move to check each address user
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Sep 24, 2024
1 parent 324695d commit 5d2e79d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions emails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,12 +1641,23 @@ def _send_disabled_mask_for_spam_email(


def _disable_masks_for_complaint(message_json: dict) -> None:
_, _ = get_waffle_flag_model().objects.get_or_create(
name="disable_mask_on_complaint",
defaults={
"note": (
"MPP-3119: When a Relay user marks an email as spam, disable the mask."
)
},
)
for destination_address in message_json.get("mail", {}).get("destination", []):
try:
address = _get_address(destination_address, False)
address.enabled = False
address.save()
_send_disabled_mask_for_spam_email(address, message_json.get("mail", {}))
if flag_is_active_in_task("disable_mask_on_complaint", address.user):
address.enabled = False
address.save()
_send_disabled_mask_for_spam_email(
address, message_json.get("mail", {})
)
except (
ObjectDoesNotExist,
RelayAddress.DoesNotExist,
Expand Down Expand Up @@ -1729,16 +1740,7 @@ def _handle_complaint(message_json: AWS_SNSMessageJSON) -> HttpResponse:
profile.auto_block_spam = True
profile.save()

disable_mask_on_complaint_flag, _ = get_waffle_flag_model().objects.get_or_create(
name="disable_mask_on_complaint",
defaults={
"note": (
"MPP-3119: When a Relay user marks an email as spam, disable the mask."
)
},
)
if disable_mask_on_complaint_flag.is_active_for_user(user):
_disable_masks_for_complaint(message_json)
_disable_masks_for_complaint(message_json)

if not complaint_data:
# Data when there are no identified recipients
Expand Down

0 comments on commit 5d2e79d

Please sign in to comment.