Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand Down Expand Up @@ -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';

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down