diff --git a/modules/apigee_edge_teams/src/Entity/ListBuilder/TeamListBuilder.php b/modules/apigee_edge_teams/src/Entity/ListBuilder/TeamListBuilder.php index 0b4ab8713..419d1f978 100644 --- a/modules/apigee_edge_teams/src/Entity/ListBuilder/TeamListBuilder.php +++ b/modules/apigee_edge_teams/src/Entity/ListBuilder/TeamListBuilder.php @@ -21,7 +21,10 @@ namespace Drupal\apigee_edge_teams\Entity\ListBuilder; use Drupal\Core\Cache\Cache; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Url; use Drupal\apigee_edge\Element\StatusPropertyElement; use Drupal\apigee_edge\Entity\ListBuilder\EdgeEntityListBuilder; @@ -32,6 +35,16 @@ */ class TeamListBuilder extends EdgeEntityListBuilder { + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, ?ConfigFactoryInterface $config_factory = NULL) { + parent::__construct($entity_type, $entity_type_manager, $config_factory); + + // Override the limit here. + $this->limit = 1000; + } + /** * {@inheritdoc} */ @@ -118,7 +131,11 @@ public function render() { $build = parent::render(); $account = $this->entityTypeManager->getStorage('user')->load(\Drupal::currentUser()->id()); - $build = empty($build['table']) ? $build : $build['table']; + if (isset($build['#type']) && $build['#type'] === 'table') { + $build = [ + 'table' => $build, + ]; + } $build['#cache']['keys'][] = 'team_list_per_user'; @@ -132,6 +149,9 @@ public function render() { $build['#cache']['contexts'][] = 'user'; $build['#cache']['contexts'][] = 'user.permissions'; + // Important: Cache per page. + $build['#cache']['contexts'][] = 'url.query_args:page'; + $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $account->getCacheTags()); // Use cache expiration defined in configuration. diff --git a/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php b/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php index 76bd5c89f..fcf8f3414 100644 --- a/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php +++ b/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php @@ -189,28 +189,39 @@ public function testTeamListCache() { $assert->pageTextNotContains($this->teamA->label()); $assert->pageTextContains($this->teamB->label()); $this->drupalLogout(); + } - // cMemberAccount should not see any teams. - $this->drupalLogin($this->cMemberAccount); - $this->queueAppGroupsResponse($appgroups); - $this->queueDeveloperResponse($this->cMemberAccount); - $this->queueDeveloperResponse($this->cMemberAccount); - $this->drupalGet(Url::fromUserInput('/teams')); - $assert = $this->assertSession(); - $assert->pageTextNotContains($this->teamA->label()); - $assert->pageTextNotContains($this->teamB->label()); + /** + * Tests team list cache with and without Team Permission. + */ + public function testTeamListWithAndWithoutTeamPermission() { + $appgroups = [ + $this->teamA->decorated(), + $this->teamB->decorated(), + ]; + $this->drupalLogin($this->cMemberAccount); // Give cMemberAccount permission to view all teams. $this->cMemberAccount->addRole($this->customRole); $this->cMemberAccount->save(); // cMemberAccount should see both teams now. $this->queueAppGroupsResponse($appgroups); - $this->queueDeveloperResponse($this->cMemberAccount); $this->drupalGet(Url::fromUserInput('/teams')); $assert = $this->assertSession(); $assert->pageTextContains($this->teamA->label()); $assert->pageTextContains($this->teamB->label()); + + // cMemberAccount should not see any teams. + $this->cMemberAccount->removeRole($this->customRole); + $this->cMemberAccount->save(); + $this->queueAppGroupsResponse($appgroups); + $this->queueDeveloperResponse($this->cMemberAccount); + $this->queueDeveloperResponse($this->cMemberAccount); + $this->drupalGet(Url::fromUserInput('/teams')); + $assert = $this->assertSession(); + $assert->pageTextNotContains($this->teamA->label()); + $assert->pageTextNotContains($this->teamB->label()); } /**