示例#1
0
def send_suggestion_approved_email(journal_name, email):
    url_root = request.url_root
    if url_root.endswith("/"):
        url_root = url_root[:-1]

    to = [email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - journal accepted"

    try:
        if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/suggestion_accepted.txt",
                                journal_name=journal_name.encode('utf-8', 'replace'),
                                url_root=url_root
            )
            flash('Sent email to ' + email + ' to tell them about their journal getting accepted into DOAJ.', 'success')
        else:
            flash('Did not send email to ' + email + ' to tell them about their journal getting accepted into DOAJ, as publisher emails are disabled.', 'error')
    except Exception as e:
        magic = str(uuid.uuid1())
        util.flash_with_url('Hm, sending the journal acceptance information email didn\'t work. Please quote this magic number when reporting the issue: ' + magic + ' . Thank you!', 'error')
        app.logger.error(magic + "\n" + repr(e))
        raise e
示例#2
0
def send_editor_completed_email(application):
    """ inform the editor in charge of an application that it has been completed by an associate editor """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(
        ' ', '')  # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions",
                                             source=string_id_query)

    # This is to the editor in charge of this application's assigned editor group
    editor_group_name = application.editor_group
    editor_group_id = models.EditorGroup.group_exists_by_name(
        name=editor_group_name)
    editor_group = models.EditorGroup.pull(editor_group_id)
    editor_acc = editor_group.get_editor_account()

    editor_id = editor_acc.id
    to = [editor_acc.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME",
                             "") + " - application marked 'completed'"

    # The status change will have come from the associate editor assigned to the journal
    assoc_id = application.editor

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/editor_application_completed.txt",
                        editor=editor_id,
                        associate_editor=assoc_id,
                        application_title=journal_name,
                        url_for_application=url_for_application)
示例#3
0
文件: contact.py 项目: jbarnsby/doaj
def mailer():
    if request.method == 'POST':
        try:
            if request.values.get('message',False) and not request.values.get('not',False):
                util.send_mail(
                    [app.config['ADMIN_NAME'] + ' <' + app.config['ADMIN_EMAIL'] + '>'],
                    request.values.get('email',app.config['ADMIN_NAME'] + ' <' + app.config['ADMIN_EMAIL'] + '>'),
                    'website enquiry',
                    request.values['message']
                )
                app_email.send_mail(to=[app.config['ADMIN_NAME'] + ' <' + app.config['ADMIN_EMAIL'] + '>'],
                                    fro=request.values.get('email',app.config['ADMIN_NAME'] + ' <' + app.config['ADMIN_EMAIL'] + '>'),
                                    subject='website enquiry',
                                    template_name=None,
                                    msg_body=request.values['message']
                                    )
                flash('Thank you very much for you enquiry. We will get back to you as soon as possible.', 'success')
            else:
                flash('Sorry. Your message could not be delivered. Please try again.', 'error')
        except:
            if app.config.get('DEBUG',False):
                flash('Sorry, Your message failed. Probably because debug.', 'error')
            else:
                flash('Sorry. Your message failed. Please try again', 'error')

    return render_template('contact/index.html') 
示例#4
0
def send_publisher_update_request_revisions_required(application):
    """Tell the publisher their update request requires revisions"""
    journal_title = application.bibjson().title

    owner = models.Account.pull(application.owner)
    if owner is None:
        raise app_email.EmailException(
            "Application {x} does not have an owner, cannot send email".format(
                x=application.id))

    # This is to the publisher contact on the application
    publisher_name = owner.name
    publisher_email = owner.email

    to = [publisher_email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME",
                             "") + " - your update request requires revisions"

    app_email.send_mail(
        to=to,
        fro=fro,
        subject=subject,
        template_name="email/publisher_update_request_revisions.txt",
        publisher_name=publisher_name,
        journal_title=journal_title)
示例#5
0
def send_editor_group_email(obj):
    """ Send an email to the editor of a group """
    if type(obj) is models.Suggestion:
        template = "email/editor_application_assigned_group.txt"
        subject = app.config.get(
            "SERVICE_NAME", "") + " - new application assigned to your group"
    elif type(obj) is models.Journal:
        template = "email/editor_journal_assigned_group.txt"
        subject = app.config.get("SERVICE_NAME",
                                 "") + " - new journal assigned to your group"
    else:
        app.logger.error(
            "Attempted to send editor group email for something that's not an Application or Journal"
        )
        return
    eg = models.EditorGroup.pull_by_key("name", obj.editor_group)
    if eg is None:
        return
    editor = eg.get_editor_account()

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name=template,
                        editor=editor.id,
                        journal_name=obj.bibjson().title,
                        url_root=url_root)
示例#6
0
def send_assoc_editor_email(obj):
    """ Inform an associate editor that a journal or application has been assigned to them """
    if type(obj) is models.Suggestion:
        template = "email/assoc_editor_application_assigned.txt"
        subject = app.config.get("SERVICE_NAME",
                                 "") + " - new application assigned to you"
    elif type(obj) is models.Journal:
        template = "email/assoc_editor_journal_assigned.txt"
        subject = app.config.get("SERVICE_NAME",
                                 "") + " - new journal assigned to you"
    else:
        app.logger.error(
            "Attempted to send email to editors for something that's not an Application or Journal"
        )
        return

    assoc_editor = models.Account.pull(obj.editor)
    eg = models.EditorGroup.pull_by_key("name", obj.editor_group)

    url_root = app.config.get("BASE_URL")
    to = [assoc_editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name=template,
                        associate_editor=assoc_editor.id,
                        journal_name=obj.bibjson().title,
                        group_name=eg.name,
                        url_root=url_root)
