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

Issue #3440970 by eiriksm: Provide a way to disconnect a provider from a team

parent 251e8b96
No related branches found
No related tags found
1 merge request!50Add the methods and a test
Pipeline #146707 passed with warnings
......@@ -158,6 +158,28 @@ class TeamManager {
return $this->state->get(self::getVcsProviderStateKey($node), []);
}
/**
* Remove one connection, by key.
*
* Please note that this will complete and not fail even if the connection
* does not currently exist.
*/
public function removeVcsConnection(TeamNode $node, string $provider_id) {
$connections = $this->getVcsConnections($node);
if (empty($connections[$provider_id])) {
return;
}
unset($connections[$provider_id]);
$this->setVcsConnections($node, $connections);
}
/**
* Setter for all connections.
*/
public function setVcsConnections(TeamNode $node, array $connections) {
$this->state->set(self::getVcsProviderStateKey($node), $connections);
}
/**
* Get the state key we use to store connections for it.
*/
......
......@@ -166,4 +166,28 @@ class TeamManagerTest extends KernelTestBase {
self::assertNotEquals($hash1, $hash5);
}
/**
* Test all of the connection setters and getters.
*/
public function testConnectionMethods() {
$team = Node::create([
'type' => $this->nodeType->id(),
'title' => 'test',
]);
$team->save();
$this->teamManager->setVcsConnection($team, 'github', 'mytoken');
self::assertArrayHasKey('github', $this->teamManager->getVcsConnections($team));
self::assertEquals('mytoken', $this->teamManager->getVcsConnection($team, 'github'));
$this->teamManager->setVcsConnection($team, 'gitlab', 'mytoken2');
self::assertArrayHasKey('gitlab', $this->teamManager->getVcsConnections($team));
self::assertEquals('mytoken2', $this->teamManager->getVcsConnection($team, 'gitlab'));
// Remove the github one, and ensure its not there any more.
$this->teamManager->removeVcsConnection($team, 'github');
self::assertArrayNotHasKey('github', $this->teamManager->getVcsConnections($team));
// And let's also nuke it entirely by setting it to an empty array. This
// should remove the gitlab one.
$this->teamManager->setVcsConnections($team, []);
self::assertEmpty($this->teamManager->getVcsConnections($team));
}
}
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