scout/commands/load/user.py
def user(context, institute_id, user_name, user_mail, admin):
    """Add a user to the database."""
    adapter = context.obj['adapter']

    institutes = []
    for institute in institute_id:
        institute_obj = adapter.institute(institute_id=institute)

        if not institute_obj:
            LOG.warning("Institute % does not exist", institute)
            context.abort()

        institutes.append(institute)

    roles = []
    if admin:
        LOG.info("User is admin")
        roles.append('admin')

    user_info = dict(email=user_mail.lower(), name=user_name, roles=roles, institutes=institutes)

    user_obj = build_user(user_info)

    try:
        adapter.add_user(user_obj)
    except Exception as err:
        LOG.warning(err)
        context.abort()
def user(context, institute_id, user_name, user_mail, admin):
    adapter = context.obj['adapter']

    institutes = []
    for institute in institute_id:
        institute_obj = adapter.institute(institute_id=institute)

        if not institute_obj:
            LOG.warning("Institute % does not exist", institute)
            context.abort()

        institutes.append(institute)

    roles = []
    if admin:
        LOG.info("User is admin")
        roles.append('admin')

    user_info = dict(email=user_mail.lower(), name=user_name, roles=roles, institutes=institutes)

    user_obj = build_user(user_info)

    try:
        adapter.add_user(user_obj)
    except Exception as err:
        LOG.warning(err)
        context.abort()
def user ( context , institute_id , user_name , user_mail , admin ) : adapter = context . obj [ 'adapter' ] institutes = [ ] for institute in institute_id : institute_obj = adapter . institute ( institute_id = institute ) if not institute_obj : LOG . warning ( "Institute % does not exist" , institute ) context . abort ( ) institutes . append ( institute ) roles = [ ] if admin : LOG . info ( "User is admin" ) roles . append ( 'admin' ) user_info = dict ( email = user_mail . lower ( ) , name = user_name , roles = roles , institutes = institutes ) user_obj = build_user ( user_info ) try : adapter . add_user ( user_obj ) except Exception as err : LOG . warning ( err ) context . abort ( )
Add a user to the database.
Add a user to the database .