gui/backend/gui_plugin/users/UserManagement.py
def grant_role(username, role, web_session=None):
    """Grant the given roles to the user.

    Args:
        username (str): The name of the user
        role (str): The list of roles that should be assigned to the
            user. Use listRoles() to list all available roles.
        web_session (object): The webserver session object, optional. Will be
            passed in by the webserver automatically

    Returns:
        The generated shell request record.
    """
    result = Response.ok("Role(s) successfully granted to user.")
    with BackendDatabase(web_session) as db:
        user_id = backend.get_user_id(db, username)
        if not user_id:
            raise MSGException(Error.USER_INVALID_ROLE,
                               f"There is no user with the name '{username}'.")

        # ensure roles is always a list
        roles = [role]

        # check for each role specified if that role actually exists in the db
        with BackendTransaction(db):
            for role in roles:
                res = db.execute(
                    "SELECT id FROM role WHERE name = ?", (role,)).fetch_one()
                if not res:
                    raise MSGException(Error.USER_INVALID_ROLE,
                                       f"There is no role with the name '{role}'.")
                else:
                    role_id = res[0]

                # perform the many-to-many insert
                db.execute("INSERT INTO user_has_role("
                           "user_id, role_id) "
                           "VALUES(?, ?)", (user_id, role_id))

    return result
Grant the given roles to the user.

    Args:
        username (str): The name of the user
        role (str): The list of roles that should be assigned to the
            user. Use listRoles() to list all available roles.
        web_session (object): The webserver session object, optional. Will be
            passed in by the webserver automatically

    Returns:
        The generated shell request record.
    
Grant the given roles to the user.
Grant the given roles to the user .
def grant_role(username, role, web_session=None):
    result = Response.ok("Role(s) successfully granted to user.")
    with BackendDatabase(web_session) as db:
        user_id = backend.get_user_id(db, username)
        if not user_id:
            raise MSGException(Error.USER_INVALID_ROLE,
                               f"There is no user with the name '{username}'.")
        roles = [role]
        with BackendTransaction(db):
            for role in roles:
                res = db.execute(
                    "SELECT id FROM role WHERE name = ?", (role,)).fetch_one()
                if not res:
                    raise MSGException(Error.USER_INVALID_ROLE,
                                       f"There is no role with the name '{role}'.")
                else:
                    role_id = res[0]
                db.execute("INSERT INTO user_has_role("
                           "user_id, role_id) "
                           "VALUES(?, ?)", (user_id, role_id))
    return result
def grant_role ( username , role , web_session = None ) : result = Response . ok ( "Role(s) successfully granted to user." ) with BackendDatabase ( web_session ) as db : user_id = backend . get_user_id ( db , username ) if not user_id : raise MSGException ( Error . USER_INVALID_ROLE , f"There is no user with the name '{username}'." ) roles = [ role ] with BackendTransaction ( db ) : for role in roles : res = db . execute ( "SELECT id FROM role WHERE name = ?" , ( role , ) ) . fetch_one ( ) if not res : raise MSGException ( Error . USER_INVALID_ROLE , f"There is no role with the name '{role}'." ) else : role_id = res [ 0 ] db . execute ( "INSERT INTO user_has_role(" "user_id, role_id) " "VALUES(?, ?)" , ( user_id , role_id ) ) return result
Grant the given roles to the user.
Grant the given roles to the user .
"""Grant the given roles to the user.

    Args:
        username (str): The name of the user
        role (str): The list of roles that should be assigned to the
            user. Use listRoles() to list all available roles.
        web_session (object): The webserver session object, optional. Will be
            passed in by the webserver automatically

    Returns:
        The generated shell request record.
    """ # ensure roles is always a list # check for each role specified if that role actually exists in the db # perform the many-to-many insert
The generated shell request record.
The generated shell request record .
username
The name of the user
The name of the user
role
The list of roles that should be assigned to the
user. Use listRoles() to list all available roles.
The list of roles that should be assigned to the user . Use listRoles () to list all available roles .
web_session
The webserver session object, optional. Will be
passed in by the webserver automatically
The webserver session object optional . Will be passed in by the webserver automatically