示例#1
0
文件: events.py 项目: indico/indico
 def delete(self, reason, user=None):
     from indico.modules.events import logger, EventLogRealm, EventLogKind
     self.is_deleted = True
     signals.event.deleted.send(self, user=user)
     db.session.flush()
     logger.info('Event %r deleted [%s]', self, reason)
     self.log(EventLogRealm.event, EventLogKind.negative, 'Event', 'Event deleted', user, data={'Reason': reason})
示例#2
0
def create_event_label(data):
    event_label = EventLabel()
    event_label.populate_from_dict(data)
    db.session.add(event_label)
    db.session.flush()
    logger.info('Event label "%s" created by %s', event_label, session.user)
    return event_label
示例#3
0
def create_reference_type(data):
    reference_type = ReferenceType()
    reference_type.populate_from_dict(data)
    db.session.add(reference_type)
    db.session.flush()
    logger.info('Reference type "%s" created by %s', reference_type, session.user)
    return reference_type
示例#4
0
def update_event(event, update_timetable=False, **data):
    assert set(data.viewkeys()) <= {
        'title', 'description', 'url_shortcut', 'location_data', 'keywords',
        'person_link_data', 'start_dt', 'end_dt', 'timezone', 'keywords',
        'references', 'organizer_info', 'additional_info', 'contact_title',
        'contact_emails', 'contact_phones', 'start_dt_override',
        'end_dt_override'
    }
    old_person_links = event.person_links[:]
    if (update_timetable
            or event.type == EventType.lecture) and 'start_dt' in data:
        # Lectures have no exposed timetable so if we have any timetable entries
        # (e.g. because the event had a different type before) we always update them
        # silently.
        event.move_start_dt(data.pop('start_dt'))
    changes = event.populate_from_dict(data)
    # Person links are partially updated when the WTForms field is processed,
    # we we don't have proper change tracking there in some cases
    changes.pop('person_link_data', None)
    visible_person_link_changes = event.person_links != old_person_links
    if visible_person_link_changes or 'person_link_data' in data:
        changes['person_links'] = (old_person_links, event.person_links)
    db.session.flush()
    signals.event.updated.send(event, changes=changes)
    logger.info('Event %r updated with %r by %r', event, data, session.user)
    _log_event_update(event,
                      changes,
                      visible_person_link_changes=visible_person_link_changes)
示例#5
0
def create_event(category, event_type, data, add_creator_as_manager=True, features=None):
    """Create a new event.

    :param category: The category in which to create the event
    :param event_type: An `EventType` value
    :param data: A dict containing data used to populate the event
    :param add_creator_as_manager: Whether the creator (current user)
                                   should be added as a manager
    :param features: A list of features that will be enabled for the
                     event. If set, only those features will be used
                     and the default feature set for the event type
                     will be ignored.
    """
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    person_link_data = data.pop('person_link_data', {})
    event.populate_from_dict(data)
    db.session.flush()
    event.person_link_data = person_link_data
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    if add_creator_as_manager:
        with event.logging_disabled:
            event.update_principal(event.creator, full_access=True)
    if features is not None:
        features_event_settings.set(event, 'enabled', features)
    db.session.flush()
    signals.event.created.send(event)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user)
    db.session.flush()
    return event
示例#6
0
 def restore(self, reason=None, user=None):
     from indico.modules.events import EventLogRealm, logger
     from indico.modules.logs import LogKind
     if not self.is_deleted:
         return
     self.is_deleted = False
     signals.event.restored.send(self, user=user, reason=reason)
     db.session.flush()
     logger.info('Event %r restored [%s]', self, reason)
     data = {'Reason': reason} if reason else None
     self.log(EventLogRealm.event,
              LogKind.positive,
              'Event',
              'Event restored',
              user=user,
              data=data)
     if self.category:
         self.category.log(CategoryLogRealm.events,
                           LogKind.positive,
                           'Content',
                           f'Event restored: "{self.title}"',
                           user,
                           data={
                               'ID': self.id,
                               'Reason': reason
                           })
