Beispiel #1
0
 def _clone_person_links(self, new_event):
     attrs = get_simple_column_attrs(EventPersonLink)
     for old_link in self.old_event.person_links:
         link = EventPersonLink()
         link.populate_from_attrs(old_link, attrs)
         link.person = self._person_map[old_link.person]
         new_event.person_links.append(link)
Beispiel #2
0
 def _clone_person_links(self, new_event):
     attrs = get_simple_column_attrs(EventPersonLink)
     for old_link in self.old_event.person_links:
         link = EventPersonLink()
         link.populate_from_attrs(old_link, attrs)
         link.person = self._person_map[old_link.person]
         new_event.person_links.append(link)
Beispiel #3
0
def test_dump_event(db, dummy_user, dummy_event):
    from indico.modules.search.schemas import EventSchema
    schema = EventSchema()
    dummy_event.description = 'A dummy event'
    dummy_event.keywords = ['foo', 'bar']
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person2 = EventPerson(event=dummy_event,
                          first_name='Admin',
                          last_name='Saurus',
                          affiliation='Indico')
    dummy_event.person_links.append(EventPersonLink(person=person))
    dummy_event.person_links.append(EventPersonLink(person=person2))
    db.session.flush()
    category_id = dummy_event.category_id
    assert schema.dump(dummy_event) == {
        'description':
        'A dummy event',
        'keywords': ['foo', 'bar'],
        'location': {
            'address': '',
            'room_name': '',
            'venue_name': ''
        },
        'persons': [{
            'affiliation': None,
            'name': 'Guinea Pig'
        }, {
            'affiliation': 'Indico',
            'name': 'Admin Saurus'
        }],
        'title':
        'dummy#0',
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'end_dt':
        dummy_event.end_dt.isoformat(),
        'event_id':
        0,
        'start_dt':
        dummy_event.start_dt.isoformat(),
        'type':
        'event',
        'event_type':
        'meeting',
        'url':
        '/event/0/',
    }
Beispiel #4
0
 def _copy_person_link_data(link_data):
     # Copy person link data since we would otherwise end up
     # adding the EventPersons of the first event in all other
     # events of the series.
     for link, submitter in link_data.iteritems():
         link_copy = EventPersonLink(**{col: getattr(link, col)
                                        for col in get_simple_column_attrs(EventPersonLink)})
         link_copy.person = EventPerson(**{col: getattr(link.person, col)
                                           for col in get_simple_column_attrs(EventPerson)})
         yield link_copy, submitter
Beispiel #5
0
 def _copy_person_link_data(link_data):
     # Copy person link data since we would otherwise end up
     # adding the EventPersons of the first event in all other
     # events of the series.
     for link, submitter in link_data.items():
         link_copy = EventPersonLink(**{col: getattr(link, col)
                                        for col in get_simple_column_attrs(EventPersonLink)})
         link_copy.person = EventPerson(**{col: getattr(link.person, col)
                                           for col in get_simple_column_attrs(EventPerson)})
         link_copy.person.user = link.person.user
         yield link_copy, submitter
Beispiel #6
0
def test_unused_event_person(db, dummy_user, dummy_event, create_contribution,
                             create_subcontribution, create_abstract):
    person = EventPerson.create_from_user(dummy_user, event=dummy_event)
    assert not person.has_links

    dummy_event.person_links.append(EventPersonLink(person=person))
    db.session.flush()
    assert person.has_links

    dummy_event.person_links.clear()
    db.session.flush()
    assert not person.has_links

    set_feature_enabled(dummy_event, 'abstracts', True)
    abstract = create_abstract(dummy_event,
                               'Dummy abstract',
                               submitter=dummy_user,
                               person_links=[
                                   AbstractPersonLink(
                                       person=person,
                                       is_speaker=True,
                                       author_type=AuthorType.primary)
                               ])
    assert person.has_links
    abstract.is_deleted = True
    assert not person.has_links

    contrib = create_contribution(
        dummy_event,
        'Dummy contribution',
        person_links=[ContributionPersonLink(person=person, is_speaker=True)])
    assert person.has_links
    contrib.is_deleted = True
    assert not person.has_links
    db.session.delete(contrib)

    contrib = create_contribution(dummy_event,
                                  'Dummy contribution',
                                  person_links=[])
    assert not person.has_links
    create_subcontribution(contrib,
                           'Dummy subcontribution',
                           person_links=[
                               SubContributionPersonLink(person=person,
                                                         is_speaker=True)
                           ])
    assert person.has_links

    contrib.is_deleted = True
    assert not person.has_links

    db.session.delete(contrib)
    assert not person.has_links