示例#7
0
文件: emails.py 项目: DOAJ/doaj
def send_assoc_editor_email(obj):
    """ Inform an associate editor that a journal or application has been assigned to them """
    if type(obj) is models.Suggestion:
        template = "email/assoc_editor_application_assigned.txt"
        subject = app.config.get("SERVICE_NAME", "") + " - new application assigned to you"
    elif type(obj) is models.Journal:
        template = "email/assoc_editor_journal_assigned.txt"
        subject = app.config.get("SERVICE_NAME", "") + " - new journal assigned to you"
    else:
        app.logger.error("Attempted to send email to editors for something that's not an Application or Journal")
        return

    assoc_editor = models.Account.pull(obj.editor)
    eg = models.EditorGroup.pull_by_key("name", obj.editor_group)

    url_root = app.config.get("BASE_URL")
    to = [assoc_editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name=template,
                        associate_editor=assoc_editor.id,
                        journal_name=obj.bibjson().title,
                        group_name=eg.name,
                        url_root=url_root)
示例#8
0
文件: emails.py 项目: DOAJ/doaj
def send_editor_group_email(obj):
    """ Send an email to the editor of a group """
    if type(obj) is models.Suggestion:
        template = "email/editor_application_assigned_group.txt"
        subject = app.config.get("SERVICE_NAME", "") + " - new application assigned to your group"
    elif type(obj) is models.Journal:
        template = "email/editor_journal_assigned_group.txt"
        subject = app.config.get("SERVICE_NAME", "") + " - new journal assigned to your group"
    else:
        app.logger.error("Attempted to send editor group email for something that's not an Application or Journal")
        return
    eg = models.EditorGroup.pull_by_key("name", obj.editor_group)
    if eg is None:
        return
    editor = eg.get_editor_account()

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name=template,
                        editor=editor.id,
                        journal_name=obj.bibjson().title,
                        url_root=url_root)
示例#9
0
    def run(self):
        """
        Execute the task as specified by the background_job
        :return:
        """

        # Connection to the ES index
        conn = Connection(app.config.get("ELASTIC_SEARCH_HOST"), index='_snapshot')

        try:
            client = ESSnapshotsClient(conn, app.config['ELASTIC_SEARCH_SNAPSHOT_REPOSITORY'])
            resp = client.request_snapshot()
            if resp.status_code == 200:
                job = self.background_job
                job.add_audit_message("ElasticSearch backup requested. Response: " + resp.text)
            else:
                raise Exception("Status code {0} received from snapshots plugin.".format(resp.text))

        except Exception as e:
            app_email.send_mail(
                to=[app.config.get('ADMIN_EMAIL', '*****@*****.**')],
                fro=app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**'),
                subject='Alert: DOAJ ElasticSearch backup failure',
                msg_body="The ElasticSearch snapshot could not requested. Error: \n" + e.message
            )
            raise e
示例#10
0
def send_publisher_update_request_editor_assigned_email(application):
    """ Send email to publisher informing them an editor has been assigned """

    owner = models.Account.pull(application.owner)
    send_list = [{
        "name": owner.name,
        "email": owner.email,
        "sent_alert": Messages.SENT_PUBLISHER_ASSIGNED_EMAIL,
        "not_sent_alert": Messages.NOT_SENT_PUBLISHER_ASSIGNED_EMAIL
    }]

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get(
        "SERVICE_NAME",
        "") + " - your update request has been assigned an editor for review"

    alerts = []
    for instructions in send_list:
        to = [instructions["email"]]
        try:
            app_email.send_mail(
                to=to,
                fro=fro,
                subject=subject,
                template_name=
                "email/publisher_update_request_editor_assigned.txt",
                application_title=application.bibjson().title,
                publisher_name=instructions["name"])
            alerts.append(instructions["sent_alert"])
        except app_email.EmailException:
            alerts.append(instructions["not_sent_alert"])

    return alerts
示例#11
0
文件: emails.py 项目: DOAJ/doaj
def send_editor_completed_email(application):
    """ inform the editor in charge of an application that it has been completed by an associate editor """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(' ', '')       # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions", source=string_id_query)

    # This is to the editor in charge of this application's assigned editor group
    editor_group_name = application.editor_group
    editor_group_id = models.EditorGroup.group_exists_by_name(name=editor_group_name)
    editor_group = models.EditorGroup.pull(editor_group_id)
    editor_acc = editor_group.get_editor_account()

    editor_id = editor_acc.id
    to = [editor_acc.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - application marked 'completed'"

    # The status change will have come from the associate editor assigned to the journal
    assoc_id = application.editor

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/editor_application_completed.txt",
                        editor=editor_id,
                        associate_editor=assoc_id,
                        application_title=journal_name,
                        url_for_application=url_for_application)
示例#12
0
    def email_error(report):
        to = [account.email]
        fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
        subject = app.config.get(
            "SERVICE_NAME", "") + " - problems with your bulk reapplication"

        try:
            if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
                now = datetime.now().strftime("%Y%m%d")
                att = app_email.make_attachment(
                    "reapplication_errors_" + now + ".csv", "text/plain",
                    report)  # NOTE: file extension is now csv
                when = datetime.strptime(
                    upload.created_date,
                    "%Y-%m-%dT%H:%M:%SZ").strftime("%d %b %Y")
                app_email.send_mail(to=to,
                                    fro=fro,
                                    subject=subject,
                                    template_name="email/bulk_reapp_error.txt",
                                    files=[att],
                                    when=when,
                                    account=account)
        except Exception as e:
            magic = str(uuid.uuid1())
            app.logger.error(magic + "\n" + repr(e))
            raise e
