You are here

public function GroupRequestController::routeAccess in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::routeAccess()
  2. 10.3.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::routeAccess()
  3. 10.1.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::routeAccess()
  4. 10.2.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::routeAccess()

Checks access for a specific route request to see if user can see requests.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php, line 201

Class

GroupRequestController
Returns responses for Group request routes.

Namespace

Drupal\social_group_request\Controller

Code

public function routeAccess(AccountInterface $account) {

  // @todo refactor this when Group entity query access lands.
  $has_administer_users = $account
    ->hasPermission('administer members');
  if ($has_administer_users) {
    return AccessResult::allowed();
  }
  $group = _social_group_get_current_group();
  if (!$group instanceof Group) {
    $group_id = \Drupal::routeMatch()
      ->getParameter('group');

    // Views upcasting is lame.
    if (!isset($group_id)) {
      $group_id = \Drupal::routeMatch()
        ->getParameter('arg_0');
    }
    $group = Group::load($group_id);
  }
  $is_group_page = isset($group);
  $is_group_manager = $group
    ->hasPermission('administer members', $account);
  return AccessResult::allowedIf($is_group_page && $is_group_manager);
}