Пример #1
0
def send_brief_closed_email(brief):
    from app.api.services import audit_service, audit_types  # to circumvent circular dependency
    from app.tasks.s3 import create_resumes_zip, CreateResumesZipException

    brief_email_sent_audit_event = audit_service.find(
        type=audit_types.sent_closed_brief_email.value,
        object_type="Brief",
        object_id=brief.id).count()

    if (brief_email_sent_audit_event > 0):
        return

    # create the resumes zip
    has_resumes_zip = False
    try:
        create_resumes_zip(brief.id)
        has_resumes_zip = True
    except Exception as e:
        rollbar.report_exc_info()
        pass

    to_addresses = [
        user.email_address for user in brief.users
        if user.active and user.email_address.endswith('@digital.gov.au')
    ]

    # prepare copy
    email_body = render_email_template(
        'brief_closed.md',
        frontend_url=current_app.config['FRONTEND_ADDRESS'],
        brief_name=brief.data['title'],
        brief_id=brief.id,
        has_resumes_zip=has_resumes_zip)

    subject = "Your brief has closed - please review all responses."

    send_or_handle_error(to_addresses,
                         email_body,
                         subject,
                         current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
                         current_app.config['DM_GENERIC_SUPPORT_NAME'],
                         event_description_for_errors='brief closed')

    audit_service.log_audit_event(
        audit_type=audit_types.sent_closed_brief_email,
        user='',
        data={
            "to_addresses": ', '.join(to_addresses),
            "email_body": email_body,
            "subject": subject
        },
        db_object=brief)
def send_specialist_brief_closed_email(brief):
    from app.api.services import (
        audit_service,
        audit_types,
        brief_responses_service
    )  # to circumvent circular dependency

    if brief.lot.slug != 'specialist':
        return

    audit_event = audit_service.find(type=audit_types.specialist_brief_closed_email.value,
                                     object_type="Brief",
                                     object_id=brief.id).count()

    if (audit_event > 0):
        return

    responses = brief_responses_service.get_brief_responses(brief.id, None, submitted_only=True)
    to_addresses = get_brief_emails(brief)

    # prepare copy
    email_body = render_email_template(
        'specialist_brief_closed.md',
        frontend_url=current_app.config['FRONTEND_ADDRESS'],
        brief_name=brief.data['title'],
        brief_id=brief.id,
        number_of_responses='{}'.format(len(responses)),
        number_of_responses_plural='s' if len(responses) > 1 else ''
    )

    subject = 'Your "{}" opportunity has closed.'.format(brief.data['title'])

    send_or_handle_error(
        to_addresses,
        email_body,
        subject,
        current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
        current_app.config['DM_GENERIC_SUPPORT_NAME'],
        event_description_for_errors='brief closed'
    )

    audit_service.log_audit_event(
        audit_type=audit_types.specialist_brief_closed_email,
        user='',
        data={
            "to_addresses": ', '.join(to_addresses),
            "email_body": email_body,
            "subject": subject
        },
        db_object=brief)
Пример #3
0
def test_audit_event_is_created_when_team_is_created(published_team, client,
                                                     app, users):
    with app.app_context():
        client.post('/2/login',
                    data=json.dumps({
                        'emailAddress': '*****@*****.**',
                        'password': '******'
                    }),
                    content_type='application/json')

        response = client.post('/2/team/create',
                               content_type='application/json')
        audit_event = audit_service.find(
            type=audit_types.create_team.value).first()

        assert audit_event.type == audit_types.create_team.value
        assert audit_event.user == '*****@*****.**'
def send_brief_closed_email(brief):
    from app.api.services import audit_service, audit_types  # to circumvent circular dependency

    if brief.lot.slug in ['specialist']:
        return

    brief_email_sent_audit_event = audit_service.find(type=audit_types.sent_closed_brief_email.value,
                                                      object_type="Brief",
                                                      object_id=brief.id).count()

    if (brief_email_sent_audit_event > 0):
        return

    to_addresses = get_brief_emails(brief)

    # prepare copy
    email_body = render_email_template(
        'brief_closed.md',
        frontend_url=current_app.config['FRONTEND_ADDRESS'],
        brief_name=brief.data['title'],
        brief_id=brief.id
    )

    subject = "Your opportunity has closed - please review all responses."

    send_or_handle_error(
        to_addresses,
        email_body,
        subject,
        current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
        current_app.config['DM_GENERIC_SUPPORT_NAME'],
        event_description_for_errors='brief closed'
    )

    audit_service.log_audit_event(
        audit_type=audit_types.sent_closed_brief_email,
        user='',
        data={
            "to_addresses": ', '.join(to_addresses),
            "email_body": email_body,
            "subject": subject
        },
        db_object=brief)
    def test_edit_opportunity_creates_audit_event(self, agency_service, briefs, users):
        specialist_brief = brief_service.get(2)
        user = user_service.get(2)
        agency_service.get_agency_name.return_value = 'DTA'

        edits = {
            'closingDate': '',
            'title': 'test',
            'sellers': {},
            'summary': ''
        }

        brief = brief_edit_business.edit_opportunity(user.id, specialist_brief.id, edits)
        audit_event = audit_service.find(
            object_id=specialist_brief.id,
            object_type='Brief',
            type=audit_types.opportunity_edited.value
        ).one_or_none()

        assert audit_event is not None
