You are here

public function OpignoModuleManagerController::accessActivitiesOverview in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Controller/OpignoModuleManagerController.php \Drupal\opigno_module\Controller\OpignoModuleManagerController::accessActivitiesOverview()

Checks access for the activities overview.

Parameters

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

Return value

\Drupal\Core\Access\AccessResult Access result.

1 string reference to 'OpignoModuleManagerController::accessActivitiesOverview'
opigno_module.routing.yml in ./opigno_module.routing.yml
opigno_module.routing.yml

File

src/Controller/OpignoModuleManagerController.php, line 257

Class

OpignoModuleManagerController
Controller for all the actions of the Opigno module manager.

Namespace

Drupal\opigno_module\Controller

Code

public function accessActivitiesOverview(AccountInterface $account) {

  // Allow access if the user is a platform-level content manager.
  if ($account
    ->hasPermission('manage group content in any group')) {
    return AccessResult::allowed();
  }

  // Allow access if the user is a group-level content manager in any group.
  $membership_service = \Drupal::service('group.membership_loader');
  $memberships = $membership_service
    ->loadByUser($account);
  foreach ($memberships as $membership) {

    /** @var \Drupal\group\GroupMembership $membership */
    $group = $membership
      ->getGroup();
    if ($group
      ->access('update', $account)) {
      return AccessResult::allowed();
    }
  }
  return AccessResult::forbidden();
}