Exemplo n.º 1
0
 def testModifyLinks(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Add a new role for an existing event
     avatar_links.add_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager', 'conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Delete a role from an event with multiple roles
     avatar_links.del_link(self._avatar1, self._event1, 'conference_participant', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Delete a role from an event with just one role
     avatar_links.del_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Add a role for a new event
     avatar_links.add_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
Exemplo n.º 2
0
    def testLinkModificationsOnlyAffectCorrectAvatar(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1,
                                client=self._redis,
                                assumeEvents=True)
        avatar_links.init_links(self._avatar2,
                                client=self._redis,
                                assumeEvents=True)

        # No change may touch other avatars
        links = avatar_links.get_links(self._avatar2, client=self._redis)
        avatar_links.add_link(self._avatar1,
                              self._event1,
                              'foo',
                              client=self._redis)
        self.assertEqual(
            links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.del_link(self._avatar1,
                              self._event4,
                              'conference_manager',
                              client=self._redis)
        self.assertEqual(
            links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.del_link(self._avatar1,
                              self._event4,
                              'conference_participant',
                              client=self._redis)
        self.assertEqual(
            links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.delete_avatar(self._avatar1, client=self._redis)
        self.assertEqual(
            links, avatar_links.get_links(self._avatar2, client=self._redis))
Exemplo n.º 3
0
 def testModifyLinks(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Add a new role for an existing event
     avatar_links.add_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager', 'conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Delete a role from an event with multiple roles
     avatar_links.del_link(self._avatar1, self._event1, 'conference_participant', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Delete a role from an event with just one role
     avatar_links.del_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
     # Add a role for a new event
     avatar_links.add_link(self._avatar1, self._event1, 'conference_manager', client=self._redis)
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
Exemplo n.º 4
0
 def testDeleteAvatar(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     keys = frozenset(self._redis.keys())
     links = avatar_links.get_links(self._avatar1, client=self._redis)
     avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)
     avatar_links.delete_avatar(self._avatar2, client=self._redis)
     self.assertEqual(keys, frozenset(self._redis.keys()))
     self.assertEqual(links, avatar_links.get_links(self._avatar1, client=self._redis))
Exemplo n.º 5
0
 def testDeleteAvatar(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     keys = frozenset(self._redis.keys())
     links = avatar_links.get_links(self._avatar1, client=self._redis)
     avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)
     avatar_links.delete_avatar(self._avatar2, client=self._redis)
     self.assertEqual(keys, frozenset(self._redis.keys()))
     self.assertEqual(links, avatar_links.get_links(self._avatar1, client=self._redis))
Exemplo n.º 6
0
    def testImport(self):
        self.assertFalse(self._redis.keys())
        self._createDummies()

        avatar_links.init_links(self._avatar1,
                                client=self._redis,
                                assumeEvents=True)
        self.assertEqual(
            frozenset(self._redis.keys()),
            frozenset([
                'avatar-event-links/avatar_events:1',
                'avatar-event-links/event_avatars:2',
                'avatar-event-links/event_avatars:3',
                'avatar-event-links/event_avatars:1',
                'avatar-event-links/event_avatars:4',
                'avatar-event-links/avatar_event_roles:1:4',
                'avatar-event-links/avatar_event_roles:1:3',
                'avatar-event-links/avatar_event_roles:1:2',
                'avatar-event-links/avatar_event_roles:1:1'
            ]))

        avatar_links.init_links(self._avatar2,
                                client=self._redis,
                                assumeEvents=True)
        self.assertEqual(
            frozenset(self._redis.keys()),
            frozenset([
                'avatar-event-links/avatar_events:1',
                'avatar-event-links/avatar_events:2',
                'avatar-event-links/event_avatars:2',
                'avatar-event-links/event_avatars:3',
                'avatar-event-links/event_avatars:1',
                'avatar-event-links/event_avatars:4',
                'avatar-event-links/avatar_event_roles:1:4',
                'avatar-event-links/avatar_event_roles:1:3',
                'avatar-event-links/avatar_event_roles:1:2',
                'avatar-event-links/avatar_event_roles:1:1',
                'avatar-event-links/avatar_event_roles:2:4',
                'avatar-event-links/avatar_event_roles:2:3',
                'avatar-event-links/avatar_event_roles:2:1'
            ]))

        self.assertEqual(
            avatar_links.get_links(self._avatar1, client=self._redis),
            OrderedDict([('2', set(['conference_participant'])),
                         ('1', set(['conference_participant'])),
                         ('4',
                          set(['conference_manager',
                               'conference_participant'])),
                         ('3', set(['conference_manager']))]))

        self.assertEqual(
            avatar_links.get_links(self._avatar2, client=self._redis),
            OrderedDict([('1', set(['conference_manager'])),
                         ('4', set(['conference_manager'])),
                         ('3', set(['conference_manager']))]))
Exemplo n.º 7
0
 def testMergeAvatars(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     keys = frozenset(self._redis.keys())
     avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)
     avatar_links.merge_avatars(self._avatar1, self._avatar2, client=self._redis)
     self.assertEqual(keys, frozenset(self._redis.keys()))
     self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis), OrderedDict())
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager', 'conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
Exemplo n.º 8
0
 def testMergeAvatars(self):
     self._createDummies()
     avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
     keys = frozenset(self._redis.keys())
     avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)
     avatar_links.merge_avatars(self._avatar1, self._avatar2, client=self._redis)
     self.assertEqual(keys, frozenset(self._redis.keys()))
     self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis), OrderedDict())
     self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                      OrderedDict([('2', set(['conference_participant'])),
                                   ('1', set(['conference_manager', 'conference_participant'])),
                                   ('4', set(['conference_manager', 'conference_participant'])),
                                   ('3', set(['conference_manager']))]))
Exemplo n.º 9
0
    def testLinkModificationsOnlyAffectCorrectAvatar(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
        avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)

        # No change may touch other avatars
        links = avatar_links.get_links(self._avatar2, client=self._redis)
        avatar_links.add_link(self._avatar1, self._event1, 'foo', client=self._redis)
        self.assertEqual(links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.del_link(self._avatar1, self._event4, 'conference_manager', client=self._redis)
        self.assertEqual(links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.del_link(self._avatar1, self._event4, 'conference_participant', client=self._redis)
        self.assertEqual(links, avatar_links.get_links(self._avatar2, client=self._redis))
        avatar_links.delete_avatar(self._avatar1, client=self._redis)
        self.assertEqual(links, avatar_links.get_links(self._avatar2, client=self._redis))
Exemplo n.º 10
0
def get_linked_events(user, from_dt, to_dt, limit=None):
    """Get the linked events and the user's roles in them"""
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (get_events_managed_by, get_events_created_by,
                                            get_events_with_linked_event_persons)

    links = avatar_links.get_links(user, from_dt, to_dt) if redis_client else OrderedDict()
    for event_id in get_events_registered(user, from_dt, to_dt):
        links.setdefault(str(event_id), set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, from_dt, to_dt):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, from_dt, to_dt):
        links.setdefault(str(event_id), set()).add('conference_manager')
    for event_id in get_events_created_by(user, from_dt, to_dt):
        links.setdefault(str(event_id), set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(user, from_dt, to_dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(user, from_dt, to_dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id in get_events_with_linked_event_persons(user, from_dt, to_dt):
        links.setdefault(str(event_id), set()).add('conference_chair')

    query = (Event.query
             .filter(~Event.is_deleted,
                     Event.id.in_(map(int, links)))
             .options(joinedload('series'),
                      load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                                'series_id', 'series_pos', 'series_count'))
             .order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return OrderedDict((event, links[str(event.id)]) for event in query)
Exemplo n.º 11
0
 def export_linked_events(self, aw):
     if not redis_client:
         raise HTTPAPIError('This API is only available when using Redis')
     self._checkProtection(aw)
     links = avatar_links.get_links(self._avatar.user, self._fromDT,
                                    self._toDT)
     for event_id in get_events_registered(self._avatar.user, self._fromDT,
                                           self._toDT):
         links.setdefault(str(event_id),
                          set()).add('registration_registrant')
     for event_id in get_events_with_submitted_surveys(
             self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('survey_submitter')
     for event_id in get_events_managed_by(self._avatar.user, self._fromDT,
                                           self._toDT):
         links.setdefault(str(event_id), set()).add('conference_manager')
     for event_id in get_events_created_by(self._avatar.user, self._fromDT,
                                           self._toDT):
         links.setdefault(str(event_id), set()).add('conference_creator')
     for event_id, principal_roles in get_events_with_linked_sessions(
             self._avatar.user, self._fromDT, self._toDT).iteritems():
         links.setdefault(str(event_id), set()).update(principal_roles)
     for event_id, principal_roles in get_events_with_linked_contributions(
             self._avatar.user, self._fromDT, self._toDT).iteritems():
         links.setdefault(str(event_id), set()).update(principal_roles)
     for event_id in get_events_with_linked_event_persons(
             self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('conference_chair')
     return UserRelatedEventFetcher(aw, self, links).events(links.keys())
Exemplo n.º 12
0
    def testTimeFilter(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)

        # Stupid values that always result in no results
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=99999999, client=self._redis),
                         OrderedDict())
        self.assertEqual(avatar_links.get_links(self._avatar1, maxDT=0, client=self._redis),
                         OrderedDict())
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=200000, maxDT=0, client=self._redis),
                         OrderedDict())
        # Only a minimum
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=150000, client=self._redis),
                         OrderedDict([('4', set(['conference_manager', 'conference_participant'])),
                                      ('3', set(['conference_manager']))]))
        # Only a maximum
        self.assertEqual(avatar_links.get_links(self._avatar1, maxDT=150000, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant']))]))
        # Both minimum and maximum
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=100000, maxDT=150000, client=self._redis),
                         OrderedDict([('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant']))]))
        # Same value for both
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=150000, maxDT=150000, client=self._redis),
                         OrderedDict([('4', set(['conference_manager', 'conference_participant']))]))
