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] Management command to enable new emails for existing events #2671

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
3 changes: 2 additions & 1 deletion amy/emails/actions/ask_for_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def ask_for_website_strategy(event: Event) -> StrategyEnum:


def run_ask_for_website_strategy(
strategy: StrategyEnum, request: HttpRequest, event: Event
strategy: StrategyEnum, request: HttpRequest, event: Event, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: ask_for_website_signal,
Expand All @@ -95,6 +95,7 @@ def run_ask_for_website_strategy(
sender=event,
event=event,
event_start_date=event.start,
**kwargs,
)


Expand Down
61 changes: 51 additions & 10 deletions amy/emails/actions/base_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ def __call__(self, sender: Any, **kwargs) -> None:
return

request = kwargs.pop("request")
supress_messages = kwargs.pop("supress_messages", False)
dry_run = kwargs.pop("dry_run", False)

context = self.get_context(**kwargs)
context_json = self.get_context_json(context)
scheduled_at = self.get_scheduled_at(**kwargs)
generic_relation_obj = self.get_generic_relation_object(context, **kwargs)

try:
if dry_run:
logger.debug(
f"Dry-run mode: email action for signal {self.signal}, "
f"{generic_relation_obj}"
)
return

scheduled_email = EmailController.schedule_email(
signal=self.signal,
context_json=context_json,
Expand All @@ -91,17 +101,21 @@ def __call__(self, sender: Any, **kwargs) -> None:
to_header_context_json=self.get_recipients_context_json(
context, **kwargs
),
generic_relation_obj=self.get_generic_relation_object(
context, **kwargs
),
generic_relation_obj=generic_relation_obj,
author=person_from_request(request),
)
except EmailControllerMissingRecipientsException:
messages_missing_recipients(request, self.signal)
logger.warning(f"Missing recipients for signal {self.signal}")
if not supress_messages:
messages_missing_recipients(request, self.signal)
except EmailTemplate.DoesNotExist:
messages_missing_template(request, self.signal)
logger.warning(f"Missing template for signal {self.signal}")
if not supress_messages:
messages_missing_template(request, self.signal)
else:
messages_action_scheduled(request, self.signal, scheduled_email)
logger.info(f"Action scheduled for signal {self.signal}")
if not supress_messages:
messages_action_scheduled(request, self.signal, scheduled_email)


# TODO: turn into a generic class that combines BaseAction,
Expand All @@ -112,6 +126,8 @@ def __call__(self, sender: Any, **kwargs) -> None:
return

request = kwargs.pop("request")
supress_messages = kwargs.pop("supress_messages", False)
dry_run = kwargs.pop("dry_run", False)

context = self.get_context(**kwargs)
context_json = self.get_context_json(context)
Expand Down Expand Up @@ -147,6 +163,13 @@ def __call__(self, sender: Any, **kwargs) -> None:
return

try:
if dry_run:
logger.debug(
f"Dry-run mode: email update action for signal {self.signal}, "
f"{generic_relation_obj}"
)
return

scheduled_email = EmailController.update_scheduled_email(
scheduled_email=scheduled_email,
context_json=context_json,
Expand All @@ -159,13 +182,19 @@ def __call__(self, sender: Any, **kwargs) -> None:
author=person_from_request(request),
)
except EmailControllerMissingRecipientsException:
messages_missing_recipients(request, signal_name)
logger.warning(f"Missing recipients for signal {self.signal}")
if not supress_messages:
messages_missing_recipients(request, signal_name)
except EmailControllerMissingTemplateException:
# Note: this is not realistically possible because the scheduled email
# is looked up using a specific template signal.
messages_missing_template_link(request, scheduled_email)
logger.warning(f"Template not linked to signal {self.signal}")
if not supress_messages:
messages_missing_template_link(request, scheduled_email)
else:
messages_action_updated(request, signal_name, scheduled_email)
logger.info(f"Action updated for signal {self.signal}")
if not supress_messages:
messages_action_updated(request, signal_name, scheduled_email)


# TODO: turn into a generic class that combines BaseAction,
Expand All @@ -184,6 +213,9 @@ def __call__(self, sender: Any, **kwargs) -> None:
return

request = kwargs["request"]
supress_messages = kwargs.pop("supress_messages", False)
dry_run = kwargs.pop("dry_run", False)

context = self.get_context(**kwargs)
generic_relation_obj = self.get_generic_relation_object(context, **kwargs)
signal_name = self.signal
Expand All @@ -197,8 +229,17 @@ def __call__(self, sender: Any, **kwargs) -> None:
).select_for_update()