Пример #6
0
def send_brief_closed_email(brief):
    from app.api.services import audit_service, audit_types  # to circumvent circular dependency

    brief_email_sent_audit_event = audit_service.find(type=audit_types.sent_closed_brief_email.value,
                                                      object_type="Brief",
                                                      object_id=brief.id).count()

    if (brief_email_sent_audit_event > 0):
        return

    to_addresses = [user.email_address for user in brief.users if user.active]

    # prepare copy
    email_body = render_email_template(
        'brief_closed.md',
        frontend_url=current_app.config['FRONTEND_ADDRESS'],
        brief_name=brief.data['title'],
        brief_id=brief.id
    )

    subject = "Your brief has closed - please review all responses."

    send_or_handle_error(
        to_addresses,
        email_body,
        subject,
        current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
        current_app.config['DM_GENERIC_SUPPORT_NAME'],
        event_description_for_errors='brief closed'
    )

    audit_service.log_audit_event(
        audit_type=audit_types.sent_closed_brief_email,
        user='',
        data={
            "to_addresses": ', '.join(to_addresses),
            "email_body": email_body,
            "subject": subject
        },
        db_object=brief)
def send_specialist_brief_published_email(brief):
    from app.api.services import (
        audit_service,
        audit_types,
        domain_service,
        suppliers
    )  # to circumvent circular dependency
    from app.models import Supplier

    if brief.lot.slug != 'specialist':
        return

    brief_email_sent_audit_event = audit_service.find(type=audit_types.specialist_brief_published.value,
                                                      object_type="Brief",
                                                      object_id=brief.id).count()

    if (brief_email_sent_audit_event > 0):
        return

    to_addresses = get_brief_emails(brief)

    invited_sellers = ''
    sellers_text = ''
    if brief.data.get('sellerSelector', '') == 'someSellers':
        sellers_text = ''
        seller_codes = []
        for key, value in brief.data.get('sellers', {}).iteritems():
            seller_codes.append(key)
        sellers = suppliers.filter(Supplier.code.in_(seller_codes)).all()
        for seller in sellers:
            invited_sellers += '* {}\n'.format(seller.name)
    else:
        panel_category = domain_service.get(id=brief.data.get('sellerCategory'))
        sellers_text = 'All sellers approved under {}'.format(panel_category.name)

    # prepare copy
    email_body = render_email_template(
        'specialist_brief_published.md',
        frontend_url=current_app.config['FRONTEND_ADDRESS'],
        brief_name=brief.data['title'],
        brief_id=brief.id,
        brief_close_date=brief.closed_at.strftime('%d/%m/%Y'),
        sellers_text=sellers_text,
        invited_sellers=invited_sellers,
        number_of_suppliers=brief.data.get('numberOfSuppliers', ''),
        question_close_date=brief.questions_closed_at.strftime('%d/%m/%Y')
    )

    subject = "Your opportunity for {} has been published".format(brief.data['title'])

    send_or_handle_error(
        to_addresses,
        email_body,
        subject,
        current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
        current_app.config['DM_GENERIC_SUPPORT_NAME'],
        event_description_for_errors='brief published'
    )

    audit_service.log_audit_event(
        audit_type=audit_types.specialist_brief_published,
        user='',
        data={
            "to_addresses": ', '.join(to_addresses),
            "email_body": email_body,
            "subject": subject
        },
        db_object=brief)