Exemplo n.º 13
0
    def testTimeFilter(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)

        # Stupid values that always result in no results
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=99999999, client=self._redis),
                         OrderedDict())
        self.assertEqual(avatar_links.get_links(self._avatar1, maxDT=0, client=self._redis),
                         OrderedDict())
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=200000, maxDT=0, client=self._redis),
                         OrderedDict())
        # Only a minimum
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=150000, client=self._redis),
                         OrderedDict([('4', set(['conference_manager', 'conference_participant'])),
                                      ('3', set(['conference_manager']))]))
        # Only a maximum
        self.assertEqual(avatar_links.get_links(self._avatar1, maxDT=150000, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant']))]))
        # Both minimum and maximum
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=100000, maxDT=150000, client=self._redis),
                         OrderedDict([('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant']))]))
        # Same value for both
        self.assertEqual(avatar_links.get_links(self._avatar1, minDT=150000, maxDT=150000, client=self._redis),
                         OrderedDict([('4', set(['conference_manager', 'conference_participant']))]))
Exemplo n.º 14
0
    def export_linked_events(self, aw):
        if not redis_client:
            raise HTTPAPIError('This API is only available when using Redis')
        self._checkProtection(aw)
        links = avatar_links.get_links(self._avatar.user, self._fromDT, self._toDT)

        for event_id in get_events_with_submitted_surveys(self._avatar.user, self._fromDT, self._toDT):
            links.setdefault(str(event_id), set()).add('survey_submitter')
        return UserRelatedEventFetcher(aw, self, links).events(links.keys())