示例#7
0
 def delete(self, reason, user=None):
     from indico.modules.events import EventLogRealm, logger
     from indico.modules.logs import LogKind
     self.is_deleted = True
     if self.pending_move_request:
         self.pending_move_request.withdraw(user=user)
     signals.event.deleted.send(self, user=user)
     db.session.flush()
     logger.info('Event %r deleted [%s]', self, reason)
     self.log(EventLogRealm.event,
              LogKind.negative,
              'Event',
              'Event deleted',
              user,
              data={'Reason': reason})
     if self.category:
         self.category.log(CategoryLogRealm.events,
                           LogKind.negative,
                           'Content',
                           f'Event deleted: "{self.title}"',
                           user,
                           data={
                               'ID': self.id,
                               'Reason': reason
                           })
示例#8
0
def create_event(category, event_type, data, add_creator_as_manager=True, features=None):
    """Create a new event.

    :param category: The category in which to create the event
    :param event_type: An `EventType` value
    :param data: A dict containing data used to populate the event
    :param add_creator_as_manager: Whether the creator (current user)
                                   should be added as a manager
    :param features: A list of features that will be enabled for the
                     event. If set, only those features will be used
                     and the default feature set for the event type
                     will be ignored.
    """
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    person_link_data = data.pop('person_link_data', {})
    event.populate_from_dict(data)
    db.session.flush()
    event.person_link_data = person_link_data
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    if add_creator_as_manager:
        with event.logging_disabled:
            event.update_principal(event.creator, full_access=True)
    if features is not None:
        features_event_settings.set(event, 'enabled', features)
    db.session.flush()
    signals.event.created.send(event)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user)
    db.session.flush()
    return event
示例#9
0
 def delete(self, reason, user=None):
     from indico.modules.events import EventLogKind, EventLogRealm, logger
     self.is_deleted = True
     signals.event.deleted.send(self, user=user)
     db.session.flush()
     logger.info('Event %r deleted [%s]', self, reason)
     self.log(EventLogRealm.event, EventLogKind.negative, 'Event', 'Event deleted', user, data={'Reason': reason})
示例#10
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)})
示例#11
0
def create_reference_type(data):
    reference_type = ReferenceType()
    reference_type.populate_from_dict(data)
    db.session.add(reference_type)
    db.session.flush()
    logger.info('Reference type "%s" created by %s', reference_type, session.user)
    return reference_type
示例#12
0
def update_event_type(event, type_):
    if event.type_ == type_:
        return
    event.type_ = type_
    logger.info('Event %r type changed to %s by %r', event, type_.name,
                session.user)
    event.log(EventLogRealm.event, EventLogKind.change, 'Event',
              'Type changed to {}'.format(type_.title), session.user)
示例#13
0
def sort_reviewing_questions(questions, new_positions):
    questions_by_id = {q.id: q for q in questions}
    for index, new_position in enumerate(new_positions, 0):
        questions_by_id[new_position].position = index
        del questions_by_id[new_position]
    for index, field in enumerate(sorted(questions_by_id.values(), key=attrgetter('position')), len(new_positions)):
        field.position = index
    db.session.flush()
    logger.info("Reviewing questions of %r reordered by %r", questions[0].event, session.user)
示例#14
0
def sort_reviewing_questions(questions, new_positions):
    questions_by_id = {q.id: q for q in questions}
    for index, new_position in enumerate(new_positions, 0):
        questions_by_id[new_position].position = index
        del questions_by_id[new_position]
    for index, field in enumerate(sorted(questions_by_id.values(), key=attrgetter('position')), len(new_positions)):
        field.position = index
    db.session.flush()
    logger.info("Reviewing questions of %r reordered by %r", questions[0].event, session.user)
