Skip to content
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

[Emails] Change email scheduled condition in some strategies #2722

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
13 changes: 6 additions & 7 deletions amy/emails/actions/ask_for_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
ASK_FOR_WEBSITE_SIGNAL_NAME,
Expand Down Expand Up @@ -63,19 +63,18 @@ def ask_for_website_strategy(event: Event) -> StrategyEnum:
logger.debug(f"{email_should_exist=}")

ct = ContentType.objects.get_for_model(event) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=event.pk,
template__signal=ASK_FOR_WEBSITE_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")
logger.debug(f"{email_exists=}")

if not has_email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
13 changes: 6 additions & 7 deletions amy/emails/actions/host_instructors_introduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
HOST_INSTRUCTORS_INTRODUCTION_SIGNAL_NAME,
Expand Down Expand Up @@ -77,19 +77,18 @@ def host_instructors_introduction_strategy(event: Event) -> StrategyEnum:
logger.debug(f"{email_should_exist=}")

ct = ContentType.objects.get_for_model(event) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=event.pk,
template__signal=HOST_INSTRUCTORS_INTRODUCTION_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")
logger.debug(f"{email_exists=}")

if not has_email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
15 changes: 7 additions & 8 deletions amy/emails/actions/instructor_confirmed_for_workshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
INSTRUCTOR_CONFIRMED_FOR_WORKSHOP_SIGNAL_NAME,
Expand Down Expand Up @@ -68,20 +68,19 @@ def instructor_confirmed_for_workshop_strategy(
)
logger.debug(f"{email_should_exist=}")

ct = ContentType.objects.get_for_model(Task) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
ct = ContentType.objects.get_for_model(Task)
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=optional_task_pk or task.pk,
template__signal=INSTRUCTOR_CONFIRMED_FOR_WORKSHOP_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")
logger.debug(f"{email_exists=}")

if not has_email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
13 changes: 6 additions & 7 deletions amy/emails/actions/instructor_training_approaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
INSTRUCTOR_TRAINING_APPROACHING_SIGNAL_NAME,
Expand Down Expand Up @@ -47,19 +47,18 @@ def instructor_training_approaching_strategy(event: Event) -> StrategyEnum:
logger.debug(f"{email_should_exist=}")

ct = ContentType.objects.get_for_model(event) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=event.pk,
template__signal=INSTRUCTOR_TRAINING_APPROACHING_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")
logger.debug(f"{email_exists=}")

if not has_email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
11 changes: 5 additions & 6 deletions amy/emails/actions/new_membership_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
NEW_MEMBERSHIP_ONBOARDING_SIGNAL_NAME,
Expand Down Expand Up @@ -39,11 +39,10 @@ def new_membership_onboarding_strategy(membership: Membership) -> StrategyEnum:
logger.info(f"Running NewMembershipOnboarding strategy for {membership}")

ct = ContentType.objects.get_for_model(membership) # type: ignore
email_scheduled = ScheduledEmail.objects.filter(
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=membership.pk,
template__signal=NEW_MEMBERSHIP_ONBOARDING_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
task_count = MembershipTask.objects.filter(
membership=membership, role__name__in=MEMBERSHIP_TASK_ROLES_EXPECTED
Expand All @@ -60,11 +59,11 @@ def new_membership_onboarding_strategy(membership: Membership) -> StrategyEnum:
# email would be de-scheduled.
email_should_exist = bool(membership.pk and task_count)

if not email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
13 changes: 6 additions & 7 deletions amy/emails/actions/post_workshop_7days.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
POST_WORKSHOP_7DAYS_SIGNAL_NAME,
Expand Down Expand Up @@ -57,7 +57,7 @@ def post_workshop_7days_strategy(event: Event) -> StrategyEnum:
at_least_1_instructor=at_least_1_instructor,
)

email_should_exist = (
email_exists = (
not_self_organised
and not_cldt
and end_date_in_future
Expand All @@ -66,22 +66,21 @@ def post_workshop_7days_strategy(event: Event) -> StrategyEnum:
and at_least_1_host
and at_least_1_instructor
)
logger.debug(f"{email_should_exist=}")
logger.debug(f"{email_exists=}")

ct = ContentType.objects.get_for_model(event) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=event.pk,
template__signal=POST_WORKSHOP_7DAYS_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")

if not has_email_scheduled and email_should_exist:
if not has_email_scheduled and email_exists:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif has_email_scheduled and not email_exists:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif has_email_scheduled and email_exists:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
13 changes: 6 additions & 7 deletions amy/emails/actions/recruit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from emails.actions.base_action import BaseAction, BaseActionCancel, BaseActionUpdate
from emails.actions.base_strategy import run_strategy
from emails.models import ScheduledEmail, ScheduledEmailStatus
from emails.models import ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import (
RECRUIT_HELPERS_SIGNAL_NAME,
Expand Down Expand Up @@ -70,19 +70,18 @@ def recruit_helpers_strategy(event: Event) -> StrategyEnum:
logger.debug(f"{email_should_exist=}")

ct = ContentType.objects.get_for_model(event) # type: ignore
has_email_scheduled = ScheduledEmail.objects.filter(
email_exists = ScheduledEmail.objects.filter(
generic_relation_content_type=ct,
generic_relation_pk=event.pk,
template__signal=RECRUIT_HELPERS_SIGNAL_NAME,
state=ScheduledEmailStatus.SCHEDULED,
).exists()
logger.debug(f"{has_email_scheduled=}")
logger.debug(f"{email_exists=}")

if not has_email_scheduled and email_should_exist:
if not email_exists and email_should_exist:
result = StrategyEnum.CREATE
elif has_email_scheduled and not email_should_exist:
elif email_exists and not email_should_exist:
result = StrategyEnum.CANCEL
elif has_email_scheduled and email_should_exist:
elif email_exists and email_should_exist:
result = StrategyEnum.UPDATE
else:
result = StrategyEnum.NOOP
Expand Down
Loading