Skip to content
Snippets Groups Projects
Commit dbb146fc authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3420060 by eiriksm: ::getTeamsByUser should give me teams they are admins on

parent ebbbfaef
No related branches found
No related tags found
1 merge request!31Make sure teams are returned if user is only admin
Pipeline #90474 passed
......@@ -68,12 +68,16 @@ class TeamManager {
*/
public function getTeamsByUser(UserInterface $user) : array {
$node_storage = $this->entityTypeManager->getStorage('node');
$nids = $node_storage
$nids_q = $node_storage
->getQuery()
->accessCheck(FALSE)
->condition('type', TeamNode::NODE_TYPE)
->condition(TeamNode::MEMBERS_FIELD, $user->id())
->execute();
->condition('type', TeamNode::NODE_TYPE);
$or = $nids_q->orConditionGroup()
->condition('field_team_members', $user->id())
->condition('field_team_admins', $user->id());
$nids_q->condition($or);
$nids = $nids_q->execute();
return $node_storage->loadMultiple($nids);
}
......
......@@ -52,6 +52,30 @@ class TeamManagerTest extends KernelTestBase {
self::assertEquals($node->id(), $team_node_result->id());
}
/**
* Test that we can get teams from user.
*/
public function testGetTeamsFromUserOnlyAdmin() {
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
'title' => 'test',
]);
$node->save();
$user = User::create([
'name' => 'test',
'mail' => 'test@example.com',
]);
$user->save();
$node->setAdmins([$user]);
$node->save();
$teams = $this->teamManager->getTeamsByUser($user);
self::assertCount(1, $teams);
/** @var \Drupal\violinist_teams\TeamNode $team_node_result */
$team_node_result = reset($teams);
self::assertEquals($node->id(), $team_node_result->id());
}
/**
* Test what happens when we delete a user.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment