def create_abstract(event,
                    abstract_data,
                    custom_fields_data=None,
                    send_notifications=False):
    abstract = Abstract(event=event, submitter=session.user)
    tracks = abstract_data.pop('submitted_for_tracks', None)
    attachments = abstract_data.pop('attachments', None)
    abstract.populate_from_dict(abstract_data)
    if tracks is not None:
        _update_tracks(abstract, tracks)
    if custom_fields_data:
        set_custom_fields(abstract, custom_fields_data)
    db.session.flush()

    if attachments:
        add_abstract_files(abstract, attachments['added'], log_action=False)
    signals.event.abstract_created.send(abstract)

    if send_notifications:
        send_abstract_notifications(abstract)
    logger.info('Abstract %s created by %s', abstract, session.user)
    abstract.event.log(EventLogRealm.management, EventLogKind.positive,
                       'Abstracts',
                       'Abstract {} created'.format(abstract.verbose_title),
                       session.user)
    return abstract
Example #2
0
def test_email_content(monkeypatch, abstract_objects, create_email_template,
                       dummy_user):
    def _mock_send_email(email, event, module, user):
        assert event == ev
        assert module == 'Abstracts'
        assert email[
            'subject'] == '[fossir] Abstract Acceptance notification (#314)'
        assert_text_equal(
            email['body'], """
            Dear Guinea Pig,

            We're pleased to announce that your abstract "Broken Symmetry and the Mass of Gauge Vector Mesons" with ID
            #314 has been accepted in track "Dummy Track" (Poster).

            See below a summary of your submitted abstract:
            Conference: {event.title}
            Submitted by: Guinea Pig
            Title: Broken Symmetry and the Mass of Gauge Vector Mesons
            Primary Authors: John Doe, John Smith, Pocahontas Silva
            Co-authors:
            Track classification: Dummy Track
            Presentation type: Poster

            For a more detailed summary please visit the page of your abstract:
            http://localhost/event/-314/abstracts/1234/.

            Kind regards,
            The organizers of {event.title}

            --
            fossir :: Call for Abstracts
            http://localhost/event/{event.id}/
        """.format(event=ev))

    ev, abstract, track, contrib_type = abstract_objects
    monkeypatch.setattr(
        'fossir.modules.events.abstracts.notifications.send_email',
        _mock_send_email)

    ev.abstract_email_templates.append(
        create_email_template(ev, 0, 'accept', 'accept', [{
            'state': [AbstractState.accepted.value]
        }], True))

    abstract.accepted_contrib_type = contrib_type
    abstract.accepted_track = track
    abstract.state = AbstractState.accepted
    abstract.judge = dummy_user
    abstract.judgment_dt = now_utc(False)
    send_abstract_notifications(abstract)
Example #3
0
def test_notification_any_conditions(mocker, abstract_objects,
                                     create_email_template, dummy_user):
    event, abstract, track, contrib_type = abstract_objects
    event.abstract_email_templates = [
        create_email_template(event, 0, 'accept', 'accepted', [{
            'state': [AbstractState.accepted.value]
        }], True)
    ]

    send_email = mocker.patch(
        'fossir.modules.events.abstracts.notifications.send_email')
    abstract.state = AbstractState.accepted
    abstract.judge = dummy_user
    abstract.judgment_dt = now_utc(False)
    abstract.accepted_track = track
    send_abstract_notifications(abstract)
    assert send_email.call_count == 1
Example #4
0
def test_notification_rules(mocker, abstract_objects, create_email_template,
                            dummy_user, dummy_event):
    send_email = mocker.patch(
        'fossir.modules.events.abstracts.notifications.send_email')

    event, abstract, track, contrib_type = abstract_objects
    event.abstract_email_templates.append(
        create_email_template(event, 0, 'merge', 'merged poster for track', [{
            'state': [AbstractState.merged.value],
            'track': [track.id]
        }], True))

    send_abstract_notifications(abstract)
    assert send_email.call_count == 0

    abstract.state = AbstractState.accepted
    abstract.judge = dummy_user
    abstract.judgment_dt = now_utc(False)
    abstract.accepted_track = track
    send_abstract_notifications(abstract)
    assert send_email.call_count == 0

    abstract.state = AbstractState.merged
    abstract.merged_into = Abstract(title='test',
                                    submitter=dummy_user,
                                    event=dummy_event)
    abstract.accepted_track = None
    abstract.submitted_for_tracks = {track}
    send_abstract_notifications(abstract)
    assert send_email.call_count == 1