Exemplo n.º 15
0
def get_linked_events(user, dt, limit=None):
    """Get the linked events and the user's roles in them

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :param limit: Max number of events
    """
    from indico.modules.events.abstracts.util import (get_events_with_abstract_reviewer_convener,
                                                      get_events_with_abstract_persons)
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (get_events_managed_by, get_events_created_by,
                                            get_events_with_linked_event_persons)

    links = avatar_links.get_links(user, dt) if redis_client else OrderedDict()
    allowed_redis_links = {'conference_editor', 'conference_paperReviewManager', 'conference_referee',
                           'conference_reviewer'}
    for event_id, event_links in links.items():
        event_links &= allowed_redis_links
        if not event_links:
            del links[event_id]
    for event_id in get_events_registered(user, dt):
        links.setdefault(str(event_id), set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, dt):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_manager')
    for event_id in get_events_created_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id in get_events_with_linked_event_persons(user, dt):
        links.setdefault(str(event_id), set()).add('conference_chair')
    for event_id, roles in get_events_with_abstract_reviewer_convener(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)
    for event_id, roles in get_events_with_abstract_persons(user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)

    if not links:
        return OrderedDict()

    query = (Event.query
             .filter(~Event.is_deleted,
                     Event.id.in_(map(int, links)))
             .options(joinedload('series'),
                      load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                                'series_id', 'series_pos', 'series_count'))
             .order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return OrderedDict((event, links[str(event.id)]) for event in query)