Beispiel #7
0
 def _migrate_event_persons_links(self):
     person_link_map = {}
     for chair in getattr(self.conf, '_chairs', []):
         person = self._get_person(chair)
         if not person:
             continue
         link = person_link_map.get(person)
         if link:
             self.print_warning('%[yellow!]Duplicated chair "{}" for event'.format(person.full_name))
         else:
             link = EventPersonLink(person=person, **self._get_person_data(chair))
             person_link_map[person] = link
             self.event.person_links.append(link)
Beispiel #8
0
def test_submitter_permissions(app, db, dummy_event, dummy_user):
    from indico.modules.events.persons.schemas import PersonLinkSchema
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person_link = EventPersonLink(person=person)
    dummy_event.person_links = [person_link]
    dummy_event.update_principal(person_link.person.principal,
                                 add_permissions={'submit'})
    with app.test_request_context():
        form = MockForm(event=dummy_event)
    form.person_link_data.data = dummy_event.person_links
    # Remove all persons
    form.person_link_data.process_formdata(['[]'])
    dummy_event.person_link_data = form.person_link_data.data
    db.session.flush()
    assert person.has_role('submit', dummy_event) is False
    # Serialize a person_link with a submitter role
    input_person = PersonLinkSchema().dump(person_link)
    input_person['roles'] = ['submitter']
    form.person_link_data.process_formdata([json.dumps([input_person])])
    dummy_event.person_link_data = form.person_link_data.data
    db.session.flush()
    assert person.has_role('submit', dummy_event) is True
Beispiel #9
0
def test_dump_event(db, dummy_user, dummy_event):
    from .schemas import EventRecordSchema

    schema = EventRecordSchema(context={'schema': 'test-events'})
    dummy_event.description = 'A dummy <strong>event</strong>'
    dummy_event.keywords = ['foo', 'bar']
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person2 = EventPerson(event=dummy_event,
                          first_name='Admin',
                          last_name='Saurus',
                          affiliation='Indico')
    dummy_event.person_links.append(EventPersonLink(person=person))
    dummy_event.person_links.append(EventPersonLink(person=person2))
    db.session.flush()
    category_id = dummy_event.category_id
    assert schema.dump(dummy_event) == {
        '$schema':
        'test-events',
        '_access': {
            'delete': ['IndicoAdmin'],
            'owner': ['IndicoAdmin'],
            'update': ['IndicoAdmin'],
        },
        '_data': {
            'description':
            'A dummy event',
            'keywords': ['foo', 'bar'],
            'location': {
                'address': '',
                'room_name': '',
                'venue_name': ''
            },
            'persons': [{
                'name': 'Guinea Pig'
            }, {
                'affiliation': 'Indico',
                'name': 'Admin Saurus'
            }],
            'site':
            'http://localhost',
            'title':
            'dummy#0'
        },
        'category_id':
        1,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'end_dt':
        dummy_event.end_dt.isoformat(),
        'event_id':
        0,
        'start_dt':
        dummy_event.start_dt.isoformat(),
        'type':
        'event',
        'type_format':
        'meeting',
        'url':
        'http://localhost/event/0/',
    }