示例#13
0
文件: emails.py 项目: DOAJ/doaj
def send_editor_inprogress_email(application):
    """ Inform editor in charge of an application that the status is has been reverted from ready by a ManEd """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(' ', '')       # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions", source=string_id_query)

    # This is to the editor in charge of this AssEd's group
    editor_group_name = application.editor_group
    editor_group_id = models.EditorGroup.group_exists_by_name(name=editor_group_name)

    try:
        editor_group = models.EditorGroup.pull(editor_group_id)
        editor_acc = editor_group.get_editor_account()
        editor_id = editor_acc.id
        to = [editor_acc.email]
    except AttributeError:
        raise

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - Application reverted to 'In Progress' by Managing Editor"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/editor_application_inprogress.txt",
                        editor=editor_id,
                        application_title=journal_name,
                        url_for_application=url_for_application)
示例#14
0
def send_assoc_editor_inprogress_email(application):
    """ Inform the associate editor assigned to application that the status has been reverted by an Ed or ManEd """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(
        ' ', '')  # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions",
                                             source=string_id_query)

    # This is to the associate editor assigned to this application
    assoc_editor = models.Account.pull(application.editor)
    to = [assoc_editor.email]

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get(
        "SERVICE_NAME",
        "") + " - an application assigned to you has not passed review."

    app_email.send_mail(
        to=to,
        fro=fro,
        subject=subject,
        template_name="email/assoc_editor_application_inprogress.txt",
        assoc_editor=assoc_editor.id,
        application_title=journal_name,
        url_for_application=url_for_application)
示例#15
0
def send_emails(emails_dict):

    for (email, (to_name, paragraphs)) in emails_dict.iteritems():
        pre = 'Dear ' + to_name + ',\n\n'
        post = '\n\nThe DOAJ Team\n\n***\nThis is an automated message. Please do not reply to this email.'
        full_body = pre + '\n\n'.join(paragraphs) + post

        app_email.send_mail(to=[email],
                            fro=app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**'),
                            subject="DOAJ editorial reminders",
                            msg_body=full_body)
示例#16
0
文件: emails.py 项目: DOAJ/doaj
def send_publisher_reject_email(application, note=None, update_request=False, send_to_owner=True, send_to_suggester=False):
    """Tell the publisher their application was rejected"""
    journal_title = application.bibjson().title

    send_instructions = []
    if send_to_owner:
        owner = models.Account.pull(application.owner)
        if owner is not None:
            send_instructions.append({
                "name" : owner.name,
                "email" : owner.email,
                "type" : "owner"
            })

    if send_to_suggester:
        sug = application.suggester
        if sug is not None:
            send_instructions.append({
                "name" : sug["name"],
                "email" : sug["email"],
                "type" : "suggester"
            })

    if len(send_instructions) == 0:
        raise app_email.EmailException("Application {x} does not have an owner or suggester, cannot send email".format(x=application.id))

    # determine if this is an application or an update request
    app_type = "application" if update_request is False else "update"

    for instructions in send_instructions:
        to = [instructions["email"]]
        fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
        subject = app.config.get("SERVICE_NAME", "") + " - your " + app_type + " was rejected"

        if update_request:
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/publisher_update_request_rejected.txt",
                                publisher_name=instructions["name"],
                                journal_title=journal_title,
                                note=note)
        else:
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/publisher_application_rejected.txt",
                                publisher_name=instructions["name"],
                                journal_title=journal_title,
                                note=note)

    return send_instructions
示例#17
0
def forgot():
    CONTACT_INSTR = ' Please <a href="{url}">contact us.</a>'.format(url=url_for('doaj.contact'))
    if request.method == 'POST':
        # get hold of the user account
        un = request.form.get('un', "")
        account = models.Account.pull(un)
        if account is None:
            account = models.Account.pull_by_email(un)
        if account is None:
            util.flash_with_url('Hm, sorry, your account username / email address is not recognised.' + CONTACT_INSTR, 'error')
            return render_template('account/forgot.html')

        if not account.data.get('email'):
            util.flash_with_url('Hm, sorry, your account does not have an associated email address.' + CONTACT_INSTR, 'error')
            return render_template('account/forgot.html')

        # if we get to here, we have a user account to reset
        #newpass = util.generate_password()
        #account.set_password(newpass)
        reset_token = uuid.uuid4().hex
        account.set_reset_token(reset_token, app.config.get("PASSWORD_RESET_TIMEOUT", 86400))
        account.save()

        sep = "/"
        if request.url_root.endswith("/"):
            sep = ""
        reset_url = request.url_root + sep + "account/reset/" + reset_token

        to = [account.data['email']]
        fro = app.config.get('SYSTEM_EMAIL_FROM', app.config['ADMIN_EMAIL'])
        subject = app.config.get("SERVICE_NAME", "") + " - password reset"
        try:
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/password_reset.txt",
                                account_id=account.id,
                                reset_url=reset_url,
                                )
            flash('Instructions to reset your password have been sent to you. Please check your emails.')
            if app.config.get('DEBUG', False):
                flash('Debug mode - url for reset is ' + reset_url)
        except Exception as e:
            magic = str(uuid.uuid1())
            util.flash_with_url('Hm, sorry - sending the password reset email didn\'t work.' + CONTACT_INSTR + ' It would help us if you also quote this magic number: ' + magic + ' . Thank you!', 'error')
            if app.config.get('DEBUG', False):
                flash('Debug mode - url for reset is ' + reset_url)
            app.logger.error(magic + "\n" + repr(e))

    return render_template('account/forgot.html')
