コード例 #1
0
ファイル: operations.py プロジェクト: wasm-network/indico
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.reviewing, EventLogKind.positive,
                       'Abstracts',
                       'Abstract {} created'.format(abstract.verbose_title),
                       session.user)
    return abstract
コード例 #2
0
ファイル: operations.py プロジェクト: javfg/indico
def withdraw_abstract(abstract):
    abstract.reset_state()
    abstract.state = AbstractState.withdrawn
    contrib = abstract.contribution
    abstract.contribution = None
    if contrib:
        delete_contribution(contrib)
    db.session.flush()
    signals.event.abstract_state_changed.send(abstract)
    send_abstract_notifications(abstract)
    logger.info('Abstract %s withdrawn by %s', abstract, session.user)
    abstract.log(EventLogRealm.reviewing, LogKind.negative, 'Abstracts',
                 f'Abstract {abstract.verbose_title} withdrawn', session.user)
コード例 #3
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'] == '[Indico] 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, Pocahontas Silva, John Smith
            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}

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

    ev, abstract, track, contrib_type = abstract_objects
    monkeypatch.setattr(
        'indico.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)
コード例 #4
0
ファイル: notifications_test.py プロジェクト: indico/indico
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('indico.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
コード例 #5
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('indico.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
コード例 #6
0
ファイル: operations.py プロジェクト: nyimbi/indico
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')
        abstract.accepted_contrib_type = abstract_data.get(
            'accepted_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()
    log_data['Sent notifications'] = send_notifications
    if send_notifications:
        send_abstract_notifications(abstract)
    logger.info('Abstract %s judged by %s', abstract, judge)
    abstract.event_new.log(EventLogRealm.management,
                           EventLogKind.change,
                           'Abstracts',
                           'Abstract {} judged'.format(abstract.verbose_title),
                           judge,
                           data=log_data)
コード例 #7
0
def judge_abstract(abstract, abstract_data, judgment, judge, contrib_session=None, merge_persons=False,
                   send_notifications=False):
    from indico.modules.events.tracks.models.tracks import Track
    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

        from indico.modules.events.contributions.models.limits import ContributionLimit
        from sqlalchemy import func

        if not abstract.accepted_contrib_type:
            raise Exception("The contribution type is missing.")

        limit_obj =  ContributionLimit.query.filter_by(event_id=abstract.event.id,
                                                       track_id=(None if not abstract.accepted_track else abstract.accepted_track.id),
                                                       type_id=abstract.accepted_contrib_type.id).first()
        limit = None if not limit_obj else limit_obj.value
        val = Abstract.query.filter_by(event_id=abstract.event.id,
                                       accepted_track_id=(None if not abstract.accepted_track else abstract.accepted_track.id),
                                       accepted_contrib_type_id=abstract.accepted_contrib_type.id).count()

        if limit and val >= limit+1:
            raise Exception("Abstract admission limit of <b>%s</b> has been reached for type <i>'%s'</i> on track <i>'%s'</i>."
            " Please either reset a previous judgement or report this." % (limit, abstract.accepted_contrib_type.name,
            'No track' if not abstract.accepted_track else abstract.accepted_track.title))

    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)
コード例 #8
0
ファイル: notifications_test.py プロジェクト: indico/indico
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'] == '[Indico] 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, Pocahontas Silva, John Smith
            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}

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

    ev, abstract, track, contrib_type = abstract_objects
    monkeypatch.setattr('indico.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)
コード例 #9
0
ファイル: operations.py プロジェクト: bkolobara/indico
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.reviewing, EventLogKind.positive, 'Abstracts',
                       'Abstract {} created'.format(abstract.verbose_title), session.user)
    return abstract
コード例 #10
0
ファイル: notifications_test.py プロジェクト: indico/indico
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('indico.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
コード例 #11
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('indico.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
コード例 #12
0
ファイル: notifications_test.py プロジェクト: indico/indico
def test_notification_rules(mocker, abstract_objects, create_email_template, dummy_user, dummy_event):
    send_email = mocker.patch('indico.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
コード例 #13
0
def test_notification_rules(mocker, abstract_objects, create_email_template,
                            dummy_user, dummy_event):
    send_email = mocker.patch(
        'indico.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
コード例 #14
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('indico.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
コード例 #15
0
ファイル: notifications_test.py プロジェクト: indico/indico
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('indico.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
コード例 #16
0
def test_email_content(monkeypatch, abstract_objects, create_email_template,
                       dummy_user):
    def _mock_send_email(email, event, user):
        assert email[
            'subject'] == '[Indico] Abstract Acceptance notification (#314)'
        assert text_compare(
            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).

            Kind regards,
            The organizers of dummy#0

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

    ev, abstract, track, contrib_type = abstract_objects
    monkeypatch.setattr(
        'indico.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)
コード例 #17
0
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')
        abstract.accepted_contrib_type = abstract_data.get('accepted_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()
    log_data['Sent notifications'] = send_notifications
    if send_notifications:
        send_abstract_notifications(abstract)
    logger.info('Abstract %s judged by %s', abstract, judge)
    abstract.event_new.log(EventLogRealm.management, EventLogKind.change, 'Abstracts',
                           'Abstract {} judged'.format(abstract.verbose_title), judge, data=log_data)