You are here

class ModerationDashboardAccess in Moderation Dashboard 2.0.x

Same name in this branch
  1. 2.0.x src/Access/ModerationDashboardAccess.php \Drupal\moderation_dashboard\Access\ModerationDashboardAccess
  2. 2.0.x src/Plugin/Condition/ModerationDashboardAccess.php \Drupal\moderation_dashboard\Plugin\Condition\ModerationDashboardAccess

Checks access for displaying the scheduler list of scheduled nodes.

Hierarchy

Expanded class hierarchy of ModerationDashboardAccess

1 string reference to 'ModerationDashboardAccess'
moderation_dashboard.services.yml in ./moderation_dashboard.services.yml
moderation_dashboard.services.yml
1 service uses ModerationDashboardAccess
moderation_dashboard.access_checker in ./moderation_dashboard.services.yml
Drupal\moderation_dashboard\Access\ModerationDashboardAccess

File

src/Access/ModerationDashboardAccess.php, line 14

Namespace

Drupal\moderation_dashboard\Access
View source
class ModerationDashboardAccess implements AccessCheckInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a ScheduledListAccess object.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->hasRequirement('_access_moderation_dashboard');
  }

  /**
   * 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.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Current account.
   */
  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();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ModerationDashboardAccess::$routeMatch protected property The current route match.
ModerationDashboardAccess::access public function Determine if the $account has access to the scheduled content list.
ModerationDashboardAccess::applies public function Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface::applies
ModerationDashboardAccess::__construct public function Constructs a ScheduledListAccess object.