node access not taken in account in views using the hook_node_access, i can restrict access to content by role.

If the boolean field_private_only is selected , only the user with the role private can view it, fine.

 my_module_node_access(NodeInterface $node, $op, AccountInterface $account) {

  global $user;
  if ($node-&gt;bundle() == 'my_content_type') {
      if ($op == 'view') {
          if ($node-&gt;field_private_only-&gt;getString()) {
            $user = \Drupal\user\Entity\User::load($account-&gt;id());
            if($user-&gt;hasRole('private'))
               return \Drupal\Core\Access\AccessResult::allowed();
          }
      }
   }
 return \Drupal\Core\Access\AccessResult::forbidden();
}


When creating a view displaying these contents, the restriction does not occur .

How can i Make it happen in views?

how can i make it happens in search_api index ?
For doing access control on views, i used the hook_views_post_execute.

For nodes with a restricted_content field set to true, the content is shown or not depending on roles

 function my module_views_post_execute(ViewExecutable $view)
 {
$VIP_member=false;
$user=\Drupal::currentUser();
$userRole=$user-&gt;getAccount()-&gt;getRoles();

if (( $user!=null )&amp;&amp;(in_array('VIP_member',$userRole))){
    $VIP_member=true;
}

if ($view-&gt;id() == 'articles_list') {
    foreach ($view-&gt;result as  $elementKey =&gt; $result ) {
        $node=$result-&gt;_entity;        

        $VIP_restricted=$node-&gt;field_VIP_only-&gt;getValue();

        // Remove node if no rights
        if (($VIP_restricted[0]['value'] == true) &amp;&amp; ($VIP_member==false) ){
              unset($view-&gt;result[$elementKey]);
        }
    }
}
 }