Skip to content

Commit

Permalink
Merge pull request #2715 from carpentries/feature/2662-enable-members…
Browse files Browse the repository at this point in the history
…hip-onboarding-email-for-rollovers

[Emails] Enable membership onboarding email for membership rollovers
  • Loading branch information
pbanaszkiewicz authored Nov 5, 2024
2 parents 2ddaa4a + 1547c01 commit 53b22b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 1 addition & 8 deletions amy/emails/actions/new_membership_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,13 @@ def new_membership_onboarding_strategy(membership: Membership) -> StrategyEnum:
log_condition_elements(
**{
"membership.pk": membership.pk,
"membership.rolled_from_membership": getattr(
membership, "rolled_from_membership", None
),
"task_count": task_count,
}
)

# Membership can't be removed without removing the tasks first. This is when the
# email would be de-scheduled.
email_should_exist = (
membership.pk
and getattr(membership, "rolled_from_membership", None) is None
and task_count
)
email_should_exist = bool(membership.pk and task_count)

if not email_scheduled and email_should_exist:
result = StrategyEnum.CREATE
Expand Down
13 changes: 13 additions & 0 deletions amy/fiscal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class MembershipCreateRollOver(
permission_required = ["workshops.create_membership", "workshops.change_membership"]
template_name = "generic_form.html"
model = Membership
object: Membership
form_class = MembershipRollOverForm
pk_url_kwarg = "membership_id"
success_message = (
Expand Down Expand Up @@ -645,6 +646,18 @@ def form_valid(self, form):
]
)

try:
run_new_membership_onboarding_strategy(
new_membership_onboarding_strategy(self.object),
request=self.request,
membership=self.object,
)
except EmailStrategyException as exc:
messages.error(
self.request,
f"Error when creating or updating scheduled email. {exc}",
)

return result

def get_success_url(self) -> str:
Expand Down
10 changes: 10 additions & 0 deletions amy/workshops/management/commands/fake_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ def real_organizations(self):
if created:
self.stdout.write('Added "{}" organization.'.format(domain))

def fake_membership_person_roles(self):
self.stdout.write("Generating fake membership person roles...")
MemberRole.objects.create(
name="billing_contact", verbose_name="Billing Contact"
)
MemberRole.objects.create(
name="programmatic_contact", verbose_name="Programmatic Contact"
)

def fake_memberships(self, count=10):
self.stdout.write("Generating {} fake memberships...".format(count))

Expand Down Expand Up @@ -1003,6 +1012,7 @@ def handle(self, *args, **options):
self.fake_admins()
self.fake_organizations()
self.real_organizations()
self.fake_membership_person_roles()
self.fake_memberships()
self.fake_current_events()
self.fake_unpublished_events()
Expand Down

0 comments on commit 53b22b1

Please sign in to comment.