for scheduled_email in scheduled_emails:
if dry_run:
logger.debug(
f"Dry-run mode: email cancel action for signal {self.signal}, "
f"{generic_relation_obj}"
)
continue

scheduled_email = EmailController.cancel_email(
scheduled_email=scheduled_email,
author=person_from_request(request),
)
messages_action_cancelled(request, signal_name, scheduled_email)
logger.info(f"Action cancelled for signal {self.signal}")
if not supress_messages:
messages_action_cancelled(request, signal_name, scheduled_email)
3 changes: 2 additions & 1 deletion amy/emails/actions/host_instructors_introduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def host_instructors_introduction_strategy(event: Event) -> StrategyEnum:


def run_host_instructors_introduction_strategy(
strategy: StrategyEnum, request: HttpRequest, event: Event
strategy: StrategyEnum, request: HttpRequest, event: Event, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: host_instructors_introduction_signal,
Expand All @@ -108,6 +108,7 @@ def run_host_instructors_introduction_strategy(
request,
sender=event,
event=event,
**kwargs,
)


Expand Down
3 changes: 2 additions & 1 deletion amy/emails/actions/instructor_training_approaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def instructor_training_approaching_strategy(event: Event) -> StrategyEnum:


def run_instructor_training_approaching_strategy(
strategy: StrategyEnum, request: HttpRequest, event: Event
strategy: StrategyEnum, request: HttpRequest, event: Event, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: instructor_training_approaching_signal,
Expand All @@ -84,6 +84,7 @@ def run_instructor_training_approaching_strategy(
sender=event,
event=event,
event_start_date=event.start,
**kwargs,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def run_instructor_training_completed_not_badged_strategy(
request: HttpRequest,
person: Person,
training_completed_date: date | None,
**kwargs,
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: instructor_training_completed_not_badged_signal,
Expand Down Expand Up @@ -153,6 +154,7 @@ def run_instructor_training_completed_not_badged_strategy(
sender=person,
person=person,
training_completed_date=training_completed_date,
**kwargs,
)


Expand Down
3 changes: 2 additions & 1 deletion amy/emails/actions/new_membership_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def new_membership_onboarding_strategy(membership: Membership) -> StrategyEnum:


def run_new_membership_onboarding_strategy(
strategy: StrategyEnum, request: HttpRequest, membership: Membership
strategy: StrategyEnum, request: HttpRequest, membership: Membership, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: new_membership_onboarding_signal,
Expand All @@ -95,6 +95,7 @@ def run_new_membership_onboarding_strategy(
request,
sender=membership,
membership=membership,
**kwargs,
)


Expand Down
3 changes: 2 additions & 1 deletion amy/emails/actions/post_workshop_7days.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def post_workshop_7days_strategy(event: Event) -> StrategyEnum:


def run_post_workshop_7days_strategy(
strategy: StrategyEnum, request: HttpRequest, event: Event
strategy: StrategyEnum, request: HttpRequest, event: Event, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: post_workshop_7days_signal,
Expand All @@ -106,6 +106,7 @@ def run_post_workshop_7days_strategy(
sender=event,
event=event,
event_end_date=event.end,
**kwargs,
)


Expand Down
3 changes: 2 additions & 1 deletion amy/emails/actions/recruit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def recruit_helpers_strategy(event: Event) -> StrategyEnum:


def run_recruit_helpers_strategy(
strategy: StrategyEnum, request: HttpRequest, event: Event
strategy: StrategyEnum, request: HttpRequest, event: Event, **kwargs
) -> None:
signal_mapping: dict[StrategyEnum, Signal | None] = {
StrategyEnum.CREATE: recruit_helpers_signal,
Expand All @@ -102,6 +102,7 @@ def run_recruit_helpers_strategy(
sender=event,
event=event,
event_start_date=event.start,
**kwargs,
)


Expand Down
Empty file.
Empty file.
Loading
Loading