Пример #8
0
def send_dreamail(simulate, skip_audit_check):
    from app.api.services import (audit_service, audit_types, suppliers)
    simulation_result = []

    result = suppliers.get_suppliers_codes_with_domains(False)

    for item in result:
        supplier_code = item['code']
        supplier = suppliers.find(code=item['code']).one_or_none()

        if skip_audit_check is False:
            sent = audit_service.find(
                object_id=supplier.id,
                object_type='Supplier',
                type='seller_to_review_pricing_case_study_email_part_2'
            ).one_or_none()

            if sent:
                continue

        case_studies = supplier.case_studies

        option_1_aoe = []
        option_2_cs = []
        for supplier_domain in supplier.domains:
            domain_name = supplier_domain.domain.name
            if supplier_domain.price_status == 'rejected':
                option_1_aoe.append('* {}'.format(domain_name))

            else:
                rejected_case_studies = [
                    cs for cs in case_studies
                    if cs.data['service'] == domain_name
                    and cs.status == 'rejected'
                ]
                for cs in rejected_case_studies:
                    option_2_cs.append(
                        '* [{title}]({frontend_url}/case-study/{cs_id}) ({domain_name})'
                        .format(title=cs.data.get('title').encode('utf-8'),
                                frontend_url=current_app.
                                config['FRONTEND_ADDRESS'],
                                cs_id=cs.id,
                                domain_name=domain_name))

        dreamail_option_1_content = ''
        if option_1_aoe:
            dreamail_option_1_content = fill_template(
                'dreamail_option_1.md', aoe='\n'.join(option_1_aoe))

        dreamail_option_2_content = ''
        if option_2_cs:
            dreamail_option_2_content = fill_template(
                'dreamail_option_2.md',
                frontend_url=current_app.config['FRONTEND_ADDRESS'],
                cs='\n'.join(option_2_cs).decode('utf-8'))

        if dreamail_option_1_content == '' and dreamail_option_2_content == '':
            continue

        email_body = render_email_template(
            'dreamail.md',
            dreamail_option_1=dreamail_option_1_content,
            dreamail_option_2=dreamail_option_2_content,
            frontend_url=current_app.config['FRONTEND_ADDRESS'],
            supplier_name=supplier.name)

        subject = 'Please review your pricing and/or case studies on the Marketplace'

        to_addresses = [
            e['email_address']
            for e in suppliers.get_supplier_contacts(supplier_code)
        ]
        if simulate:
            simulation_result.append({
                'to_addresses': to_addresses,
                'email_body': email_body,
                'subject': subject,
                'supplier_code': supplier_code
            })
        else:
            send_or_handle_error(
                to_addresses,
                email_body,
                subject,
                current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
                current_app.config['DM_GENERIC_SUPPORT_NAME'],
                event_description_for_errors=audit_types.
                seller_to_review_pricing_case_study_email_part_2)

            if skip_audit_check is False:
                audit_service.log_audit_event(
                    audit_type=audit_types.
                    seller_to_review_pricing_case_study_email_part_2,
                    user='',
                    data={
                        "to_addresses": ', '.join(to_addresses),
                        "email_body": email_body,
                        "subject": subject
                    },
                    db_object=supplier)

    if simulate:
        return simulation_result
Пример #9
0
def send_dreamail_part_3(simulate, skip_audit_check):
    from app.api.services import (audit_service, audit_types, suppliers)
    simulation_result = []

    result = suppliers.get_suppliers_with_unassessed_domains_and_all_case_studies_rejected(
    )

    for item in result:
        supplier_code = item['code']
        supplier = suppliers.find(code=item['code']).one_or_none()

        if skip_audit_check is False:
            sent = audit_service.find(
                object_id=supplier.id,
                object_type='Supplier',
                type='seller_to_review_pricing_case_study_email_part_3'
            ).one_or_none()

            if sent:
                continue

        aoe = ''
        for d in item.get('domains', []):
            aoe += '* {}\n'.format(d)

        email_body = render_email_template(
            'dreamail_part_3.md',
            frontend_url=current_app.config['FRONTEND_ADDRESS'],
            supplier_name=supplier.name,
            aoe=aoe)
        subject = 'Please review your pricing and/or case studies on the Marketplace'

        to_addresses = [
            e['email_address']
            for e in suppliers.get_supplier_contacts(supplier_code)
        ]

        if simulate:
            simulation_result.append({
                'to_addresses': to_addresses,
                'email_body': email_body,
                'subject': subject,
                'supplier_code': supplier_code
            })
        else:
            send_or_handle_error(
                to_addresses,
                email_body,
                subject,
                current_app.config['DM_GENERIC_NOREPLY_EMAIL'],
                current_app.config['DM_GENERIC_SUPPORT_NAME'],
                event_description_for_errors=audit_types.
                seller_to_review_pricing_case_study_email_part_3)

            if skip_audit_check is False:
                audit_service.log_audit_event(
                    audit_type=audit_types.
                    seller_to_review_pricing_case_study_email_part_3,
                    user='',
                    data={
                        "to_addresses": ', '.join(to_addresses),
                        "email_body": email_body,
                        "subject": subject
                    },
                    db_object=supplier)

    if simulate:
        return simulation_result