How to use the ramp-database.ramp_database.tools._query.select_user_by_name function in ramp-database

To help you get started, we’ve selected a few ramp-database examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / user.py View on Github external
linkedin_url=linkedin_url, twitter_url=twitter_url,
                facebook_url=facebook_url, google_url=google_url,
                github_url=github_url, website_url=website_url, bio=bio,
                is_want_news=is_want_news)

    # Creating default team with the same name as the user
    # user is admin of his/her own team
    team = Team(name=name, admin=user)
    session.add(team)
    session.add(user)
    try:
        session.commit()
    except IntegrityError as e:
        session.rollback()
        message = ''
        if select_user_by_name(session, name) is not None:
            message += 'username is already in use'
        elif select_team_by_name(session, name) is not None:
            # We only check for team names if username is not in db
            message += 'username is already in use as a team name'
        if select_user_by_email(session, lower_case_email) is not None:
            if message:
                message += ' and '
            message += 'email is already in use'
        if message:
            raise NameClashError(message)
        else:
            raise e
    logger.info('Creating {}'.format(user))
    logger.info('Creating {}'.format(team))
    return user
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / user.py View on Github external
def approve_user(session, name):
    """Approve a user once it is created.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    name : str
        The name of the user.
    """
    user = select_user_by_name(session, name)
    if user.access_level == 'asked':
        user.access_level = 'user'
    user.is_authenticated = True
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / user.py View on Github external
def make_user_admin(session, name):
    """Make a user a RAMP admin.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    name : str
        The name of the user.
    """
    user = select_user_by_name(session, name)
    user.access_level = 'admin'
    user.is_authenticated = True
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / frontend.py View on Github external
def is_admin(session, event_name, user_name):
    """Whether or not a user is administrator or administrate an event.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    if user.access_level == 'admin':
        return True
    event_admin = select_event_admin_by_instance(session, event, user)
    if event_admin is None:
        return False
    return True
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / user.py View on Github external
Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    name : str or None
        The name of the user. If None, all users will be queried.

    Returns
    -------
    user : :class:`ramp_database.model.User` or list of \
:class:`ramp_database.model.User`
        The queried user.
    """
    return (select_user_by_email(session, name) or
            select_user_by_name(session, name))
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / frontend.py View on Github external
def is_accessible_event(session, event_name, user_name):
    """Whether or not an event is public or and a user is registered to RAMP
    or and admin.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    if event is None:
        return False
    if user.access_level == 'asked':
        return False
    if event.is_public or is_admin(session, event_name, user_name):
        return True
    return False
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / event.py View on Github external
Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.

    Returns
    -------
    event_admin : :class:`ramp_database.model.EventAdmin` or None
        The event/admin instance queried.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    return select_event_admin_by_instance(session, event, user)