Skip to content

Only send slack invite after user verifies email #360

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ def get_username_from_jwt(payload: dict) -> str:
def registration_callback(user: User, **kwargs: dict) -> None:
"""
Listens for the `user_signed_up` signal and adds a background tasks to
send the welcome email and slack invite
send the welcome email
"""
logger.info(f"Received user_signed_up signal for {user}")
send_slack_invite_job(user.email)
send_welcome_email(user.email)


@receiver(email_confirmed)
def email_confirmed_callback(email_address: EmailConfirmation, **kwargs: dict) -> None:
"""
Listens for the `email_confirmed` signal and adds a background task to
add the user to the mailing list
add the user to the mailing list and send the slack invite
"""
logger.info(f"Received email_confirmed signal for {email_address.email}")
send_slack_invite_job(email_address.email)
add_user_to_mailing_list(email_address.email)
27 changes: 24 additions & 3 deletions src/tests/integration/test_rest_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_user_profile_created(client: APIClient, register_form: Dict[str, str]):


@pytest.mark.django_db
def test_slack_invite_task_created(
def test_slack_invite_task_not_created(
client: APIClient,
register_form: Dict[str, str],
mailoutbox: List[EmailMultiAlternatives],
Expand All @@ -68,8 +68,7 @@ def test_slack_invite_task_created(

tasks = BackgroundTask.objects.filter(task_name="core.tasks.send_slack_invite_job")

assert len(tasks) == 1
assert tasks[0].task_name.split(".")[-1] == "send_slack_invite_job"
assert len(tasks) == 0


@pytest.mark.django_db
Expand Down Expand Up @@ -140,3 +139,25 @@ def test_mailing_list_task_created(
assert any(
task.task_name.split(".")[-1] == "add_user_to_mailing_list" for task in tasks
)


@pytest.mark.django_db
def test_slack_invite_task_created(
client: APIClient,
register_form: Dict[str, str],
mailoutbox: List[EmailMultiAlternatives],
):
client.post(reverse("rest_register"), register_form)

body = mailoutbox[0].body
groups = key_pattern.search(body).groupdict()

res = client.post(reverse("rest_verify_email"), {"key": groups["key"]})

assert res.status_code == 200
tasks = BackgroundTask.objects.filter(task_name="core.tasks.send_slack_invite_job")

assert len(tasks) == 1
assert any(
task.task_name.split(".")[-1] == "send_slack_invite_job" for task in tasks
)