示例#18
0
文件: account.py 项目: jbarnsby/doaj
def forgot():
    CONTACT_INSTR = ' Please <a href="{url}">contact us.</a>'.format(url=url_for('doaj.contact'))
    if request.method == 'POST':
        # get hold of the user account
        un = request.form.get('un',"")
        account = models.Account.pull(un)
        if account is None: 
            account = models.Account.pull_by_email(un)
        if account is None:
            util.flash_with_url('Hm, sorry, your account username / email address is not recognised.' + CONTACT_INSTR, 'error')
            return render_template('account/forgot.html')
        
        if not account.data.get('email'):
            util.flash_with_url('Hm, sorry, your account does not have an associated email address.' + CONTACT_INSTR, 'error')
            return render_template('account/forgot.html')

        # if we get to here, we have a user account to reset
        #newpass = util.generate_password()
        #account.set_password(newpass)
        reset_token = uuid.uuid4().hex
        account.set_reset_token(reset_token, app.config.get("PASSWORD_RESET_TIMEOUT", 86400))
        account.save()
        
        sep = "/"
        if request.url_root.endswith("/"):
            sep = ""
        reset_url = request.url_root + sep + "account/reset/" + reset_token

        to = [account.data['email']]
        fro = app.config.get('SYSTEM_EMAIL_FROM', app.config['ADMIN_EMAIL'])
        subject = app.config.get("SERVICE_NAME","") + " - password reset"
        try:
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/password_reset.txt",
                                account_id=account.id,
                                reset_url=reset_url,
                                )
            flash('Instructions to reset your password have been sent to you. Please check your emails.')
            if app.config.get('DEBUG',False):
                flash('Debug mode - url for reset is ' + reset_url)
        except Exception as e:
            magic = str(uuid.uuid1())
            util.flash_with_url('Hm, sorry - sending the password reset email didn\'t work.' + CONTACT_INSTR + ' It would help us if you also quote this magic number: ' + magic + ' . Thank you!', 'error')
            if app.config.get('DEBUG',False):
                flash('Debug mode - url for reset is ' + reset_url)
            app.logger.error(magic + "\n" + repr(e))

    return render_template('account/forgot.html')
示例#19
0
def send_publisher_application_inprogress_email(application):
    """Tell the publisher the application is underway"""
    journal_title = application.bibjson().title

    contact_name = application.get_latest_contact_name()
    contact_email = application.get_latest_contact_email()
    send_list = [{
        "name":
        contact_name,
        "email":
        contact_email,
        "sent_alert":
        Messages.SENT_JOURNAL_CONTACT_IN_PROGRESS_EMAIL,
        "not_sent_alert":
        Messages.NOT_SENT_JOURNAL_CONTACT_IN_PROGRESS_EMAIL
    }]

    owner = models.Account.pull(application.owner)
    if owner is not None:
        send_list.append({
            "name":
            owner.name,
            "email":
            owner.email,
            "sent_alert":
            Messages.SENT_PUBLISHER_IN_PROGRESS_EMAIL,
            "not_sent_alert":
            Messages.NOT_SENT_PUBLISHER_IN_PROGRESS_EMAIL
        })

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME",
                             "") + " - your application is under review"

    alerts = []
    for instructions in send_list:
        to = [instructions["email"]]
        try:
            app_email.send_mail(
                to=to,
                fro=fro,
                subject=subject,
                template_name="email/publisher_application_inprogress.txt",
                publisher_name=instructions["name"],
                journal_title=journal_title)
            alerts.append(instructions["sent_alert"])
        except app_email.EmailException:
            alerts.append(instructions["not_sent_alert"])

    return alerts
示例#20
0
文件: emails.py 项目: DOAJ/doaj
def send_received_email(application):
    """ Email the publisher when an application is received """
    suggester = application.suggester

    to = [suggester.get("email")]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - your application to DOAJ has been received"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/publisher_application_received.txt",
                        publisher_name=suggester.get("name", "Applicant"),
                        title=application.bibjson().title,
                        url=application.bibjson().get_single_url(urltype="homepage"))
示例#21
0
def email_csv_complete(account):
    to = [account.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - bulk reapplication processed"

    try:
        if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/bulk_reapp_complete.txt",
                                account=account
            )
    except Exception as e:
        magic = str(uuid.uuid1())
        app.logger.error(magic + "\n" + repr(e))
        raise e
示例#22
0
def send_received_email(application):
    """ Email the publisher when an application is received """
    suggester = application.suggester

    to = [suggester.get("email")]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get(
        "SERVICE_NAME", "") + " - your application to DOAJ has been received"

    app_email.send_mail(
        to=to,
        fro=fro,
        subject=subject,
        template_name="email/publisher_application_received.txt",
        publisher_name=suggester.get("name", "Applicant"),
        title=application.bibjson().title,
        url=application.bibjson().get_single_url(urltype="homepage"))
示例#23
0
def email_csv_complete(account):
    to = [account.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME",
                             "") + " - bulk reapplication processed"

    try:
        if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/bulk_reapp_complete.txt",
                                account=account)
    except Exception as e:
        magic = str(uuid.uuid1())
        app.logger.error(magic + "\n" + repr(e))
        raise e
示例#24
0
def send_editor_email(suggestion):
    editor = models.Account.pull(suggestion.editor)
    eg = models.EditorGroup.pull_by_key("name", suggestion.editor_group)

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - new journal assigned to you"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/suggestion_assigned_editor.txt",
                        editor=editor.id.encode('utf-8', 'replace'),
                        journal_name=suggestion.bibjson().title.encode('utf-8', 'replace'),
                        group_name=eg.name.encode("utf-8", "replace"),
                        url_root=url_root
                        )
示例#25
0
 def email_error():
     to = [account.email]
     fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
     subject = app.config.get("SERVICE_NAME","") + " - problems with your bulk reapplication"
     when = datetime.strptime(upload.created_date, "%Y-%m-%dT%H:%M:%SZ").strftime("%d %b %Y")
     try:
         if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
             app_email.send_mail(to=to,
                                 fro=fro,
                                 subject=subject,
                                 template_name="email/bulk_reapp_file_error.txt",
                                 when=when,
                                 account=account
             )
     except Exception as e:
         magic = str(uuid.uuid1())
         app.logger.error(magic + "\n" + repr(e))
         raise e
