I have searched a lot and after some R&D I found the solution by my own. Posting so that it will be helpful to others also.
In your UI component, add class on your massaction element shown as below:
<massaction name="listing_massaction" class="NameSpace\MyModule\Ui\MassAction">
In this class, we will write our logic to hide/show our MassAction dropdown.
Below is my MassAction.php file which I created under NameSpace/MyModule/UI/MassAction.php
namespace NameSpace\MyModule\Ui;
use Magento\Backend\Model\Auth\Session as AuthSession;
class MassAction extends \Magento\Ui\Component\MassAction
{
protected $authSession;
public function __construct(
\Magento\Framework\View\Element\UiComponent\ContextInterface $context,
AuthSession $authSession,
$components,
array $data
) {
$this->authSession = $authSession;
parent::__construct($context, $components, $data);
}
public function prepare()
{
parent::prepare();
$adminuser = $this->authSession->getUser();
if ($adminuser) {
$roleData = $adminuser->getRole()->getData();
if (!(strtolower($roleData['role_name']) == strtolower(\NameSpace\MyModule\Block\Menu::ADMINSTRATORS))) {
$this->setData('config', '');
}
}
}
}