def update_review(review, review_data, questions_data):
    paper = review.revision.paper
    event = paper.event
    changes = review.populate_from_dict(review_data)
    review.modified_dt = now_utc()
    log_fields = {}
    for question in event.cfp.get_questions_for_review_type(review.type):
        field_name = 'question_{}'.format(question.id)
        rating = question.get_review_rating(review, allow_create=True)
        old_value = rating.value
        rating.value = int(questions_data[field_name])
        if old_value != rating.value:
            changes[field_name] = (old_value, rating.value)
            log_fields[field_name] = {
                'title': question.text,
                'type': 'number'
            }
    db.session.flush()
    notify_paper_review_submission(review)
    logger.info("Paper review %r modified", review)
    log_fields.update({
        'proposed_action': 'Action',
        'comment': 'Comment'
    })
    event.log(EventLogRealm.management, EventLogKind.change, 'Papers',
              'Review for paper {} modified'.format(paper.verbose_title),
              session.user, data={'Changes': make_diff_log(changes, log_fields)})
def update_comment(comment, text, visibility):
    changes = comment.populate_from_dict({'text': text, 'visibility': visibility})
    comment.modified_by = session.user
    comment.modified_dt = now_utc()
    db.session.flush()
    logger.info("Paper comment %r modified by %r", comment, session.user)
    paper = comment.paper_revision.paper
    paper.event.log(EventLogRealm.management, EventLogKind.change, 'Papers',
                    'Comment on paper {} modified'.format(paper.verbose_title), session.user,
                    data={'Changes': make_diff_log(changes, {'text': 'Text', 'visibility': 'Visibility'})})
Exemple #3
0
def update_event_protection(event, data):
    assert set(data.viewkeys()) <= {'protection_mode', 'own_no_access_contact', 'access_key', 'visibility'}
    changes = event.populate_from_dict(data)
    db.session.flush()
    signals.event.updated.send(event, changes=changes)
    logger.info('Protection of event %r updated with %r by %r', event, data, session.user)
    if changes:
        log_fields = {'protection_mode': 'Protection mode',
                      'own_no_access_contact': 'No access contact',
                      'access_key': {'title': 'Access key', 'type': 'string'},
                      'visibility': {'title': 'Visibility', 'type': 'string',
                                     'convert': lambda changes: [_format_visibility(event, x) for x in changes]}}
        event.log(EventLogRealm.management, EventLogKind.change, 'Event', 'Protection updated', session.user,
                  data={'Changes': make_diff_log(changes, log_fields)})
def update_abstract_review(review, review_data, questions_data):
    event = review.abstract.event
    changes = review.populate_from_dict(review_data)
    review.modified_dt = now_utc()
    log_fields = {}
    for question in event.abstract_review_questions:
        field_name = 'question_{}'.format(question.id)
        rating = question.get_review_rating(review, allow_create=True)
        old_value = rating.value
        rating.value = int(questions_data[field_name])
        if old_value != rating.value:
            changes[field_name] = (old_value, rating.value)
            log_fields[field_name] = {'title': question.text, 'type': 'number'}
    db.session.flush()
    logger.info("Abstract review %s modified", review)
    log_fields.update({'proposed_action': 'Action', 'comment': 'Comment'})
    if review.proposed_action in {
            AbstractAction.mark_as_duplicate, AbstractAction.merge
    }:
        log_fields['proposed_related_abstract'] = {
            'title':
            'Other abstract',
            'type':
            'string',
            'convert':
            lambda change: [x.verbose_title if x else None for x in change]
        }
    elif review.proposed_action == AbstractAction.accept:
        log_fields['proposed_contribution_type'] = {
            'title': 'Contribution type',
            'type': 'string',
            'convert': lambda change: [x.name if x else None for x in change]
        }
    elif review.proposed_action == AbstractAction.change_tracks:
        log_fields['proposed_tracks'] = {
            'title': 'Other tracks',
            'convert':
            lambda change: [sorted(t.title for t in x) for x in change]
        }
    event.log(EventLogRealm.management,
              EventLogKind.change,
              'Abstracts',
              'Review for abstract {} modified'.format(
                  review.abstract.verbose_title),
              session.user,
              data={
                  'Track': review.track.title,
                  'Changes': make_diff_log(changes, log_fields)
              })
