lirmm / waves-core

WAVES is a reusable web application dedicated to bioinformatic tool integration

Home Page:https://waves-core.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Admin and User email notifications fof Errors both go to the same email address

bockp opened this issue · comments

When a service fails, the error messages for the admin and the user both go to the same email address.

Depending on if the "email me results" field was left blank (both go to the Admin) or the user entered their email (both go to the User).

I've gone as far as the waves/wcore/mails.py script to try and track the problem, and it seems that these two functions :

def send_job_error_email(self, job):

        """
        Send Job error email

        :return: the number of mail sent, should be 0 or 1
        :rtype: int
        """
        return self._send_job_mail(job, "waves/emails/job_error.tpl")

def send_job_admin_error(self, job):
        """ Admin mail to notify run error
        :return: the number of mail sent, should be 0 or 1
        :rtype: int
        """
        return self._send_job_mail(job, "waves/emails/job_admin_error.tpl")

both call upon _send_job_mail, with the same arguments.

def _send_job_mail(self, job, template, subject=None):
        """ Check if send mail is needed, in such case, create a template email and... send it to specified client

        :return: the number of mail sent, should be 0 or 1
        :rtype: int
        """
        if self.mail_activated and job.notify:
            context = self.get_context_data()
            context['job'] = job
            mail_subject = "[WAVES - %s] -- %s -- " % (
                job.title, job.get_status_display()) if subject is None else subject
            try:
                message = get_template(template_name=template).render(context)
                msg = EmailMessage(subject=mail_subject, body=message, to=[job.email_to],
                                   from_email=config.SERVICES_EMAIL)
                msg.send(fail_silently=True)
                job.job_history.create(message='Notification email sent', status=job.status, is_admin=True)
            except Exception as e:
                job.job_history.create(message='Notification email not sent %s' % e.message, status=job.status,
                                       is_admin=True)
                logger.exception("Failed to send mail to %s from %s :%s", job.email_to, config.SERVICES_EMAIL, e)
        else:
            logger.info('Mail not sent to %s, mails are not activated', job.email_to)
            return 0

To me it seems like to=[job.email_to] will either be the user's email if set, or the service email if not set, no matter if it's called by send_job_admin_error or send_job_error_email.

Am I missing something or is there an override missing to force to=[job.email_to] to be to=[config.ADMIN_EMAIL] when the error message is directed at the Administrator ?

Thank you for pointing this. Will correct this soon.

fixed in 1.6.7