Exemplo n.º 16
0
def get_category_scores(avatar, debug=False):
    attendance_roles = set(['conference_participant', 'contribution_submission', 'abstract_submitter',
                            'registration_registrant', 'evaluation_submitter'])
    links = avatar_links.get_links(avatar)
    ch = ConferenceHolder()
    attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles))
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.getOwner()].append(event)
    return dict((categ, _get_category_score(avatar, categ, events, debug))
                for categ, events in categ_events.iteritems())
Exemplo n.º 17
0
def get_category_scores(user, debug=False):
    attendance_roles = {"contribution_submission", "abstract_submitter", "registration_registrant", "survey_submitter"}
    links = avatar_links.get_links(user)
    for event_id in get_events_with_submitted_surveys(user):
        links.setdefault(str(event_id), set()).add("survey_submitter")
    ch = ConferenceHolder()
    attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles))
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.getOwner()].append(event)
    return dict((categ, _get_category_score(user, categ, events, debug)) for categ, events in categ_events.iteritems())
Exemplo n.º 18
0
def update_event_data(avatar, categ, data):
    attendance_roles = set(['conference_participant', 'contribution_submission', 'abstract_submitter',
                            'registration_registrant', 'evaluation_submitter'])
    links = avatar_links.get_links(avatar)
    ch = ConferenceHolder()
    attended = filter(None, (ch.getById(eid, True) for eid, roles in links.iteritems() if attendance_roles & roles))
    attended = [e for e in attended if e.getOwner() == categ]
    # Count common chairpersons and attendants
    chair_count = data.setdefault('chair_count', Counter())
    participant_count = data.setdefault('participant_count', Counter())
    for event in attended:
        for ch in event.getChairList():
            chair_count[ch.getEmail()] += 1
        for part in event.getParticipation().getParticipantList():
            participant_count[part.getEmail()] += 1
