diff --git a/Admin/CommunityAdmin.php b/Admin/CommunityAdmin.php index b5098093..8cef111e 100644 --- a/Admin/CommunityAdmin.php +++ b/Admin/CommunityAdmin.php @@ -84,9 +84,35 @@ public function getSecurityContexts() { $systems = []; + $webspaceCollection = $this->webspaceManager->getWebspaceCollection(); + + $webspaceKeys = array_keys($webspaceCollection->getWebspaces()); + foreach ($this->webspacesConfiguration as $webspaceKey => $webspaceConfig) { - $webspace = $this->webspaceManager->getWebspaceCollection()->getWebspace($webspaceKey); - $system = $webspace->getSecurity()->getSystem(); + $webspace = $webspaceCollection->getWebspace($webspaceKey); + + if (!$webspace) { + throw new \InvalidArgumentException( + sprintf( + 'Webspace "%s" not found for "sulu_community" expected one of %s.', + $webspaceKey, + '"' . implode('", "', $webspaceKeys) . '"' + ) + ); + } + + $security = $webspace->getSecurity(); + + if (!$security) { + throw new \InvalidArgumentException( + sprintf( + 'Missing "Website" configuration in webspace "%s" for "sulu_community".', + $webspaceKey + ) + ); + } + + $system = $security->getSystem(); $systems[$system] = []; } diff --git a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php index 6f337ab0..14b7003b 100644 --- a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php +++ b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php @@ -60,6 +60,9 @@ private function updateWebspaceConfig($webspaceKey, array $webspaceConfig) $webspaceConfig[Configuration::FIREWALL] = $webspaceKey; } + // TODO currently symfony normalize the security firewalls key which will replace "-" with "_". + $webspaceConfig[Configuration::FIREWALL] = str_replace('-', '_', $webspaceConfig[Configuration::FIREWALL]); + // Set role by webspace key if (null === $webspaceConfig[Configuration::ROLE]) { $webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User'; diff --git a/Tests/Unit/Listener/BlacklistListenerTest.php b/Tests/Unit/Listener/BlacklistListenerTest.php index 9c1b5b31..02e25bcd 100644 --- a/Tests/Unit/Listener/BlacklistListenerTest.php +++ b/Tests/Unit/Listener/BlacklistListenerTest.php @@ -76,7 +76,7 @@ public function testValidateEmail() $user->getEmail()->willReturn('test@sulu.io'); $event = $this->prophesize(CommunityEvent::class); - $event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu_io'); + $event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu-io'); $event->getConfigProperty(Configuration::EMAIL_TO)->willReturn(['admin@sulu.io' => 'admin@sulu.io']); $event->getConfigProperty(Configuration::EMAIL_FROM)->willReturn(['from@sulu.io' => 'from@sulu.io']); $event->getConfigTypeProperty(Configuration::TYPE_BLACKLISTED, Configuration::EMAIL)->willReturn( @@ -92,7 +92,7 @@ public function testValidateEmail() Argument::that( function (BlacklistUser $item) use ($user) { return '123-123-123' === $item->getToken() - && 'sulu_io' === $item->getWebspaceKey() + && 'sulu-io' === $item->getWebspaceKey() && $item->getUser() === $user->reveal(); } ) diff --git a/Tests/app/Resources/webspaces/sulu.io.xml b/Tests/app/Resources/webspaces/sulu.io.xml index 0305afef..72a0ae3c 100644 --- a/Tests/app/Resources/webspaces/sulu.io.xml +++ b/Tests/app/Resources/webspaces/sulu.io.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd"> Sulu CMF - sulu_io + sulu-io diff --git a/Tests/app/config/config_website.yml b/Tests/app/config/config_website.yml index 3bbe319b..1a80117a 100644 --- a/Tests/app/config/config_website.yml +++ b/Tests/app/config/config_website.yml @@ -7,7 +7,7 @@ framework: sulu_community: webspaces: - sulu_io: + sulu-io: to: 'admin@sulu.io' sulu_security: