def _send_notification(subscriptions, expiry_days):
    site = Site.objects.get_current()
    if expiry_days == 30:
        subject = 'Action required: Your GGC subscription will expire in 1 month'
    elif expiry_days == 7:
        subject = 'Action required: Your GGC subscription will expire in 1 week'
    else:
        subject = 'Action required: Your GGC subscription has expired'

    for subscription in subscriptions:
        organisation = subscription.order.organisation
        users = subscription.order.organisation.user_set.all()
        end_date = subscription.end_date
        for user in users:
            if has_role(user, ['admin']):
                if expiry_days == 0:
                    renewal_message = "has expired"
                else:
                    renewal_message = "is due for renewal on {}".format(
                        datefilter(end_date))
                context = {
                    'site': site,
                    'site_domain': site.domain,
                    'site_name': site.name,
                    'email': user.email,
                    'organisation_name': organisation.legal_name,
                    'renewal_message': renewal_message,
                    'user_name': user.name
                }
                send(to=user.email,
                     subject=subject,
                     template_name='subscriptions/emails/order_renewal.txt',
                     context=context,
                     sender=settings.DEFAULT_SUBSCRIPTION_FROM_EMAIL)
Пример #2
0
def _send_notification(documents):
    site = Site.objects.get_current()
    subject = 'Action required - Document expiry notice.'
    for document in documents:
        users = User.objects.filter(organisation=document.organisation)
        for user in users:
            if has_role(user, ['admin', 'manager']):
                expires_in_days = relativedelta(document.expiry,
                                                date.today()).days
                if expires_in_days == 0:
                    expires_in_message = "today"
                else:
                    expires_in_message = "in {} days".format(expires_in_days)
                context = {
                    'site': site,
                    'site_domain': site.domain,
                    'site_name': site.name,
                    'email': user.email,
                    'document_expiry': document.expiry,
                    'document': document.name,
                    'organisation_name': user.organisation.legal_name,
                    'user_name': user.name,
                    'expires_in_message': expires_in_message,
                }
                send(
                    to=user.email,
                    subject=subject,
                    template_name='documents/document_expiry_email.txt',
                    context=context,
                )
    def send_invites_unregistered(self,
                                  token_generator=default_token_generator):
        site = Site.objects.get_current()
        subject = 'Invitation to submit assessment'
        invitation = self
        grantor_name = self.grantor.legal_name
        token = signing.dumps(invitation.id)

        context = {
            'site': site,
            'email': self.grantee_email,
            'user_email': invitation.grantee_email,
            'new_user': True,
            'token': token,
            'site_domain': site.domain,
            'site_name': site.name,
            'survey_level': get_level_name(self.level),
            'survey_name': self.survey.name,
            'grantor_name': grantor_name
        }

        send(
            to=invitation.grantee_email,
            subject=subject,
            template_name='surveys/emails/userinvite.txt',
            context=context,
        )
Пример #4
0
    def send_validation_email(self):
        """
        Send a validation email to the user's email address.

        The email subject can be customised by overriding
        VerifyEmailMixin.EMAIL_SUBJECT or VerifyEmailMixin.get_email_subject.
        To include your site's domain in the subject, include {domain} in
        VerifyEmailMixin.EMAIL_SUBJECT.

        By default send_validation_email sends a multipart email using
        VerifyEmailMixin.TEXT_EMAIL_TEMPLATE and
        VerifyEmailMixin.HTML_EMAIL_TEMPLATE. To send a text-only email
        set VerifyEmailMixin.HTML_EMAIL_TEMPLATE to None.

        You can also customise the context available in the email templates
        by extending VerifyEmailMixin.email_context.

        If you want more control over the sending of the email you can
        extend VerifyEmailMixin.email_kwargs.
        """
        if not self.email_verification_required:
            raise ValueError(_('Cannot validate already active user.'))

        site = Site.objects.get_current()
        context = self.email_context(site)
        send(**self.email_kwargs(context, site.domain))
