From cbb1cc4d98220b978675ae7b3b6a779f6c8f56f4 Mon Sep 17 00:00:00 2001 From: shailesh-google Date: Tue, 2 Dec 2025 20:15:32 +0530 Subject: [PATCH 1/2] Added Pagination For Team Listing Page --- .../Entity/ListBuilder/TeamListBuilder.php | 22 ++++++++++++++- .../ApigeeX/TeamListBuilderTest.php | 28 ++++++++++++------- 2 files changed, 39 insertions(+), 11 deletions(-) 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..6cc292562 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,36 @@ 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()); + 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()); } /** From cf4afcf313198b933dd3ef56603783779f7435fc Mon Sep 17 00:00:00 2001 From: shailesh-google Date: Tue, 2 Dec 2025 21:11:02 +0530 Subject: [PATCH 2/2] Fixes PHPCS Issue --- .../tests/src/Functional/ApigeeX/TeamListBuilderTest.php | 3 +++ 1 file changed, 3 insertions(+) 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 6cc292562..fcf8f3414 100644 --- a/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php +++ b/modules/apigee_edge_teams/tests/src/Functional/ApigeeX/TeamListBuilderTest.php @@ -191,6 +191,9 @@ public function testTeamListCache() { $this->drupalLogout(); } + /** + * Tests team list cache with and without Team Permission. + */ public function testTeamListWithAndWithoutTeamPermission() { $appgroups = [ $this->teamA->decorated(),