You are here

final class TeamAppListByTeamAccess in Apigee Edge 8

Check access on Team app list by team route.

@internal

Hierarchy

Expanded class hierarchy of TeamAppListByTeamAccess

1 string reference to 'TeamAppListByTeamAccess'
apigee_edge_teams.services.yml in modules/apigee_edge_teams/apigee_edge_teams.services.yml
modules/apigee_edge_teams/apigee_edge_teams.services.yml
1 service uses TeamAppListByTeamAccess
apigee_edge_teams.access_checker.team_app_list_by_team_access in modules/apigee_edge_teams/apigee_edge_teams.services.yml
Drupal\apigee_edge_teams\Access\TeamAppListByTeamAccess

File

modules/apigee_edge_teams/src/Access/TeamAppListByTeamAccess.php, line 36

Namespace

Drupal\apigee_edge_teams\Access
View source
final class TeamAppListByTeamAccess implements AccessInterface {

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  private $entityTypeManager;

  /**
   * The team permission handler service.
   *
   * @var \Drupal\apigee_edge_teams\TeamPermissionHandlerInterface
   */
  private $teamPermissionHandler;

  /**
   * TeamAppListByTeamAccess constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\apigee_edge_teams\TeamPermissionHandlerInterface $team_permission_handler
   *   The team permission handler service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, TeamPermissionHandlerInterface $team_permission_handler) {
    $this->entityTypeManager = $entity_type_manager;
    $this->teamPermissionHandler = $team_permission_handler;
  }

  /**
   * Grant access to Team app list by team page.
   *
   * @param \Drupal\apigee_edge_teams\Entity\TeamInterface $team
   *   The team entity from the route.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(TeamInterface $team, AccountInterface $account) {
    $team_app_admin_permission = $this->entityTypeManager
      ->getDefinition('team_app')
      ->getAdminPermission();
    $result = AccessResult::allowedIfHasPermissions($account, [
      TeamAppPermissionProvider::MANAGE_TEAM_APPS_PERMISSION,
      $team_app_admin_permission,
    ], 'OR')
      ->cachePerUser();
    if ($result
      ->isNeutral()) {
      if ($account
        ->isAuthenticated()) {
        $result = AccessResult::allowedIf(in_array('team_app_view', $this->teamPermissionHandler
          ->getDeveloperPermissionsByTeam($team, $account)));
        $result
          ->addCacheableDependency($account);
      }
    }
    return $result
      ->addCacheableDependency($team);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TeamAppListByTeamAccess::$entityTypeManager private property The entity type manager service.
TeamAppListByTeamAccess::$teamPermissionHandler private property The team permission handler service.
TeamAppListByTeamAccess::access public function Grant access to Team app list by team page.
TeamAppListByTeamAccess::__construct public function TeamAppListByTeamAccess constructor.