Esempio n. 1
0
def create_user(current_session, username, role, email):
    """
    Create a user for all the projects or groups in the list.
    If the user already exists, to avoid unadvertedly changing it, we suggest update
    Returns a dictionary.
    """
    if not username:
        raise UserError(("Error: Please provide a username"))
    try:
        usr = us.get_user(current_session, username)
        raise UserError(("Error: user already exist. If this is not a"
                         " mistake, please, retry using update"))
    except NotFound:
        user_list = [
            user["name"].upper()
            for user in get_all_users(current_session)["users"]
        ]
        if username.upper() in user_list:
            raise UserError(
                ("Error: user with a name with the same combination/order "
                 "of characters already exists. Please remove this other user"
                 " or modify the new one. Contact us in case of doubt"))
        is_admin = role == "admin"
        email_add = email
        usr = User(username=username,
                   active=True,
                   is_admin=is_admin,
                   email=email_add)
        current_session.add(usr)
        return us.get_user_info(current_session, username)
Esempio n. 2
0
def get_group_users(current_session, groupname):
    users = gp.get_group_users(current_session, groupname)
    get_user_info = lambda user: us.get_user_info(current_session, user.username)
    users_names = [
        {"name": the_user["name"], "role": the_user["role"]}
        for the_user in map(get_user_info, users)
    ]
    return {"users": users_names}
Esempio n. 3
0
def update_user(current_session, username, role, email, new_name):
    usr = us.get_user(current_session, username)
    user_list = [
        user["name"].upper()
        for user in get_all_users(current_session)["users"]
    ]
    if (new_name and new_name.upper() in user_list
            and not username.upper() == new_name.upper()):
        raise UserError(
            ("Error: user with a name with the same combination/order "
             "of characters already exists. Please remove this other user"
             " or modify the new one. Contact us in case of doubt"))
    usr.email = email or usr.email
    if role:
        usr.is_admin = role == "admin"
    usr.username = new_name or usr.username
    return us.get_user_info(current_session, usr.username)
Esempio n. 4
0
def get_user_info(current_session, username):
    return us.get_user_info(current_session, username)