getUser(); if (!$user instanceof User) { return false; } if ($this->hasRolePermission($user, $attribute . '_customer')) { return true; } // those cannot be assigned to teams if (\in_array($attribute, ['create', 'delete'])) { return false; } $hasTeamleadPermission = $this->hasRolePermission($user, $attribute . '_teamlead_customer'); $hasTeamPermission = $this->hasRolePermission($user, $attribute . '_team_customer'); if (!$hasTeamleadPermission && !$hasTeamPermission) { return false; } /** @var Team $team */ foreach ($subject->getTeams() as $team) { if ($hasTeamleadPermission && $user->isTeamleadOf($team)) { return true; } if ($hasTeamPermission && $user->isInTeam($team)) { return true; } } return false; } }