示例#26
0
文件: journal.py 项目: jbarnsby/doaj
def send_editor_email(journal):
    editor = Account.pull(journal.editor)
    eg = EditorGroup.pull_by_key("name", journal.editor_group)

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - new journal assigned to you"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/journal_assigned_editor.txt",
                        editor=editor.id.encode('utf-8', 'replace'),
                        journal_name=journal.bibjson().title.encode('utf-8', 'replace'),
                        group_name=eg.name.encode("utf-8", "replace"),
                        url_root=url_root
                        )
示例#27
0
文件: emails.py 项目: DOAJ/doaj
def send_publisher_inprogress_email(application):
    """Tell the publisher the application is underway"""
    journal_title = application.bibjson().title

    contact_name = application.get_latest_contact_name()
    contact_email = application.get_latest_contact_email()
    send_list = [
        {
            "name" : contact_name,
            "email" : contact_email,
            "sent_alert" : Messages.SENT_JOURNAL_CONTACT_IN_PROGRESS_EMAIL,
            "not_sent_alert" : Messages.NOT_SENT_JOURNAL_CONTACT_IN_PROGRESS_EMAIL
        }
    ]

    owner = models.Account.pull(application.owner)
    if owner is not None:
        send_list.append(
            {
                "name" : owner.name,
                "email" : owner.email,
                "sent_alert" : Messages.SENT_PUBLISHER_IN_PROGRESS_EMAIL,
                "not_sent_alert" : Messages.NOT_SENT_PUBLISHER_IN_PROGRESS_EMAIL
            }
        )

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - your application is under review"

    alerts = []
    for instructions in send_list:
        to = [instructions["email"]]
        try:
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/publisher_application_inprogress.txt",
                                publisher_name=instructions["name"],
                                journal_title=journal_title)
            alerts.append(instructions["sent_alert"])
        except app_email.EmailException:
            alerts.append(instructions["not_sent_alert"])

    return alerts
示例#28
0
def send_editor_group_email(suggestion):
    eg = models.EditorGroup.pull_by_key("name", suggestion.editor_group)
    if eg is None:
        return
    editor = models.Account.pull(eg.editor)

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - new journal assigned to your group"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/suggestion_assigned_group.txt",
                        editor=editor.id.encode('utf-8', 'replace'),
                        journal_name=suggestion.bibjson().title.encode('utf-8', 'replace'),
                        url_root=url_root
                        )
示例#29
0
文件: emails.py 项目: DOAJ/doaj
def send_publisher_editor_assigned_email(application):
    """ Send email to publisher informing them an editor has been assigned """

    contact_name = application.get_latest_contact_name()
    contact_email = application.get_latest_contact_email()
    send_list = [
        {
            "name" : contact_name,
            "email" : contact_email,
            "sent_alert" : Messages.SENT_JOURNAL_CONTACT_ASSIGNED_EMAIL,
            "not_sent_alert" : Messages.NOT_SENT_JOURNAL_CONTACT_ASSIGNED_EMAIL
        }
    ]

    owner = models.Account.pull(application.owner)
    if owner is not None:
        send_list.append(
            {
                "name" : owner.name,
                "email" : owner.email,
                "sent_alert" : Messages.SENT_PUBLISHER_ASSIGNED_EMAIL,
                "not_sent_alert" : Messages.NOT_SENT_PUBLISHER_ASSIGNED_EMAIL
            }
        )

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - your application has been assigned an editor for review"

    alerts = []
    for instructions in send_list:
        to = [instructions["email"]]
        try:
            app_email.send_mail(to=to,
                            fro=fro,
                            subject=subject,
                            template_name="email/publisher_application_editor_assigned.txt",
                            application_title=application.bibjson().title,
                            publisher_name=instructions["name"])
            alerts.append(instructions["sent_alert"])
        except app_email.EmailException:
            alerts.append(instructions["not_sent_alert"])

    return alerts
示例#30
0
 def email_error():
     to = [account.email]
     fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
     subject = app.config.get(
         "SERVICE_NAME", "") + " - problems with your bulk reapplication"
     when = datetime.strptime(upload.created_date,
                              "%Y-%m-%dT%H:%M:%SZ").strftime("%d %b %Y")
     try:
         if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
             app_email.send_mail(
                 to=to,
                 fro=fro,
                 subject=subject,
                 template_name="email/bulk_reapp_file_error.txt",
                 when=when,
                 account=account)
     except Exception as e:
         magic = str(uuid.uuid1())
         app.logger.error(magic + "\n" + repr(e))
         raise e
示例#31
0
    def run(self):
        """
        Execute the task as specified by the background_job
        :return:
        """

        # Connection to the ES index
        conn = Connection(app.config["ELASTIC_SEARCH_HOST"], index='_snapshot')

        try:
            client = ESSnapshotsClient(conn, app.config['ELASTIC_SEARCH_SNAPSHOT_REPOSITORY'])
            client.check_today_snapshot()
        except Exception as e:
            app_email.send_mail(
                to=[app.config.get('ADMIN_EMAIL', '*****@*****.**')],
                fro=app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**'),
                subject='Alert: DOAJ ElasticSearch backup failure',
                msg_body="Today's ES snapshot has not been found by the checking task. Error: \n" + e.message
            )
            raise e
示例#32
0
def send_editor_group_email(journal):
    eg = EditorGroup.pull_by_key("name", journal.editor_group)
    if eg is None:
        return
    editor = Account.pull(eg.editor)

    url_root = app.config.get("BASE_URL")
    to = [editor.email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME",
                             "") + " - new journal assigned to your group"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/journal_assigned_group.txt",
                        editor=editor.id.encode('utf-8', 'replace'),
                        journal_name=journal.bibjson().title.encode(
                            'utf-8', 'replace'),
                        url_root=url_root)