Exemplo n.º 19
0
    def testImport(self):
        self.assertFalse(self._redis.keys())
        self._createDummies()

        avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
        self.assertEqual(frozenset(self._redis.keys()),
                         frozenset(['avatar-event-links/avatar_events:1', 'avatar-event-links/event_avatars:2',
                                    'avatar-event-links/event_avatars:3', 'avatar-event-links/event_avatars:1',
                                    'avatar-event-links/event_avatars:4', 'avatar-event-links/avatar_event_roles:1:4',
                                    'avatar-event-links/avatar_event_roles:1:3',
                                    'avatar-event-links/avatar_event_roles:1:2',
                                    'avatar-event-links/avatar_event_roles:1:1']))

        avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)
        self.assertEqual(frozenset(self._redis.keys()),
                         frozenset(['avatar-event-links/avatar_events:1', 'avatar-event-links/avatar_events:2',
                                    'avatar-event-links/event_avatars:2', 'avatar-event-links/event_avatars:3',
                                    'avatar-event-links/event_avatars:1', 'avatar-event-links/event_avatars:4',
                                    'avatar-event-links/avatar_event_roles:1:4',
                                    'avatar-event-links/avatar_event_roles:1:3',
                                    'avatar-event-links/avatar_event_roles:1:2',
                                    'avatar-event-links/avatar_event_roles:1:1',
                                    'avatar-event-links/avatar_event_roles:2:4',
                                    'avatar-event-links/avatar_event_roles:2:3',
                                    'avatar-event-links/avatar_event_roles:2:1']))

        self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant'])),
                                      ('3', set(['conference_manager']))]))

        self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis),
                         OrderedDict([('1', set(['conference_manager'])),
                                      ('4', set(['conference_manager'])),
                                      ('3', set(['conference_manager']))]))
Exemplo n.º 20
0
def get_category_scores(avatar, debug=False):
    attendance_roles = set([
        'conference_participant', 'contribution_submission',
        'abstract_submitter', 'registration_registrant', 'evaluation_submitter'
    ])
    links = avatar_links.get_links(avatar)
    ch = ConferenceHolder()
    attended = filter(
        None,
        (ch.getById(eid, True)
         for eid, roles in links.iteritems() if attendance_roles & roles))
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.getOwner()].append(event)
    return dict((categ, _get_category_score(avatar, categ, events, debug))
                for categ, events in categ_events.iteritems())
Exemplo n.º 21
0
def get_category_scores(user, debug=False):
    attendance_roles = {
        'contribution_submission', 'abstract_submitter',
        'registration_registrant', 'survey_submitter'
    }
    links = avatar_links.get_links(user)
    for event_id in get_events_with_submitted_surveys(user):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    ch = ConferenceHolder()
    attended = filter(
        None,
        (ch.getById(eid, True)
         for eid, roles in links.iteritems() if attendance_roles & roles))
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.getOwner()].append(event)
    return dict((categ, _get_category_score(user, categ, events, debug))
                for categ, events in categ_events.iteritems())
Exemplo n.º 22
0
    def testModifyEvent(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1,
                                client=self._redis,
                                assumeEvents=True)
        avatar_links.init_links(self._avatar2,
                                client=self._redis,
                                assumeEvents=True)

        self.assertEqual(
            avatar_links.get_links(self._avatar1, client=self._redis),
            OrderedDict([('2', set(['conference_participant'])),
                         ('1', set(['conference_participant'])),
                         ('4',
                          set(['conference_manager',
                               'conference_participant'])),
                         ('3', set(['conference_manager']))]))
        self.assertEqual(
            avatar_links.get_links(self._avatar2, client=self._redis),
            OrderedDict([('1', set(['conference_manager'])),
                         ('4', set(['conference_manager'])),
                         ('3', set(['conference_manager']))]))

        # Delete whole event
        avatar_links.delete_event(self._event1, client=self._redis)
        self.assertEqual(
            avatar_links.get_links(self._avatar1, client=self._redis),
            OrderedDict([('2', set(['conference_participant'])),
                         ('4',
                          set(['conference_manager',
                               'conference_participant'])),
                         ('3', set(['conference_manager']))]))
        self.assertEqual(
            avatar_links.get_links(self._avatar2, client=self._redis),
            OrderedDict([('4', set(['conference_manager'])),
                         ('3', set(['conference_manager']))]))

        # Modify event start time so the order changes
        self._event4.start_date = self._event3.start_date + 10
        avatar_links.update_event_time(self._event4, client=self._redis)

        self.assertEqual(
            avatar_links.get_links(self._avatar1, client=self._redis),
            OrderedDict([('2', set(['conference_participant'])),
                         ('3', set(['conference_manager'])),
                         ('4',
                          set(['conference_manager',
                               'conference_participant']))]))
        self.assertEqual(
            avatar_links.get_links(self._avatar2, client=self._redis),
            OrderedDict([('3', set(['conference_manager'])),
                         ('4', set(['conference_manager']))]))
