Get Current Admin User Role id programmatically in Magento 2.

Magento 2 Contains Multiple Users for admin panel to access different section of the functionality based on their User Roles.

You can see User Roles in the admin panel by click on the left navigation System -> Permissions -> User Roles.

You can get current logged user id in Magento 2 by calling

Magento\Authorization\Model\UserContextInterface

Class.

<?php
namespace Rbj\UserRole\Model;

use Magento\Authorization\Model\UserContextInterface;

class GetUserRole
{
    /**
     * @var UserContextInterface
     */
    protected $userContext;

    public function __construct(
        UserContextInterface $userContext,
    ) {
        $this->userContext = $userContext;
    }

    public function getUserRoleId()
    {
        $roleId = $this->userContext->getUserId();
        return $roleId;
    }
}

You need to call getUserRoleId() function from the above class to get Current User role id.

The return value will be User Id of current User.