示例#33
0
文件: emails.py 项目: DOAJ/doaj
def send_admin_ready_email(application, editor_id):
    """ send email to the managing editors when an application is ready """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(' ', '')       # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("admin.suggestions", source=string_id_query)

    # This is to the managing editor email list
    to = [app.config.get('MANAGING_EDITOR_EMAIL', '*****@*****.**')]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - application ready"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/admin_application_ready.txt",
                        application_title=journal_name,
                        editor=editor_id,
                        url_for_application=url_for_application)
示例#34
0
    def decorated_fn(*args, **kwargs):
        try:
            fn(*args, **kwargs)
        except (CaughtTermException, KeyboardInterrupt):
            app.logger.warning(u"Harvester caught SIGTERM. Exiting.")
            report = Report.write_report()
            if app.config.get("HARVESTER_EMAIL_ON_EVENT", False):
                to = app.config.get("HARVESTER_EMAIL_RECIPIENTS", None)
                fro = app.config.get("SYSTEM_EMAIL_FROM")

                if to is not None:
                    from portality import app_email as mail
                    mail.send_mail(
                        to=to,
                        fro=fro,
                        subject="DOAJ Harvester caught SIGTERM at {0}".format(
                            datetime.datetime.utcnow().strftime(
                                "%Y-%m-%dT%H:%M:%SZ")),
                        msg_body=report)
            app.logger.info(report)
            exit(1)
示例#35
0
def send_admin_ready_email(application, editor_id):
    """ send email to the managing editors when an application is ready """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(
        ' ', '')  # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("admin.suggestions",
                                             source=string_id_query)

    # This is to the managing editor email list
    to = [app.config.get('MANAGING_EDITOR_EMAIL', '*****@*****.**')]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - application ready"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/admin_application_ready.txt",
                        application_title=journal_name,
                        editor=editor_id,
                        url_for_application=url_for_application)
示例#36
0
文件: emails.py 项目: DOAJ/doaj
def send_publisher_update_request_revisions_required(application):
    """Tell the publisher their update request requires revisions"""
    journal_title = application.bibjson().title

    owner = models.Account.pull(application.owner)
    if owner is None:
        raise app_email.EmailException("Application {x} does not have an owner, cannot send email".format(x=application.id))

    # This is to the publisher contact on the application
    publisher_name = owner.name
    publisher_email = owner.email

    to = [publisher_email]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - your update request requires revisions"

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/publisher_update_request_revisions.txt",
                        publisher_name=publisher_name,
                        journal_title=journal_title)
示例#37
0
文件: emails.py 项目: DOAJ/doaj
def send_assoc_editor_inprogress_email(application):
    """ Inform the associate editor assigned to application that the status has been reverted by an Ed or ManEd """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(' ', '')       # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions", source=string_id_query)

    # This is to the associate editor assigned to this application
    assoc_editor = models.Account.pull(application.editor)
    to = [assoc_editor.email]

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME", "") + " - an application assigned to you has not passed review."

    app_email.send_mail(to=to,
                        fro=fro,
                        subject=subject,
                        template_name="email/assoc_editor_application_inprogress.txt",
                        assoc_editor=assoc_editor.id,
                        application_title=journal_name,
                        url_for_application=url_for_application)
示例#38
0
    def run(self):
        """
        Execute the task as specified by the background_job
        :return:
        """

        # Connection to the ES index
        conn = Connection(app.config["ELASTIC_SEARCH_HOST"], index='_snapshot')

        try:
            client = ESSnapshotsClient(
                conn, app.config['ELASTIC_SEARCH_SNAPSHOT_REPOSITORY'])
            client.check_today_snapshot()
        except Exception as e:
            app_email.send_mail(
                to=[app.config.get('ADMIN_EMAIL', '*****@*****.**')],
                fro=app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**'),
                subject='Alert: DOAJ ElasticSearch backup failure',
                msg_body=
                "Today's ES snapshot has not been found by the checking task. Error: \n"
                + str(e))
            raise e
示例#39
0
    def email_error(report):
        to = [account.email]
        fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
        subject = app.config.get("SERVICE_NAME","") + " - problems with your bulk reapplication"

        try:
            if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
                now = datetime.now().strftime("%Y%m%d")
                att = app_email.make_attachment("reapplication_errors_" + now + ".csv", "text/plain", report) # NOTE: file extension is now csv
                when = datetime.strptime(upload.created_date, "%Y-%m-%dT%H:%M:%SZ").strftime("%d %b %Y")
                app_email.send_mail(to=to,
                                    fro=fro,
                                    subject=subject,
                                    template_name="email/bulk_reapp_error.txt",
                                    files=[att],
                                    when=when,
                                    account=account
                )
        except Exception as e:
            magic = str(uuid.uuid1())
            app.logger.error(magic + "\n" + repr(e))
            raise e
示例#40
0
def mailer():
    if request.method == 'POST':
        try:
            if request.values.get(
                    'message', False) and not request.values.get('not', False):
                util.send_mail([
                    app.config['ADMIN_NAME'] + ' <' +
                    app.config['ADMIN_EMAIL'] + '>'
                ],
                               request.values.get(
                                   'email', app.config['ADMIN_NAME'] + ' <' +
                                   app.config['ADMIN_EMAIL'] + '>'),
                               'website enquiry', request.values['message'])
                app_email.send_mail(to=[
                    app.config['ADMIN_NAME'] + ' <' +
                    app.config['ADMIN_EMAIL'] + '>'
                ],
                                    fro=request.values.get(
                                        'email',
                                        app.config['ADMIN_NAME'] + ' <' +
                                        app.config['ADMIN_EMAIL'] + '>'),
                                    subject='website enquiry',
                                    template_name=None,
                                    msg_body=request.values['message'])
                flash(
                    'Thank you very much for you enquiry. We will get back to you as soon as possible.',
                    'success')
            else:
                flash(
                    'Sorry. Your message could not be delivered. Please try again.',
                    'error')
        except:
            if app.config.get('DEBUG', False):
                flash('Sorry, Your message failed. Probably because debug.',
                      'error')
            else:
                flash('Sorry. Your message failed. Please try again', 'error')

    return render_template('contact/index.html')