Exemplo n.º 23
0
def update_event_data(avatar, categ, data):
    attendance_roles = set([
        'conference_participant', 'contribution_submission',
        'abstract_submitter', 'registration_registrant', 'evaluation_submitter'
    ])
    links = avatar_links.get_links(avatar)
    ch = ConferenceHolder()
    attended = filter(
        None,
        (ch.getById(eid, True)
         for eid, roles in links.iteritems() if attendance_roles & roles))
    attended = [e for e in attended if e.getOwner() == categ]
    # Count common chairpersons and attendants
    chair_count = data.setdefault('chair_count', Counter())
    participant_count = data.setdefault('participant_count', Counter())
    for event in attended:
        for ch in event.getChairList():
            chair_count[ch.getEmail()] += 1
        for part in event.getParticipation().getParticipantList():
            participant_count[part.getEmail()] += 1
Exemplo n.º 24
0
def get_category_scores(user, debug=False):
    # XXX: check if we can add some more roles such as 'contributor' to assume attendance
    event_ids = set()
    event_ids.update(int(id_)
                     for id_, roles in avatar_links.get_links(user).iteritems()
                     if 'abstract_submitter' in roles)
    event_ids.update(id_
                     for id_, roles in get_events_with_linked_contributions(user).iteritems()
                     if 'contribution_submission' in roles)
    event_ids |= get_events_registered(user)
    event_ids |= get_events_with_submitted_surveys(user)
    attended = (Event.query
                .filter(Event.id.in_(event_ids), ~Event.is_deleted)
                .options(joinedload('category'))
                .order_by(Event.start_dt, Event.id)
                .all())
    categ_events = defaultdict(list)
    for event in attended:
        categ_events[event.category].append(event)
    return dict((categ, _get_category_score(user, categ, events, debug))
                for categ, events in categ_events.iteritems())
Exemplo n.º 25
0
 def export_linked_events(self, aw):
     if not redis_client:
         raise HTTPAPIError('This API is only available when using Redis')
     self._checkProtection(aw)
     links = avatar_links.get_links(self._avatar.user, self._fromDT, self._toDT)
     for event_id in get_events_registered(self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('registration_registrant')
     for event_id in get_events_with_submitted_surveys(self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('survey_submitter')
     for event_id in get_events_managed_by(self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('conference_manager')
     for event_id in get_events_created_by(self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('conference_creator')
     for event_id, principal_roles in get_events_with_linked_sessions(self._avatar.user, self._fromDT,
                                                                      self._toDT).iteritems():
         links.setdefault(str(event_id), set()).update(principal_roles)
     for event_id, principal_roles in get_events_with_linked_contributions(self._avatar.user, self._fromDT,
                                                                           self._toDT).iteritems():
         links.setdefault(str(event_id), set()).update(principal_roles)
     for event_id in get_events_with_linked_event_persons(self._avatar.user, self._fromDT, self._toDT):
         links.setdefault(str(event_id), set()).add('conference_chair')
     return UserRelatedEventFetcher(aw, self, links).events(links.keys())
Exemplo n.º 26
0
    def testModifyEvent(self):
        self._createDummies()
        avatar_links.init_links(self._avatar1, client=self._redis, assumeEvents=True)
        avatar_links.init_links(self._avatar2, client=self._redis, assumeEvents=True)

        self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('1', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant'])),
                                      ('3', set(['conference_manager']))]))
        self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis),
                         OrderedDict([('1', set(['conference_manager'])),
                                      ('4', set(['conference_manager'])),
                                      ('3', set(['conference_manager']))]))

        # Delete whole event
        avatar_links.delete_event(self._event1, client=self._redis)
        self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('4', set(['conference_manager', 'conference_participant'])),
                                      ('3', set(['conference_manager']))]))
        self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis),
                         OrderedDict([('4', set(['conference_manager'])),
                                      ('3', set(['conference_manager']))]))

        # Modify event start time so the order changes
        self._event4.start_date = self._event3.start_date + 10
        avatar_links.update_event_time(self._event4, client=self._redis)

        self.assertEqual(avatar_links.get_links(self._avatar1, client=self._redis),
                         OrderedDict([('2', set(['conference_participant'])),
                                      ('3', set(['conference_manager'])),
                                      ('4', set(['conference_manager', 'conference_participant']))]))
        self.assertEqual(avatar_links.get_links(self._avatar2, client=self._redis),
                         OrderedDict([('3', set(['conference_manager'])),
                                      ('4', set(['conference_manager']))]))