def judge_abstract(abstract,
                   abstract_data,
                   judgment,
                   judge,
                   contrib_session=None,
                   merge_persons=False,
                   send_notifications=False):
    abstract.judge = judge
    abstract.judgment_dt = now_utc()
    abstract.judgment_comment = abstract_data['judgment_comment']
    log_data = {'Judgment': orig_string(judgment.title)}
    if judgment == AbstractAction.accept:
        abstract.state = AbstractState.accepted
        abstract.accepted_track = abstract_data.get('accepted_track')
        if abstract_data.get('override_contrib_type') or abstract_data.get(
                'accepted_contrib_type'):
            abstract.accepted_contrib_type = abstract_data.get(
                'accepted_contrib_type')
        else:
            abstract.accepted_contrib_type = abstract.submitted_contrib_type
        if not abstract.contribution:
            abstract.contribution = create_contribution_from_abstract(
                abstract, contrib_session)
        if abstract.accepted_track:
            log_data['Track'] = abstract.accepted_track.title
        if abstract.accepted_contrib_type:
            log_data['Type'] = abstract.accepted_contrib_type.name
    elif judgment == AbstractAction.reject:
        abstract.state = AbstractState.rejected
    elif judgment == AbstractAction.mark_as_duplicate:
        abstract.state = AbstractState.duplicate
        abstract.duplicate_of = abstract_data['duplicate_of']
        log_data['Duplicate of'] = abstract.duplicate_of.verbose_title
    elif judgment == AbstractAction.merge:
        abstract.state = AbstractState.merged
        abstract.merged_into = abstract_data['merged_into']
        log_data['Merged into'] = abstract.merged_into.verbose_title
        log_data['Merge authors'] = merge_persons
        if merge_persons:
            _merge_person_links(abstract.merged_into, abstract)
    db.session.flush()
    if send_notifications:
        log_data['Notifications sent'] = send_abstract_notifications(abstract)
    logger.info('Abstract %s judged by %s', abstract, judge)
    abstract.event.log(EventLogRealm.management,
                       EventLogKind.change,
                       'Abstracts',
                       'Abstract {} judged'.format(abstract.verbose_title),
                       judge,
                       data=log_data)
Example #6
0
def test_notification_stop_on_match(mocker, abstract_objects,
                                    create_email_template, dummy_user):
    event, abstract, track, contrib_type = abstract_objects
    event.abstract_email_templates = [
        create_email_template(event, 0, 'accept', 'accepted poster', [{
            'state': [AbstractState.accepted.value]
        }], False),
        create_email_template(event, 0, 'accept', 'accepted poster 2', [{
            'state': [AbstractState.accepted.value]
        }], True)
    ]

    send_email = mocker.patch(
        'fossir.modules.events.abstracts.notifications.send_email')
    abstract.state = AbstractState.accepted
    abstract.judge = dummy_user
    abstract.judgment_dt = now_utc(False)
    send_abstract_notifications(abstract)
    assert send_email.call_count == 2

    send_email.reset_mock()
    event.abstract_email_templates[0].stop_on_match = True
    send_abstract_notifications(abstract)
    assert send_email.call_count == 1
Example #7
0
def test_notification_several_conditions(db, mocker, abstract_objects,
                                         create_email_template,
                                         create_dummy_track,
                                         create_dummy_contrib_type,
                                         dummy_user):
    event, abstract, track, contrib_type = abstract_objects
    event.abstract_email_templates = [
        create_email_template(event, 0, 'accept', 'accepted', [{
            'state': [AbstractState.accepted.value],
            'track': [track.id],
            'contribution_type': [contrib_type.id]
        }, {
            'state': [AbstractState.accepted.value],
            'contribution_type': []
        }], True)
    ]

    send_email = mocker.patch(
        'fossir.modules.events.abstracts.notifications.send_email')
    abstract.state = AbstractState.accepted
    abstract.judge = dummy_user
    abstract.judgment_dt = now_utc(False)
    abstract.accepted_track = track
    send_abstract_notifications(abstract)
    assert send_email.call_count == 1

    send_email.reset_mock()
    abstract.accepted_contrib_type = contrib_type
    send_abstract_notifications(abstract)
    assert send_email.call_count == 1

    send_email.reset_mock()
    abstract.accepted_track = create_dummy_track(event)
    abstract.accepted_contrib_type = create_dummy_contrib_type(
        event, name='Presentation')
    db.session.flush()
    send_abstract_notifications(abstract)
    assert send_email.call_count == 0