def send_external_join_confirmation(group_pk, email, **kwargs): try: group = SupportGroup.objects.get(pk=group_pk) except SupportGroup.DoesNotExist: return subscription_token = subscription_confirmation_token_generator.make_token( email=email, **kwargs) confirm_subscription_url = front_url("external_join_group", args=[group_pk], auto_login=False) query_args = {"email": email, **kwargs, "token": subscription_token} confirm_subscription_url += "?" + urlencode(query_args) bindings = { "GROUP_NAME": group.name, "JOIN_LINK": confirm_subscription_url } send_mosaico_email( code="GROUP_EXTERNAL_JOIN_OPTIN", subject=_(f"Confirmez que vous souhaitez rejoindre « {group.name} »"), from_email=settings.EMAIL_FROM, recipients=[email], bindings=bindings, )
def test_cannot_external_join_if_does_not_allow_external(self): self.subtype.allow_external = False self.subtype.save() subscription_token = subscription_confirmation_token_generator.make_token( email="*****@*****.**" ) query_args = {"email": "*****@*****.**", "token": subscription_token} self.client.get( reverse("external_join_group", args=[self.group.pk]) + "?" + urlencode(query_args) ) with self.assertRaises(Person.DoesNotExist): Person.objects.get(email="*****@*****.**")
def send_confirmation_email(email, type=SUBSCRIPTION_TYPE_LFI, **kwargs): if PersonEmail.objects.filter(address__iexact=email).exists(): p = Person.objects.get_by_natural_key(email) if "already_subscribed" in SUBSCRIPTIONS_EMAILS[type]: message_info = SUBSCRIPTIONS_EMAILS[type]["already_subscribed"] send_mosaico_email( code=message_info.code, subject=message_info.subject, from_email=message_info.from_email, bindings={ "PANEL_LINK": front_url("dashboard", auto_login=True), "AGO": pretty_time_since(p.created), }, recipients=[p], ) return subscription_token = subscription_confirmation_token_generator.make_token( email=email, type=type, **kwargs) confirm_subscription_url = front_url("subscription_confirm", auto_login=False, nsp=type == SUBSCRIPTION_TYPE_NSP) query_args = { "email": email, "type": type, **kwargs, "token": subscription_token } confirm_subscription_url += "?" + urlencode(query_args) message_info = SUBSCRIPTIONS_EMAILS[type]["confirmation"] send_mosaico_email( code=message_info.code, subject=message_info.subject, from_email=message_info.from_email, recipients=[email], bindings={"CONFIRMATION_URL": confirm_subscription_url}, )
def test_can_join(self): res = self.client.get(reverse("view_group", args=[self.group.pk])) self.assertNotContains(res, "Se connecter pour") self.assertContains(res, "Rejoindre ce groupe") self.client.post( reverse("external_join_group", args=[self.group.pk]), data={"email": self.person.email}, ) self.assertEqual(self.person.rsvps.all().count(), 0) subscription_token = subscription_confirmation_token_generator.make_token( email=self.person.email ) query_args = {"email": self.person.email, "token": subscription_token} self.client.get( reverse("external_join_group", args=[self.group.pk]) + "?" + urlencode(query_args) ) self.assertEqual(self.person.supportgroups.first(), self.group)
def send_external_rsvp_confirmation(event_pk, email, **kwargs): event = Event.objects.get(pk=event_pk) subscription_token = subscription_confirmation_token_generator.make_token( email=email, **kwargs) confirm_subscription_url = front_url("external_rsvp_event", args=[event_pk], auto_login=False) query_args = {"email": email, **kwargs, "token": subscription_token} confirm_subscription_url += "?" + urlencode(query_args) bindings = { "EVENT_NAME": event.name, "RSVP_LINK": confirm_subscription_url } send_mosaico_email( code="EVENT_EXTERNAL_RSVP_OPTIN", subject=_("Merci de confirmer votre participation à l'événement"), from_email=settings.EMAIL_FROM, recipients=[email], bindings=bindings, )
def test_can_rsvp_without_account(self): self.client.post( reverse("external_join_group", args=[self.group.pk]), data={"email": "*****@*****.**"}, ) with self.assertRaises(Person.DoesNotExist): Person.objects.get(email="*****@*****.**") subscription_token = subscription_confirmation_token_generator.make_token( email="*****@*****.**" ) query_args = {"email": "*****@*****.**", "token": subscription_token} self.client.get( reverse("external_join_group", args=[self.group.pk]) + "?" + urlencode(query_args) ) self.assertEqual( Person.objects.get(email="*****@*****.**").supportgroups.first(), self.group ) self.assertEqual(Person.objects.get(email="*****@*****.**").is_insoumise, False)
def send_no_account_email(email, subscription_type=SUBSCRIPTION_TYPE_AP, **kwargs): subscription_token = subscription_confirmation_token_generator.make_token( email=email, type=subscription_type, **kwargs) confirm_subscription_url = front_url("subscription_confirm", auto_login=False, nsp=False) query_args = { "email": email, "type": subscription_type, **kwargs, "token": subscription_token, } confirm_subscription_url += "?" + urlencode(query_args) send_mosaico_email( code="UNEXISTING_EMAIL_LOGIN", subject="Vous n'avez pas encore de compte sur Action Populaire", from_email=settings.EMAIL_FROM, recipients=[email], bindings={"SUBSCRIPTION_URL": confirm_subscription_url}, )
def make_subscription_token(email, **kwargs): return subscription_confirmation_token_generator.make_token(email=email, **kwargs)