Пример #1
0
    def migrate_event_notes(self):
        self.print_step('migrating event notes')

        janitor_user = User.get_one(self.janitor_user_id)
        self.print_msg('Using janitor user {}'.format(janitor_user), always=True)
        for event, obj, minutes, special_prot in committing_iterator(self._iter_minutes()):
            if special_prot:
                self.print_warning(
                    cformat('%{yellow!}{} minutes have special permissions; skipping them').format(obj),
                    event_id=event.id
                )
                continue
            path = get_archived_file(minutes, self.archive_dirs)[1]
            if path is None:
                self.print_error(cformat('%{red!}{} minutes not found on disk; skipping them').format(obj),
                                 event_id=event.id)
                continue
            with open(path, 'r') as f:
                data = convert_to_unicode(f.read()).strip()
            if not data:
                self.print_warning(cformat('%{yellow}{} minutes are empty; skipping them').format(obj),
                                   always=False, event_id=event.id)
                continue
            note = EventNote(linked_object=obj)
            note.create_revision(RenderMode.html, data, janitor_user)
            db.session.add(note)
            if not self.quiet:
                self.print_success(cformat('%{cyan}{}').format(obj), event_id=event.id)
Пример #2
0
    def migrate_event_notes(self):
        self.print_step('migrating event notes')

        janitor_user = User.get_one(self.janitor_user_id)
        self.print_msg('Using janitor user {}'.format(janitor_user), always=True)
        for event, obj, minutes, special_prot in committing_iterator(self._iter_minutes()):
            if special_prot:
                self.print_warning(
                    cformat('%{yellow!}{} minutes have special permissions; skipping them').format(obj),
                    event_id=event.id
                )
                continue
            path = get_archived_file(minutes, self.archive_dirs)[1]
            if path is None:
                self.print_error(cformat('%{red!}{} minutes not found on disk; skipping them').format(obj),
                                 event_id=event.id)
                continue
            with open(path, 'r') as f:
                data = convert_to_unicode(f.read()).strip()
            if not data:
                self.print_warning(cformat('%{yellow}{} minutes are empty; skipping them').format(obj),
                                   always=False, event_id=event.id)
                continue
            note = EventNote(linked_object=obj)
            note.create_revision(RenderMode.html, data, janitor_user)
            db.session.add(note)
            if not self.quiet:
                self.print_success(cformat('%{cyan}{}').format(obj), event_id=event.id)
Пример #3
0
 def clone(self, new_event, options):
     from indico.modules.events.notes.models.notes import EventNote
     if 'notes' not in options:
         return
     for old_note in self.find_notes():
         revision = old_note.current_revision
         new_note = EventNote(link_type=old_note.link_type,
                              event_id=new_event.id,
                              session_id=old_note.session_id,
                              contribution_id=old_note.contribution_id,
                              subcontribution_id=old_note.subcontribution_id)
         new_note.create_revision(render_mode=revision.render_mode,
                                  source=revision.source,
                                  user=revision.user)
         db.session.add(new_note)
         db.session.flush()
         logger.info('Added note during event cloning: {}'.format(new_note))
Пример #4
0
 def clone(self, new_event, options):
     from indico.modules.events.notes.models.notes import EventNote
     if 'notes' not in options:
         return
     for old_note in self.find_notes():
         revision = old_note.current_revision
         new_note = EventNote(link_type=old_note.link_type,
                              event_id=new_event.id,
                              session_id=old_note.session_id,
                              contribution_id=old_note.contribution_id,
                              subcontribution_id=old_note.subcontribution_id)
         new_note.create_revision(render_mode=revision.render_mode,
                                  source=revision.source,
                                  user=revision.user)
         db.session.add(new_note)
         db.session.flush()
         logger.info('Added note during event cloning: {}'.format(new_note))
Пример #5
0
 def migrate(self):
     for obj, minutes, special_prot in self._iter_minutes():
         if special_prot:
             self.print_warning('%[yellow!]{} minutes have special permissions; skipping them'.format(obj))
             continue
         path = get_archived_file(minutes, self.archive_dirs)[1]
         if path is None:
             self.print_error('%[red!]{} minutes not found on disk; skipping them'.format(obj))
             continue
         with open(path, 'r') as f:
             data = convert_to_unicode(f.read()).strip()
         if not data:
             self.print_warning('%[yellow]{} minutes are empty; skipping them'.format(obj), always=False)
             continue
         note = EventNote(object=obj)
         note.create_revision(RenderMode.html, data, self.system_user)
         if not self.quiet:
             self.print_success('%[cyan]{}'.format(obj))
Пример #6
0
def test_dump_event_note(db, dummy_user, dummy_event, dummy_contribution,
                         link_type):
    from .schemas import EventNoteRecordSchema

    if link_type == 'event':
        ids = {}
        note = EventNote(object=dummy_event)
        url = '/event/0/note/'
    elif link_type == 'contrib':
        ids = {'contribution_id': dummy_contribution.id}
        note = EventNote(object=dummy_contribution)
        url = f'/event/0/contributions/{dummy_contribution.id}/note/'
    elif link_type == 'subcontrib':
        subcontribution = SubContribution(contribution=dummy_contribution,
                                          title='Dummy Subcontribution',
                                          duration=timedelta(minutes=10))
        db.session.flush()
        ids = {
            'contribution_id': subcontribution.contribution_id,
            'subcontribution_id': subcontribution.id,
        }
        note = EventNote(object=subcontribution)
        url = f'/event/0/contributions/{dummy_contribution.id}/subcontributions/{subcontribution.id}/note/'

    note.create_revision(RenderMode.html,
                         'this is a dummy <strong>note</strong>', dummy_user)
    db.session.flush()
    category_id = dummy_event.category_id
    schema = EventNoteRecordSchema(context={'schema': 'test-notes'})
    assert schema.dump(note) == {
        '$schema':
        'test-notes',
        '_access': {
            'delete': ['IndicoAdmin'],
            'owner': ['IndicoAdmin'],
            'update': ['IndicoAdmin'],
        },
        '_data': {
            'content': 'this is a dummy note',
            'site': 'http://localhost',
            'title': note.object.title,
            'persons': {
                'name': 'Guinea Pig'
            }
        },
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'modified_dt':
        note.current_revision.created_dt.isoformat(),
        'event_id':
        0,
        'note_id':
        note.id,
        'type':
        'event_note',
        'url':
        f'http://localhost{url}',
        **ids
    }
Пример #7
0
def test_dump_event_note(db, dummy_user, dummy_event, dummy_contribution,
                         link_type):
    from indico.modules.search.schemas import EventNoteSchema

    if link_type == 'event':
        ids = {'contribution_id': None, 'subcontribution_id': None}
        note = EventNote(object=dummy_event)
        url = '/event/0/note/'
    elif link_type == 'contrib':
        ids = {
            'contribution_id': dummy_contribution.id,
            'subcontribution_id': None
        }
        note = EventNote(object=dummy_contribution)
        url = f'/event/0/contributions/{dummy_contribution.id}/note/'
    elif link_type == 'subcontrib':
        subcontribution = SubContribution(contribution=dummy_contribution,
                                          title='Dummy Subcontribution',
                                          duration=timedelta(minutes=10))
        db.session.flush()
        ids = {
            'contribution_id': subcontribution.contribution_id,
            'subcontribution_id': subcontribution.id,
        }
        note = EventNote(object=subcontribution)
        url = f'/event/0/contributions/{dummy_contribution.id}/subcontributions/{subcontribution.id}/note/'

    note.create_revision(RenderMode.html, 'this is a dummy note', dummy_user)
    db.session.flush()
    category_id = dummy_event.category_id
    schema = EventNoteSchema()
    assert schema.dump(note) == {
        'content':
        'this is a dummy note',
        'user': {
            'affiliation': None,
            'name': 'Guinea Pig'
        },
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'modified_dt':
        note.current_revision.created_dt.isoformat(),
        'event_id':
        0,
        'note_id':
        note.id,
        'title':
        note.object.title,
        'type':
        'event_note',
        'url':
        url,
        **ids
    }