示例#15
0
文件: operations.py 项目: fph/indico
def create_event(category, event_type, data):
    from MaKaC.conference import Conference
    conf = Conference.new(category, creator=session.user, title=data.pop('title'), start_dt=data.pop('start_dt'),
                          end_dt=data.pop('end_dt'), timezone=data.pop('timezone'), event_type=event_type)
    event = conf.as_event
    theme = data.pop('theme', None)
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    event.populate_from_dict(data)
    db.session.flush()
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user)
    return event
示例#16
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)})
示例#17
0
 def restore(self, reason=None, user=None):
     from indico.modules.events import EventLogKind, EventLogRealm, logger
     if not self.is_deleted:
         return
     self.is_deleted = False
     signals.event.restored.send(self, user=user, reason=reason)
     db.session.flush()
     logger.info('Event %r restored [%s]', self, reason)
     data = {'reason': reason} if reason else None
     self.log(EventLogRealm.event,
              EventLogKind.positive,
              'Event',
              'Event restored',
              user=user,
              data=data)
示例#18
0
def create_event(category, event_type, data, add_creator_as_manager=True, features=None):
    from indico.modules.rb_new.operations.bookings import create_booking_for_event
    """Create a new event.

    :param category: The category in which to create the event
    :param event_type: An `EventType` value
    :param data: A dict containing data used to populate the event
    :param add_creator_as_manager: Whether the creator (current user)
                                   should be added as a manager
    :param features: A list of features that will be enabled for the
                     event. If set, only those features will be used
                     and the default feature set for the event type
                     will be ignored.
    """
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    create_booking = data.pop('create_booking', False)
    person_link_data = data.pop('person_link_data', {})
    event.populate_from_dict(data)
    db.session.flush()
    event.person_link_data = person_link_data
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    if add_creator_as_manager:
        with event.logging_disabled:
            event.update_principal(event.creator, full_access=True)
    if features is not None:
        features_event_settings.set(event, 'enabled', features)
    db.session.flush()
    signals.event.created.send(event)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user)
    db.session.flush()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {'Room': booking.room.full_name,
                            'Date': booking.start_dt.strftime('%d/%m/%Y'),
                            'Times': '%s - %s' % (booking.start_dt.strftime('%H:%M'), booking.end_dt.strftime('%H:%M'))}
                event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Room booked for the event',
                          session.user, data=log_data)
                db.session.flush()
    return event
示例#19
0
def create_event(category, event_type, data):
    from MaKaC.conference import Conference
    conf = Conference.new(category,
                          creator=session.user,
                          title=data.pop('title'),
                          start_dt=data.pop('start_dt'),
                          end_dt=data.pop('end_dt'),
                          timezone=data.pop('timezone'),
                          event_type=event_type)
    event = conf.as_event
    theme = data.pop('theme', None)
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    event.populate_from_dict(data)
    db.session.flush()
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event',
              'Event created', session.user)
    return event
示例#20
0
def update_event(event, update_timetable=False, **data):
    assert set(data.viewkeys()) <= {'title', 'description', 'url_shortcut', 'location_data', 'keywords',
                                    'person_link_data', 'start_dt', 'end_dt', 'timezone', 'keywords', 'references',
                                    'organizer_info', 'additional_info', 'contact_title', 'contact_emails',
                                    'contact_phones', 'start_dt_override', 'end_dt_override'}
    old_person_links = event.person_links[:]
    if (update_timetable or event.type == EventType.lecture) and 'start_dt' in data:
        # Lectures have no exposed timetable so if we have any timetable entries
        # (e.g. because the event had a different type before) we always update them
        # silently.
        event.move_start_dt(data.pop('start_dt'))
    changes = event.populate_from_dict(data)
    # Person links are partially updated when the WTForms field is processed,
    # we we don't have proper change tracking there in some cases
    changes.pop('person_link_data', None)
    visible_person_link_changes = event.person_links != old_person_links
    if visible_person_link_changes or 'person_link_data' in data:
        changes['person_links'] = (old_person_links, event.person_links)
    db.session.flush()
    signals.event.updated.send(event, changes=changes)
    logger.info('Event %r updated with %r by %r', event, data, session.user)
    _log_event_update(event, changes, visible_person_link_changes=visible_person_link_changes)
示例#21
0
def delete_event(event):
    event.as_legacy.delete(session.user)
    db.session.flush()
    logger.info('Event %r deleted by %r', event, session.user)
示例#22
0
def create_event(category,
                 event_type,
                 data,
                 add_creator_as_manager=True,
                 features=None,
                 cloning=False):
    """Create a new event.

    :param category: The category in which to create the event
    :param event_type: An `EventType` value
    :param data: A dict containing data used to populate the event
    :param add_creator_as_manager: Whether the creator (current user)
                                   should be added as a manager
    :param features: A list of features that will be enabled for the
                     event. If set, only those features will be used
                     and the default feature set for the event type
                     will be ignored.
    :param cloning: Whether the event is created via cloning or not
    """
    from indico.modules.rb.operations.bookings import create_booking_for_event
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    create_booking = data.pop('create_booking', False)
    person_link_data = data.pop('person_link_data', {})
    event.populate_from_dict(data)
    db.session.flush()
    event.person_link_data = person_link_data
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    if add_creator_as_manager:
        with event.logging_disabled:
            event.update_principal(event.creator, full_access=True)
    if features is not None:
        features_event_settings.set(event, 'enabled', features)
    db.session.flush()
    signals.event.created.send(event, cloning=cloning)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    sep = ' \N{RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK} '
    event.log(EventLogRealm.event,
              LogKind.positive,
              'Event',
              'Event created',
              session.user,
              data={
                  'Category':
                  sep.join(category.chain_titles) if category else None
              })
    if category:
        category.log(CategoryLogRealm.events,
                     LogKind.positive,
                     'Content',
                     f'Event created: "{event.title}"',
                     session.user,
                     data={
                         'ID': event.id,
                         'Type': orig_string(event.type_.title)
                     })
    db.session.flush()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {
                    'Room':
                    booking.room.full_name,
                    'Date':
                    booking.start_dt.strftime('%d/%m/%Y'),
                    'Times':
                    '{} - {}'.format(booking.start_dt.strftime('%H:%M'),
                                     booking.end_dt.strftime('%H:%M'))
                }
                event.log(EventLogRealm.event,
                          LogKind.positive,
                          'Event',
                          'Room booked for the event',
                          session.user,
                          data=log_data)
                db.session.flush()
    return event
示例#23
0
def update_event_label(event_label, data):
    event_label.populate_from_dict(data)
    db.session.flush()
    logger.info('Event label "%s" updated by %s', event_label, session.user)
示例#24
0
def update_event(event, data):
    event.populate_from_dict(data)
    db.session.flush()
    signals.event.updated.send(event)
    logger.info('Event %r updated with %r', event, data)
示例#25
0
def update_reference_type(reference_type, data):
    reference_type.populate_from_dict(data)
    db.session.flush()
    logger.info('Reference type "%s" updated by %s', reference_type,
                session.user)
示例#26
0
def create_event_references(event, data):
    event.references = data['references']
    db.session.flush()
    for reference in event.references:
        logger.info('Reference "%s" created by %s', reference, session.user)
示例#27
0
def delete_event(event):
    event.as_legacy.delete(session.user)
    db.session.flush()
    logger.info('Event %r deleted by %r', event, session.user)
示例#28
0
def update_reviewing_question(question, form):
    question.field.update_object(form.data)
    form.populate_obj(question)
    db.session.flush()
    logger.info("Reviewing question %r updated by %r", question, session.user)
示例#29
0
def update_reviewing_question(question, form):
    question.field.update_object(form.data)
    form.populate_obj(question)
    db.session.flush()
    logger.info("Reviewing question %r updated by %r", question, session.user)
示例#30
0
def delete_reviewing_question(question):
    question.is_deleted = True
    db.session.flush()
    logger.info("Reviewing question %r deleted by %r", question, session.user)
示例#31
0
def unlock_event(event):
    event.is_locked = False
    db.session.flush()
    logger.info('Event %r unlocked by %r', event, session.user)
    event.log(EventLogRealm.event, EventLogKind.change, 'Event', 'Event unlocked', session.user)