Exemplo n.º 27
0
 def export_linked_events(self, aw):
     if not redis_client:
         raise HTTPAPIError('This API is only available when using Redis')
     self._checkProtection(aw)
     links = avatar_links.get_links(self._avatar, self._fromDT, self._toDT)
     return UserRelatedEventFetcher(aw, self, links).events(links.keys())
Exemplo n.º 28
0
 def export_linked_events(self, aw):
     if not redis_client:
         raise HTTPAPIError('This API is only available when using Redis')
     self._checkProtection(aw)
     links = avatar_links.get_links(self._avatar, self._fromDT, self._toDT)
     return UserRelatedEventFetcher(aw, self, links).events(links.keys())
Exemplo n.º 29
0
def get_linked_events(user, dt, limit=None):
    """Get the linked events and the user's roles in them

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :param limit: Max number of events
    """
    from indico.modules.events.abstracts.util import (
        get_events_with_abstract_reviewer_convener,
        get_events_with_abstract_persons)
    from indico.modules.events.contributions.util import get_events_with_linked_contributions
    from indico.modules.events.registration.util import get_events_registered
    from indico.modules.events.sessions.util import get_events_with_linked_sessions
    from indico.modules.events.surveys.util import get_events_with_submitted_surveys
    from indico.modules.events.util import (
        get_events_managed_by, get_events_created_by,
        get_events_with_linked_event_persons)

    links = avatar_links.get_links(user, dt) if redis_client else OrderedDict()
    allowed_redis_links = {
        'conference_editor', 'conference_paperReviewManager',
        'conference_referee', 'conference_reviewer'
    }
    for event_id, event_links in links.items():
        event_links &= allowed_redis_links
        if not event_links:
            del links[event_id]
    for event_id in get_events_registered(user, dt):
        links.setdefault(str(event_id), set()).add('registration_registrant')
    for event_id in get_events_with_submitted_surveys(user, dt):
        links.setdefault(str(event_id), set()).add('survey_submitter')
    for event_id in get_events_managed_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_manager')
    for event_id in get_events_created_by(user, dt):
        links.setdefault(str(event_id), set()).add('conference_creator')
    for event_id, principal_roles in get_events_with_linked_sessions(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id, principal_roles in get_events_with_linked_contributions(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(principal_roles)
    for event_id in get_events_with_linked_event_persons(user, dt):
        links.setdefault(str(event_id), set()).add('conference_chair')
    for event_id, roles in get_events_with_abstract_reviewer_convener(
            user, dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)
    for event_id, roles in get_events_with_abstract_persons(user,
                                                            dt).iteritems():
        links.setdefault(str(event_id), set()).update(roles)

    if not links:
        return OrderedDict()

    query = (Event.query.filter(~Event.is_deleted, Event.id.in_(map(
        int, links))).options(
            joinedload('series'),
            load_only('id', 'category_id', 'title', 'start_dt', 'end_dt',
                      'series_id', 'series_pos',
                      'series_count')).order_by(Event.start_dt, Event.id))
    if limit is not None:
        query = query.limit(limit)
    return OrderedDict((event, links[str(event.id)]) for event in query)