示例#41
0
def send_editor_inprogress_email(application):
    """ Inform editor in charge of an application that the status is has been reverted from ready by a ManEd """
    journal_name = application.bibjson().title
    url_root = app.config.get("BASE_URL")
    query_for_id = Facetview2.make_query(query_string=application.id)
    string_id_query = json.dumps(query_for_id).replace(
        ' ', '')  # Avoid '+' being added to URLs by removing spaces
    url_for_application = url_root + url_for("editor.group_suggestions",
                                             source=string_id_query)

    # This is to the editor in charge of this AssEd's group
    editor_group_name = application.editor_group
    editor_group_id = models.EditorGroup.group_exists_by_name(
        name=editor_group_name)

    try:
        editor_group = models.EditorGroup.pull(editor_group_id)
        editor_acc = editor_group.get_editor_account()
        editor_id = editor_acc.id
        to = [editor_acc.email]
    except AttributeError:
        raise

    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get(
        "SERVICE_NAME",
        "") + " - Application reverted to 'In Progress' by Managing Editor"

    app_email.send_mail(
        to=to,
        fro=fro,
        subject=subject,
        template_name="email/editor_application_inprogress.txt",
        editor=editor_id,
        application_title=journal_name,
        url_for_application=url_for_application)
示例#42
0
文件: background.py 项目: DOAJ/doaj
    def execute(self, background_task):
        job = background_task.background_job
        ctx = None
        acc = None
        if job.user is not None:
            ctx = app.test_request_context("/")
            ctx.push()
            acc = models.Account.pull(job.user)     # FIXME: what happens when this is the "system" user
            if acc is not None:
                login_user(acc)

        job.start()
        job.add_audit_message("Job Started")

        try:
            background_task.run()
        except RetryException:
            if job.reference is None:
                job.reference = {}
            retries = job.reference.get("retries", 0)
            job.reference["retries"] = retries + 1
            job.save()
            raise
        except Exception as e:
            job.fail()
            job.add_audit_message("Error in Job Run")
            job.add_audit_message("Caught in job runner during run: " + traceback.format_exc())
        job.add_audit_message("Job Run Completed")

        job.add_audit_message("Cleanup Started")
        try:
            background_task.cleanup()
        except Exception as e:
            job.fail()
            job.add_audit_message("Error in Cleanup Run")
            job.add_audit_message("Caught in job runner during cleanup: " + traceback.format_exc())
        job.add_audit_message("Job Cleanup Completed")

        job.add_audit_message("Job Finished")
        if not job.is_failed():
            job.success()
        job.save()

        # send a confirmation email to the user if the account exists
        if acc is not None:
            if acc.email is not None and acc.has_role("admin"):
                template = "email/admin_background_job_finished.txt"
                subject = app.config.get("SERVICE_NAME", "") + " - background job finished"

                url_root = app.config.get("BASE_URL")
                if not url_root.endswith("/"):
                    url_root += "/"
                to = [acc.email]
                fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
                query = Facetview2.make_query(job.id)
                url = url_root + "admin/background_jobs?source=" + Facetview2.url_encode_query(query)

                app_email.send_mail(to=to,
                                    fro=fro,
                                    subject=subject,
                                    template_name=template,
                                    job_id=job.id,
                                    action=job.action,
                                    status=job.status,
                                    background_job_url=url
                                    )

        if ctx is not None:
            ctx.pop()
示例#43
0
def create_account_on_suggestion_approval(suggestion, journal):
    o = Account.pull(suggestion.owner)
    if o:
        flash('Account {username} already exists, so simply associating the new journal with it.'.format(username=o.id), 'success')
        o.add_journal(journal.id)
        if not o.has_role('publisher'):
            o.add_role('publisher')
        o.save()
        return o

    suggestion_contact = util.listpop(suggestion.contacts())
    if not suggestion_contact.get('email'):
        msg = ERROR_MSG_TEMPLATE.format(username=o.id, missing_thing='journal contact email in the application')
        app.logger.error(msg)
        flash(msg)
        return o

    send_info_to = suggestion_contact.get('email')
    o = Account.make_account(
        suggestion.owner,
        name=suggestion_contact.get('name'),
        email=send_info_to,
        roles=['publisher'],
        associated_journal_ids=[journal.id]
    )

    o.save()

    url_root = request.url_root
    if url_root.endswith("/"):
        url_root = url_root[:-1]

    if not o.reset_token:
        msg = ERROR_MSG_TEMPLATE.format(username=o.id, missing_thing='reset token')
        app.logger.error(msg)
        flash(msg)
        return o

    reset_url = url_root + url_for('account.reset', reset_token=o.reset_token)
    forgot_pw_url = url_root + url_for('account.forgot')


    password_create_timeout_seconds = int(app.config.get("PASSWORD_CREATE_TIMEOUT", app.config.get('PASSWORD_RESET_TIMEOUT', 86400) * 14))
    password_create_timeout_days = password_create_timeout_seconds / (60*60*24)

    to = [send_info_to]
    fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
    subject = app.config.get("SERVICE_NAME","") + " - account created"


    try:
        if app.config.get("ENABLE_PUBLISHER_EMAIL", False):
            app_email.send_mail(to=to,
                                fro=fro,
                                subject=subject,
                                template_name="email/account_created.txt",
                                reset_url=reset_url,
                                username=o.id,
                                timeout_days=password_create_timeout_days,
                                forgot_pw_url=forgot_pw_url
            )
            flash('Sent email to ' + send_info_to + ' to tell them about the new account.', 'success')
        else:
            flash('Did not email to ' + send_info_to + ' to tell them about the new account, as publisher emailing is disabled.', 'error')
        if app.config.get('DEBUG',False):
            util.flash_with_url('Debug mode - url for create is <a href="{url}">{url}</a>'.format(url=reset_url))
    except Exception as e:
        magic = str(uuid.uuid1())
        util.flash_with_url('Hm, sending the account creation email didn\'t work. Please quote this magic number when reporting the issue: ' + magic + ' . Thank you!', 'error')
        if app.config.get('DEBUG',False):
            util.flash_with_url('Debug mode - url for create is <a href="{url}">{url}</a>'.format(url=reset_url))
        app.logger.error(magic + "\n" + repr(e))
        raise e

    flash('Account {username} created'.format(username=o.id), 'success')
    return o
