예제 #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 test_acls(dummy_event, dummy_contribution, dummy_user, create_user,
              obj_type):
    from .schemas import ACLSchema

    class TestSchema(ACLSchema, mm.Schema):
        pass

    if obj_type == 'event':
        obj = dummy_event
    elif obj_type == 'contrib':
        obj = dummy_contribution
    elif obj_type == 'subcontrib':
        obj = SubContribution(contribution=dummy_contribution,
                              title='Test',
                              duration=timedelta(minutes=10))
    elif obj_type == 'attachment':
        folder = AttachmentFolder(title='Dummy Folder',
                                  description='a dummy folder')
        obj = Attachment(folder=folder,
                         user=dummy_user,
                         title='Dummy Attachment',
                         type=AttachmentType.link,
                         link_url='https://example.com')
        obj.folder.object = dummy_event
    elif obj_type == 'note':
        obj = EventNote(object=dummy_event)
        obj.create_revision(RenderMode.html, 'this is a dummy note',
                            dummy_user)

    def assert_acl(expected_read_acl):
        __tracebackhide__ = True
        data = schema.dump(obj)
        read_acl = data['_access'].pop('read', None)
        assert data == {
            '_access': {
                'delete': ['IndicoAdmin'],
                'owner': ['IndicoAdmin'],
                'update': ['IndicoAdmin']
            }
        }
        if read_acl is not None:
            read_acl = set(read_acl)
        assert read_acl == expected_read_acl

    schema = TestSchema()
    user = create_user(1, email='*****@*****.**')

    # everything is public
    assert_acl(None)

    # event is protected and the acl is empty (nobody has regular access)
    dummy_event.protection_mode = ProtectionMode.protected
    assert_acl({'IndicoAdmin'})

    # user on the acl has access
    dummy_event.update_principal(user, read_access=True)
    assert_acl({'IndicoAdmin', 'User:1'})
예제 #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 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))
예제 #5
0
 def _clone_note(self, old_note, new_object):
     revision = old_note.current_revision
     new_object.note = EventNote()
     new_object.note.create_revision(render_mode=revision.render_mode,
                                     source=revision.source,
                                     user=revision.user)
예제 #6
0
def note(db, dummy_event):
    note = EventNote(object=dummy_event)
    db.session.expunge(
        note
    )  # keep it out of the SA session (linking it to the event adds it)
    return note
예제 #7
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
    }
예제 #8
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
    }