You are here

public function ModerationDashboardAccess::access in Moderation Dashboard 2.0.x

Determine if the $account has access to the scheduled content list.

The result will vary depending on whether the page being viewed is the user profile page or the scheduled content admin overview.

Parameters

\Drupal\Core\Session\AccountInterface $account: Current account.

File

src/Access/ModerationDashboardAccess.php, line 50

Class

ModerationDashboardAccess
Checks access for displaying the scheduler list of scheduled nodes.

Namespace

Drupal\moderation_dashboard\Access

Code

public function access(AccountInterface $account) {
  $dashboard_owner = $account;
  $current_user_id = $this->routeMatch
    ->getParameter('user');

  // If the current user is on their own dashboard, they can view it.
  if ($current_user_id === $dashboard_owner
    ->id() && $dashboard_owner
    ->hasPermission('use moderation dashboard')) {
    return AccessResult::allowed();
  }

  // If the given user doesn't have a dashboard, nobody can view it.
  if (!$dashboard_owner
    ->hasPermission('use moderation dashboard') && !$dashboard_owner
    ->hasPermission('view any moderation dashboard')) {
    return AccessResult::forbidden('User does not have access to view this dashboard.');
  }

  // But they can only view the dashboard of others with another permission.
  if ($dashboard_owner
    ->hasPermission('view any moderation dashboard')) {
    return AccessResult::allowed();
  }
  else {
    return AccessResult::forbidden();
  }
}