示例#44
0
文件: runner.py 项目: mauromsl/doaj
    initialise_index(app)
    sub_prefix = app.config.get('HARVESTER_EMAIL_SUBJECT_PREFIX', '')

    # Send an email when the harvester starts.
    mail_prereqs = False
    fro = app.config.get("HARVESTER_EMAIL_FROM_ADDRESS", '*****@*****.**')
    if app.config.get("HARVESTER_EMAIL_ON_EVENT", False):
        to = app.config.get("HARVESTER_EMAIL_RECIPIENTS", None)

        if to is not None:
            mail_prereqs = True
            from portality import app_email as mail
            mail.send_mail(
                to=to,
                fro=fro,
                subject=sub_prefix + "DOAJ Harvester started at {0}".format(
                    datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")),
                msg_body="A new running instance of the harvester has started."
            )

    if app.debug:
        # Augment the default flask debug log to include a timestamp.
        app.debug_log_format = (
            '-' * 80 + '\n' + '%(asctime)s\n'
            '%(levelname)s in %(module)s [%(pathname)s:%(lineno)d]:\n' +
            '%(message)s\n' + '-' * 80)
        flask.logging.create_logger(app)

    accs = list(app.config.get("HARVESTER_API_KEYS", {}).keys())
    for account_id in accs:
        workflow.HarvesterWorkflow.process_account(account_id)
示例#45
0
    def execute(self, background_task):
        job = background_task.background_job
        ctx = None
        acc = None
        if job.user is not None:
            ctx = app.test_request_context("/")
            ctx.push()
            acc = models.Account.pull(
                job.user)  # FIXME: what happens when this is the "system" user
            if acc is not None:
                login_user(acc)

        job.start()
        job.add_audit_message("Job Started")

        try:
            background_task.run()
        except RetryException:
            if job.reference is None:
                job.reference = {}
            retries = job.reference.get("retries", 0)
            job.reference["retries"] = retries + 1
            job.save()
            raise
        except Exception as e:
            job.fail()
            job.add_audit_message("Error in Job Run")
            job.add_audit_message("Caught in job runner during run: " +
                                  traceback.format_exc())
        job.add_audit_message("Job Run Completed")

        job.add_audit_message("Cleanup Started")
        try:
            background_task.cleanup()
        except Exception as e:
            job.fail()
            job.add_audit_message("Error in Cleanup Run")
            job.add_audit_message("Caught in job runner during cleanup: " +
                                  traceback.format_exc())
        job.add_audit_message("Job Cleanup Completed")

        job.add_audit_message("Job Finished")
        if not job.is_failed():
            job.success()
        job.save()

        # send a confirmation email to the user if the account exists
        if acc is not None:
            if acc.email is not None and acc.has_role("admin"):
                template = "email/admin_background_job_finished.txt"
                subject = app.config.get("SERVICE_NAME",
                                         "") + " - background job finished"

                url_root = app.config.get("BASE_URL")
                if not url_root.endswith("/"):
                    url_root += "/"
                to = [acc.email]
                fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
                query = Facetview2.make_query(job.id)
                url = url_root + "admin/background_jobs?source=" + Facetview2.url_encode_query(
                    query)

                app_email.send_mail(to=to,
                                    fro=fro,
                                    subject=subject,
                                    template_name=template,
                                    job_id=job.id,
                                    action=job.action,
                                    status=job.status,
                                    background_job_url=url)

        if ctx is not None:
            ctx.pop()
示例#46
0
def send_publisher_reject_email(application,
                                note=None,
                                update_request=False,
                                send_to_owner=True,
                                send_to_suggester=False):
    """Tell the publisher their application was rejected"""
    journal_title = application.bibjson().title

    send_instructions = []
    if send_to_owner:
        owner = models.Account.pull(application.owner)
        if owner is not None:
            send_instructions.append({
                "name": owner.name,
                "email": owner.email,
                "type": "owner"
            })

    if send_to_suggester:
        sug = application.suggester
        if sug is not None:
            send_instructions.append({
                "name": sug["name"],
                "email": sug["email"],
                "type": "suggester"
            })

    if len(send_instructions) == 0:
        raise app_email.EmailException(
            "Application {x} does not have an owner or suggester, cannot send email"
            .format(x=application.id))

    # determine if this is an application or an update request
    app_type = "application" if update_request is False else "update"

    for instructions in send_instructions:
        to = [instructions["email"]]
        fro = app.config.get('SYSTEM_EMAIL_FROM', '*****@*****.**')
        subject = app.config.get("SERVICE_NAME",
                                 "") + " - your " + app_type + " was rejected"

        if update_request:
            app_email.send_mail(
                to=to,
                fro=fro,
                subject=subject,
                template_name="email/publisher_update_request_rejected.txt",
                publisher_name=instructions["name"],
                journal_title=journal_title,
                note=note)
        else:
            app_email.send_mail(
                to=to,
                fro=fro,
                subject=subject,
                template_name="email/publisher_application_rejected.txt",
                publisher_name=instructions["name"],
                journal_title=journal_title,
                note=note)

    return send_instructions