Exemple #5
0
def _log_event_update(event, changes, visible_person_link_changes=False):
    log_fields = {
        'title': {'title': 'Title', 'type': 'string'},
        'description': 'Description',
        'url_shortcut': {'title': 'URL Shortcut', 'type': 'string'},
        'address': 'Address',
        'venue_room': {'title': 'Location', 'type': 'string'},
        'keywords': 'Keywords',
        'references': {
            'title': 'External IDs',
            'convert': lambda changes: [map(_format_ref, refs) for refs in changes]
        },
        'person_links': {
            'title': 'Speakers' if event.type_ == EventType.lecture else 'Chairpersons',
            'convert': lambda changes: [map(_format_person, persons) for persons in changes]
        },
        'start_dt': 'Start date',
        'end_dt': 'End date',
        'start_dt_override': 'Displayed start date',
        'end_dt_override': 'Displayed end date',
        'timezone': {'title': 'Timezone', 'type': 'string'},
        'organizer_info': 'Organizers',
        'additional_info': 'Additional Info',
        'contact_title': {'title': 'Contact/Support title', 'type': 'string'},
        'contact_emails': 'Contact emails',
        'contact_phones': 'Contact phone numbers',
    }
    _split_location_changes(changes)
    if not visible_person_link_changes:
        # Don't log a person link change with no visible changes (changes
        # on an existing link or reordering). It would look quite weird in
        # the event log.
        # TODO: maybe use a separate signal for such changes to log them
        # anyway and allow other code to act on them?
        changes.pop('person_links', None)
    if changes:
        if set(changes.viewkeys()) <= {'timezone', 'start_dt', 'end_dt', 'start_dt_override', 'end_dt_override'}:
            what = 'Dates'
        elif len(changes) == 1:
            what = log_fields[changes.keys()[0]]
            if isinstance(what, dict):
                what = what['title']
        else:
            what = 'Data'
        event.log(EventLogRealm.management, EventLogKind.change, 'Event', '{} updated'.format(what), session.user,
                  data={'Changes': make_diff_log(changes, log_fields)})
def update_abstract_comment(comment, comment_data):
    changes = comment.populate_from_dict(comment_data)
    comment.modified_by = session.user
    comment.modified_dt = now_utc()
    db.session.flush()
    logger.info("Abstract comment %s modified by %s", comment, session.user)
    comment.abstract.event.log(EventLogRealm.management,
                               EventLogKind.change,
                               'Abstracts',
                               'Comment on abstract {} modified'.format(
                                   comment.abstract.verbose_title),
                               session.user,
                               data={
                                   'Changes':
                                   make_diff_log(changes, {
                                       'text': 'Text',
                                       'visibility': 'Visibility'
                                   })
                               })
def update_session_coordinator_privs(event, data):
    changes = {}
    for priv, enabled in data.iteritems():
        setting = COORDINATOR_PRIV_SETTINGS[priv]
        if session_settings.get(event, setting) == enabled:
            continue
        session_settings.set(event, setting, enabled)
        changes[priv] = (not enabled, enabled)
    db.session.flush()
    logger.info('Session coordinator privs of event %r updated with %r by %r',
                event, data, session.user)
    if changes:
        log_fields = {
            priv: orig_string(title)
            for priv, title in COORDINATOR_PRIV_TITLES.iteritems()
        }
        event.log(EventLogRealm.management,
                  EventLogKind.change,
                  'Sessions',
                  'Coordinator privileges updated',
                  session.user,
                  data={'Changes': make_diff_log(changes, log_fields)})
def update_abstract(abstract, abstract_data, custom_fields_data=None):
    tracks = abstract_data.pop('submitted_for_tracks', None)
    attachments = abstract_data.pop('attachments', None)
    changes = {}

    if tracks is not None and abstract.edit_track_mode == EditTrackMode.both:
        changes.update(_update_tracks(abstract, tracks))

    if attachments:
        deleted_files = {
            f
            for f in abstract.files if f.id in attachments['deleted']
        }
        abstract.files = list(set(abstract.files) - deleted_files)
        delete_abstract_files(abstract, deleted_files)
        add_abstract_files(abstract, attachments['added'])

    changes.update(abstract.populate_from_dict(abstract_data))
    if custom_fields_data:
        changes.update(set_custom_fields(abstract, custom_fields_data))
    db.session.flush()
    logger.info('Abstract %s modified by %s', abstract, session.user)
    log_fields = {
        'title': 'Title',
        'description': 'Content',
        'submission_comment': 'Comment',
        'submitted_for_tracks': {
            'title': 'Tracks',
            'convert':
            lambda change: [sorted(t.title for t in x) for x in change]
        },
        'submitted_contrib_type': {
            'title': 'Contribution type',
            'type': 'string',
            'convert': lambda change: [t.name if t else None for t in change]
        }
    }
    for field_name, change in changes.iteritems():
        # we skip skip None -> '' changes (editing an abstract that
        # did not have a value for a new field yet without filling
        # it out)
        if not field_name.startswith('custom_') or not any(changes):
            continue
        field_id = int(field_name[7:])
        field = abstract.event.get_contribution_field(field_id)
        field_impl = field.field
        log_fields[field_name] = {
            'title':
            field.title,
            'type':
            field_impl.log_type,
            'convert':
            lambda change, field_impl=field_impl: map(
                field_impl.get_friendly_value, change)
        }
    abstract.event.log(EventLogRealm.management,
                       EventLogKind.change,
                       'Abstracts',
                       'Abstract {} modified'.format(abstract.verbose_title),
                       session.user,
                       data={'Changes': make_diff_log(changes, log_fields)})