示例#32
0
def update_event_type(event, type_):
    if event.type_ == type_:
        return
    event.type_ = type_
    logger.info('Event %r type changed to %s by %r', event, type_.name, session.user)
    event.log(EventLogRealm.event, EventLogKind.change, 'Event', 'Type changed to {}'.format(type_.title), session.user)
示例#33
0
def update_event(event, data):
    event.populate_from_dict(data)
    db.session.flush()
    logger.info("Event %r updated with %r", event, data)
示例#34
0
def lock_event(event):
    event.is_locked = True
    db.session.flush()
    logger.info('Event %r locked by %r', event, session.user)
    event.log(EventLogRealm.event, LogKind.change, 'Event', 'Event locked',
              session.user)
示例#35
0
def update_event(event, data):
    event.populate_from_dict(data)
    db.session.flush()
    signals.event.updated.send(event)
    logger.info('Event %r updated with %r', event, data)
示例#36
0
def unlock_event(event):
    event.is_locked = False
    db.session.flush()
    logger.info('Event %r unlocked by %r', event, session.user)
    event.log(EventLogRealm.event, EventLogKind.change, 'Event',
              'Event unlocked', session.user)
示例#37
0
def update_reference_type(reference_type, data):
    reference_type.populate_from_dict(data)
    db.session.flush()
    logger.info('Reference type "%s" updated by %s', reference_type, session.user)
示例#38
0
def delete_reviewing_question(question):
    question.is_deleted = True
    db.session.flush()
    logger.info("Reviewing question %r deleted by %r", question, session.user)
示例#39
0
def delete_reference_type(reference_type):
    db.session.delete(reference_type)
    db.session.flush()
    logger.info('Reference type "%s" deleted by %s', reference_type, session.user)
示例#40
0
def delete_reference_type(reference_type):
    db.session.delete(reference_type)
    db.session.flush()
    logger.info('Reference type "%s" deleted by %s', reference_type,
                session.user)
示例#41
0
def create_event_references(event, data):
    event.references = data['references']
    db.session.flush()
    for reference in event.references:
        logger.info('Reference "%s" created by %s', reference, session.user)
示例#42
0
def create_event(category,
                 event_type,
                 data,
                 add_creator_as_manager=True,
                 features=None):
    from indico.modules.rb.operations.bookings import create_booking_for_event
    """Create a new event.

    :param category: The category in which to create the event
    :param event_type: An `EventType` value
    :param data: A dict containing data used to populate the event
    :param add_creator_as_manager: Whether the creator (current user)
                                   should be added as a manager
    :param features: A list of features that will be enabled for the
                     event. If set, only those features will be used
                     and the default feature set for the event type
                     will be ignored.
    """
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    create_booking = data.pop('create_booking', False)
    person_link_data = data.pop('person_link_data', {})
    event.populate_from_dict(data)
    db.session.flush()
    event.person_link_data = person_link_data
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    if add_creator_as_manager:
        with event.logging_disabled:
            event.update_principal(event.creator, full_access=True)
    if features is not None:
        features_event_settings.set(event, 'enabled', features)
    db.session.flush()
    signals.event.created.send(event)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event',
              'Event created', session.user)
    db.session.flush()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {
                    'Room':
                    booking.room.full_name,
                    'Date':
                    booking.start_dt.strftime('%d/%m/%Y'),
                    'Times':
                    '%s - %s' % (booking.start_dt.strftime('%H:%M'),
                                 booking.end_dt.strftime('%H:%M'))
                }
                event.log(EventLogRealm.event,
                          EventLogKind.positive,
                          'Event',
                          'Room booked for the event',
                          session.user,
                          data=log_data)
                db.session.flush()
    return event
示例#43
0
def delete_event_label(event_label):
    db.session.delete(event_label)
    db.session.flush()
    logger.info('Event label "%s" deleted by %s', event_label, session.user)