Ejemplo n.º 1
0
def get_events_with_abstract_reviewer_convener(user, dt=None):
    """
    Return a dict of event ids and the abstract reviewing related
    roles the user has in that event.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    """
    data = defaultdict(set)
    # global reviewer/convener
    mapping = {
        'global_abstract_reviewer_for_events': 'abstract_reviewer',
        'global_convener_for_events': 'track_convener'
    }
    for rel, role in mapping.iteritems():
        query = (Event.query.with_parent(user, rel).filter(
            Event.ends_after(dt), ~Event.is_deleted).options(load_only('id')))
        for event in query:
            data[event.id].add(role)
    # track reviewer/convener
    mapping = {
        'abstract_reviewer_for_tracks': 'abstract_reviewer',
        'convener_for_tracks': 'track_convener'
    }
    for rel, role in mapping.iteritems():
        query = (Track.query.with_parent(user, rel).join(Track.event).filter(
            Event.ends_after(dt),
            ~Event.is_deleted).options(load_only('event_id')))
        for track in query:
            data[track.event_id].add(role)
    return data
Ejemplo n.º 2
0
def get_events_with_abstract_persons(user, dt=None):
    """
    Return a dict of event ids and the abstract submission related
    roles the user has in that event.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    """
    data = defaultdict(set)
    bad_states = {AbstractState.withdrawn, AbstractState.rejected}
    # submitter
    query = (Abstract.query.filter(~Event.is_deleted, ~Abstract.is_deleted,
                                   ~Abstract.state.in_(bad_states),
                                   Event.ends_after(dt),
                                   Abstract.submitter == user).join(
                                       Abstract.event).options(
                                           load_only('event_id')))
    for abstract in query:
        data[abstract.event_id].add('abstract_submitter')
    # person
    abstract_criterion = db.and_(~Abstract.state.in_(bad_states),
                                 ~Abstract.is_deleted)
    query = (user.event_persons.filter(
        ~Event.is_deleted, Event.ends_after(dt),
        EventPerson.abstract_links.any(
            AbstractPersonLink.abstract.has(abstract_criterion))).join(
                EventPerson.event).options(load_only('event_id')))
    for person in query:
        data[person.event_id].add('abstract_person')
    return data
Ejemplo n.º 3
0
def get_events_with_linked_sessions(user, dt=None):
    """Returns a dict with keys representing event_id and the values containing
    data about the user rights for sessions within the event

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    """
    query = (user.in_session_acls.options(
        load_only('session_id', 'roles', 'full_access',
                  'read_access')).options(noload('*')).options(
                      contains_eager(SessionPrincipal.session).load_only(
                          'event_id')).join(Session).join(
                              Event, Event.id == Session.event_id).filter(
                                  ~Session.is_deleted, ~Event.is_deleted,
                                  Event.ends_after(dt)))
    data = defaultdict(set)
    for principal in query:
        roles = data[principal.session.event_id]
        if 'coordinate' in principal.roles:
            roles.add('session_coordinator')
        if 'submit' in principal.roles:
            roles.add('session_submission')
        if principal.full_access:
            roles.add('session_manager')
        if principal.read_access:
            roles.add('session_access')
    return data
Ejemplo n.º 4
0
def get_events_created_by(user, dt=None):
    """Gets the IDs of events created by the user

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :return: A set of event ids
    """
    query = (user.created_events.filter(~Event.is_deleted,
                                        Event.ends_after(dt)).options(
                                            load_only('id')))
    return {event.id for event in query}
Ejemplo n.º 5
0
def get_events_managed_by(user, dt=None):
    """Gets the IDs of events where the user has management privs.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :return: A set of event ids
    """
    query = (user.in_event_acls.join(Event).options(
        noload('user'), noload('local_group'), load_only('event_id')).filter(
            ~Event.is_deleted, Event.ends_after(dt)).filter(
                EventPrincipal.has_management_role('ANY')))
    return {principal.event_id for principal in query}
Ejemplo n.º 6
0
def get_events_with_submitted_surveys(user, dt=None):
    """Gets the IDs of events where the user submitted a survey.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :return: A set of event ids
    """
    from fossir.modules.events.surveys.models.surveys import Survey
    # Survey submissions are not stored in links anymore, so we need to get them directly
    query = (user.survey_submissions
             .options(load_only('survey_id'))
             .options(joinedload(SurveySubmission.survey).load_only('event_id'))
             .join(Survey)
             .join(Event)
             .filter(~Survey.is_deleted, ~Event.is_deleted, Event.ends_after(dt)))
    return {submission.survey.event_id for submission in query}
Ejemplo n.º 7
0
def get_events_with_paper_roles(user, dt=None):
    """
    Get the IDs and PR roles of events where the user has any kind
    of paper reviewing privileges.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    :return: A dict mapping event IDs to a set of roles
    """
    paper_roles = {'paper_manager', 'paper_judge', 'paper_content_reviewer', 'paper_layout_reviewer'}
    role_criteria = [EventPrincipal.has_management_role(role, explicit=True) for role in paper_roles]
    query = (user.in_event_acls
             .join(Event)
             .options(noload('user'), noload('local_group'), load_only('event_id', 'roles'))
             .filter(~Event.is_deleted, Event.ends_after(dt))
             .filter(db.or_(*role_criteria)))
    return {principal.event_id: set(principal.roles) & paper_roles for principal in query}
Ejemplo n.º 8
0
def get_events_with_linked_event_persons(user, dt=None):
    """
    Returns a dict containing the event ids and role for all events
    where the user is a chairperson or (in case of a lecture) speaker.

    :param user: A `User`
    :param dt: Only include events taking place on/after that date
    """
    query = (user.event_persons.with_entities(
        EventPerson.event_id,
        Event._type).join(Event, Event.id == EventPerson.event_id).filter(
            EventPerson.event_links.any()).filter(~Event.is_deleted,
                                                  Event.ends_after(dt)))
    return {
        event_id: ('lecture_speaker'
                   if event_type == EventType.lecture else 'conference_chair')
        for event_id, event_type in query
    }