In Drupal 7, you would use the user_access function to check for user access. Here’s how to do it in Drupal 8.

How to check for permission in Drupal 8
1
2
3
4
5
// Get the current user
$user = \Drupal::currentUser();

// Check for permission
$user->hasPermission('access administration menu');