Пример #5
0
    def send_and_assert_email(self, html_template_name=()):
        """Runs send() on proper input and checks the result."""
        kwargs = {
            'sender': ['*****@*****.**'],
            'to': ['*****@*****.**'],
            'cc': ['*****@*****.**'],
            'bcc': ['*****@*****.**'],
            'subject': 'Test email',
            'template_name': 'dummy_template.html',
            'html_template_name': html_template_name,
        }

        incuna_mail.send(**kwargs)

        # Assert that the email exists and has the correct parameters
        self.assertEqual(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertEqual(email.to, kwargs['to'])
        self.assertEqual(email.from_email, kwargs['sender'])
        self.assertEqual(email.cc, kwargs['cc'])
        self.assertEqual(email.bcc, kwargs['bcc'])
        self.assertEqual(email.subject, kwargs['subject'])

        return email
Пример #6
0
    def send_and_assert_email(self, html_template_name=None):
        """Runs send() on proper input and checks the result."""
        kwargs = {
            'sender': ['*****@*****.**'],
            'to': ['*****@*****.**'],
            'cc': ['*****@*****.**'],
            'bcc': ['*****@*****.**'],
            'subject': 'Test email',
            'template_name': 'dummy_template.html',
            'reply_to': ['*****@*****.**'],
            'html_template_name': html_template_name,
        }

        incuna_mail.send(**kwargs)

        # Assert that the email exists and has the correct parameters
        self.assertEqual(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertEqual(email.to, kwargs['to'])
        self.assertEqual(email.from_email, kwargs['sender'])
        self.assertEqual(email.cc, kwargs['cc'])
        self.assertEqual(email.bcc, kwargs['bcc'])
        self.assertEqual(email.subject, kwargs['subject'])
        self.assertEqual(email.reply_to, kwargs['reply_to'])

        return email
    def send_invites(self, token_generator=default_token_generator):
        users = User.objects.filter(organisation=self.grantee)
        site = Site.objects.get_current()
        subject = 'Invitation to submit assessment'

        grantor_name = self.grantor.legal_name

        for user in users:
            if has_role(user, ['admin', 'manager']):
                context = {
                    'user_name': user.name,
                    'survey_level': get_level_name(self.level),
                    'survey_name': self.survey.name,
                    'grantor_name': grantor_name,
                    'email': user.email,
                    'site_domain': site.domain,
                    'survey_url': '',
                    'site_name': site.name,
                }
                send(
                    to=user.email,
                    subject=subject,
                    template_name='surveys/emails/invitation.txt',
                    context=context,
                )
Пример #8
0
    def send_validation_email(self):
        """
        Send a validation email to the user's email address.

        The email subject can be customised by overriding
        VerifyEmailMixin.EMAIL_SUBJECT or VerifyEmailMixin.get_email_subject.
        To include your site's domain in the subject, include {domain} in
        VerifyEmailMixin.EMAIL_SUBJECT.

        By default send_validation_email sends a multipart email using
        VerifyEmailMixin.TEXT_EMAIL_TEMPLATE and
        VerifyEmailMixin.HTML_EMAIL_TEMPLATE. To send a text-only email
        set VerifyEmailMixin.HTML_EMAIL_TEMPLATE to None.

        You can also customise the context available in the email templates
        by extending VerifyEmailMixin.email_context.

        If you want more control over the sending of the email you can
        extend VerifyEmailMixin.email_kwargs.
        """
        if not self.email_verification_required:
            raise ValueError(_('Cannot validate already active user.'))

        site = Site.objects.get_current()
        context = self.email_context(site)
        send(**self.email_kwargs(context, site.domain))
Пример #9
0
 def send_email(self, user):
     site = Site.objects.get_current()
     send(
         to=[user.email],
         template_name=self.template_name,
         subject=_('{domain} password reset').format(domain=site.domain),
         context=self.email_context(site, user),
     )
Пример #10
0
 def send_email(self, user):
     site = Site.objects.get_current()
     send(
         to=[user.email],
         template_name=self.template_name,
         subject=_('{domain} password reset').format(domain=site.domain),
         context=self.email_context(site, user),
     )
Пример #11
0
 def test_default_email(self):
     with self.settings(DEFAULT_FROM_EMAIL='*****@*****.**'):
         incuna_mail.send(
             to='*****@*****.**',
             template_name='dummy_template.html',
         )
     email = mail.outbox[0]
     self.assertEqual(email.from_email, '*****@*****.**')
Пример #12
0
 def email_login_url(self, url):
     """Email the given URL to the User."""
     send(
         to=self.email,
         subject="Log into PHMI",
         template_name="emails/login.txt",
         context={"login_url": url},
     )
def email_handler(notification, email_context):
    """Send a notification by email."""
    incuna_mail.send(
        to=notification.user.email,
        subject=notification.email_subject,
        template_name=notification.text_email_template,
        html_template_name=notification.html_email_template,
        context=email_context(notification),
    )
Пример #14
0
def email_handler(notification, email_context):
    """Send a notification by email."""
    incuna_mail.send(
        to=notification.user.email,
        subject=notification.email_subject,
        template_name=notification.text_email_template,
        html_template_name=notification.html_email_template,
        context=email_context(notification),
        headers=getattr(notification, 'headers', {}),
    )
Пример #15
0
def send_submitted_application_email(email, application):
    f = furl(settings.BASE_URL)
    f.path = application.get_absolute_url()

    context = {
        "url": f.url,
    }

    send(
        to=email,
        sender="*****@*****.**",
        subject="Thank you for applying to use OpenSAFELY",
        template_name="applications/emails/submission_confirmation.txt",
        context=context,
    )
Пример #16
0
def send_project_invite_email(email, project, invite):
    f = furl(settings.BASE_URL)
    f.path = invite.get_invitation_url()

    context = {
        "inviter_name": invite.created_by.name,
        "project_name": project.name,
        "url": f.url,
    }

    send(
        to=email,
        sender="*****@*****.**",
        subject=
        f"OpenSAFELY Project Invite from {invite.created_by.name} to {project.name}",
        template_name="emails/project_invite.txt",
        context=context,
    )
Пример #17
0
def send_finished_notification(email, job):
    f = furl(settings.BASE_URL)
    f.path = job.get_absolute_url()

    workspace_name = job.job_request.workspace.name

    context = {
        "action": job.action,
        "elapsed_time": job.runtime.total_seconds if job.runtime else None,
        "status": job.status,
        "status_message": job.status_message,
        "url": f.url,
        "workspace": workspace_name,
    }

    send(
        to=email,
        sender="*****@*****.**",
        subject=f"[os {workspace_name}] {job.action} {job.status}",
        template_name="emails/notify_finished.txt",
        context=context,
    )
Пример #18
0
    def _send_order_email(self, subject, template_name):
        users = User.objects.filter(organisation=self.organisation)
        site = Site.objects.get_current()
        order_number = '{:07d}'.format(self.pk)
        organisation_name = self.organisation.legal_name
        order_items, order_total = self.get_order_details()
        for user in users:
            if has_role(user, ['admin']):
                context = {
                    'site': site,
                    'site_domain': site.domain,
                    'site_name': site.name,
                    'organisation_name': organisation_name,
                    'order_items': order_items,
                    'order_total': '{0:.2f}'.format(order_total),
                    'order_number': order_number,
                    'user_name': user.name
                }

                send(to=user.email,
                     subject=subject,
                     template_name=template_name,
                     context=context,
                     sender=settings.DEFAULT_SUBSCRIPTION_FROM_EMAIL)
    def send_welcome_invite(self, token_generator=default_token_generator):
        site = Site.objects.get_current()
        subject = 'Welcome to the Global Grant Community'
        user = self
        user_role = get_user_roles(user)[0].get_name()

        context = {
            'site': site,
            'email': user.email,
            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
            'token': default_token_generator.make_token(user),
            'site_domain': site.domain,
            'site_name': site.name,
            'organisation_name': self.organisation.legal_name,
            'user_name': user.name,
            'user_role': user_role.title()
        }

        send(
            to=user.email,
            subject=subject,
            template_name='organization/welcome_user.txt',
            context=context,
        )
Пример #20
0
 def test_do_not_send_empty_email(self):
     """Regression test to assert empty email can't be send."""
     with self.assertRaises(TypeError):
         incuna_mail.send()