Esempio n. 1
0
def send_external_join_confirmation(self, 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}

    try:
        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,
        )
    except (smtplib.SMTPException, socket.error) as exc:
        self.retry(countdown=60, exc=exc)
Esempio n. 2
0
def send_external_rsvp_confirmation(self, event_pk, email, **kwargs):
    try:
        event = Event.objects.get(pk=event_pk)
    except ObjectDoesNotExist:
        return

    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
    }

    try:
        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,
        )
    except (smtplib.SMTPException, socket.error) as exc:
        self.retry(countdown=60, exc=exc)
Esempio n. 3
0
    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="*****@*****.**")
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
def send_confirmation_email(self, email, **kwargs):
    if PersonEmail.objects.filter(address__iexact=email).exists():
        p = Person.objects.get_by_natural_key(email)

        try:
            send_mosaico_email(
                code="ALREADY_SUBSCRIBED_MESSAGE",
                subject=_("Vous êtes déjà inscrit !"),
                from_email=settings.EMAIL_FROM,
                bindings={
                    "PANEL_LINK": front_url("dashboard", auto_login=True),
                    "AGO": pretty_time_since(p.created),
                },
                recipients=[p],
            )
        except (smtplib.SMTPException, socket.error) as exc:
            self.retry(countdown=60, exc=exc)

        return

    subscription_token = subscription_confirmation_token_generator.make_token(
        email=email, **kwargs
    )
    confirm_subscription_url = front_url("subscription_confirm", auto_login=False)
    query_args = {"email": email, **kwargs, "token": subscription_token}
    confirm_subscription_url += "?" + urlencode(query_args)

    try:
        send_mosaico_email(
            code="SUBSCRIPTION_CONFIRMATION_MESSAGE",
            subject=_("Plus qu'un clic pour vous inscrire"),
            from_email=settings.EMAIL_FROM,
            recipients=[email],
            bindings={"CONFIRMATION_URL": confirm_subscription_url},
        )
    except (smtplib.SMTPException, socket.error) as exc:
        self.retry(countdown=60, exc=exc)
Esempio n. 7
0
def invite_to_group(self, group_id, invited_email, inviter_id):
    try:
        group = SupportGroup.objects.get(pk=group_id)
    except SupportGroup.DoesNotExist:
        return

    try:
        person = Person.objects.get_by_natural_key(invited_email)
    except Person.DoesNotExist:
        person = None

    group_name = group.name

    report_params = {"group_id": group_id, "inviter_id": inviter_id}
    report_params["token"] = abusive_invitation_report_token_generator.make_token(
        **report_params
    )
    report_url = front_url("report_invitation_abuse", query=report_params)

    if person:
        invitation_token = invitation_confirmation_token_generator.make_token(
            person_id=person.pk, group_id=group_id
        )

        join_url = front_url(
            "invitation_confirmation",
            query={
                "person_id": person.id,
                "group_id": group_id,
                "token": invitation_token,
            },
        )

        try:
            send_mosaico_email(
                code="GROUP_INVITATION_MESSAGE",
                subject="Vous avez été invité à rejoindre un groupe de la FI",
                from_email=settings.EMAIL_FROM,
                recipients=[person],
                bindings={
                    "GROUP_NAME": group_name,
                    "CONFIRMATION_URL": join_url,
                    "REPORT_URL": report_url,
                },
            )
        except (smtplib.SMTPException, socket.error) as exc:
            self.retry(countdown=60, exc=exc)

    else:
        invitation_token = subscription_confirmation_token_generator.make_token(
            email=invited_email, group_id=group_id
        )
        join_url = front_url(
            "invitation_with_subscription_confirmation",
            query={
                "email": invited_email,
                "group_id": group_id,
                "token": invitation_token,
            },
        )

        try:
            send_mosaico_email(
                code="GROUP_INVITATION_WITH_SUBSCRIPTION_MESSAGE",
                subject="Vous avez été invité à rejoindre la France insoumise",
                from_email=settings.EMAIL_FROM,
                recipients=[invited_email],
                bindings={
                    "GROUP_NAME": group_name,
                    "CONFIRMATION_URL": join_url,
                    "REPORT_URL": report_url,
                },
            )
        except (smtplib.SMTPException, socket.error) as exc:
            self.retry(countdown=60, exc=exc)