final class ManageTeamMembersAccess in Apigee Edge 8
Check access on manage team members routes.
@internal
Hierarchy
- class \Drupal\apigee_edge_teams\Access\ManageTeamMembersAccess implements AccessInterface
Expanded class hierarchy of ManageTeamMembersAccess
1 string reference to 'ManageTeamMembersAccess'
- 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 ManageTeamMembersAccess
File
- modules/
apigee_edge_teams/ src/ Access/ ManageTeamMembersAccess.php, line 37
Namespace
Drupal\apigee_edge_teams\AccessView source
final class ManageTeamMembersAccess implements AccessInterface {
/**
* The team membership manager service.
*
* @var \Drupal\apigee_edge_teams\TeamMembershipManagerInterface
*/
private $teamMembershipManager;
/**
* The team permission handler.
*
* @var \Drupal\apigee_edge_teams\TeamPermissionHandlerInterface
*/
private $teamPermissionHandler;
/**
* ManageTeamMembersAccess constructor.
*
* @param \Drupal\apigee_edge_teams\TeamMembershipManagerInterface $team_membership_manager
* The team membership manager service.
* @param \Drupal\apigee_edge_teams\TeamPermissionHandlerInterface $team_permission_handler
* The team permission handler.
*/
public function __construct(TeamMembershipManagerInterface $team_membership_manager, TeamPermissionHandlerInterface $team_permission_handler) {
$this->teamMembershipManager = $team_membership_manager;
$this->teamPermissionHandler = $team_permission_handler;
}
/**
* Grant access to Manage team members pages.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(RouteMatchInterface $route_match, AccountInterface $account) {
if ($account
->isAnonymous()) {
return AccessResult::forbidden('This UI only available to logged in users.');
}
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
$team = $route_match
->getParameter('team');
/** @var \Drupal\apigee_edge\Entity\DeveloperInterface|null $developer */
$developer = $route_match
->getParameter('developer');
// If the developer parameter is available in the route make sure it is
// member of the team.
if ($developer !== NULL) {
if (!in_array($team
->id(), $this->teamMembershipManager
->getTeams($developer
->getEmail()))) {
return AccessResultForbidden::forbidden("The {$developer->getEmail()} developer is not member of the {$team->id()} team.");
}
}
$result = AccessResultAllowed::allowedIfHasPermissions($account, [
'administer team',
'manage team members',
], 'OR')
->cachePerPermissions();
if ($result
->isNeutral()) {
$result = AccessResultAllowed::allowedIf(in_array('team_manage_members', $this->teamPermissionHandler
->getDeveloperPermissionsByTeam($team, $account)))
->addCacheableDependency($team)
->cachePerUser();
}
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ManageTeamMembersAccess:: |
private | property | The team membership manager service. | |
ManageTeamMembersAccess:: |
private | property | The team permission handler. | |
ManageTeamMembersAccess:: |
public | function | Grant access to Manage team members pages. | |
ManageTeamMembersAccess:: |
public | function | ManageTeamMembersAccess constructor. |