-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Surf representative a role on its own #638
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
use Surfnet\ServiceProviderDashboard\Application\ViewObject\EntityConnection; | ||
use Surfnet\ServiceProviderDashboard\Application\ViewObject\EntityConnectionCollection; | ||
use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants; | ||
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\MetaData; | ||
use Surfnet\ServiceProviderDashboard\Domain\Entity\IdentityProvider; | ||
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; | ||
use Surfnet\ServiceProviderDashboard\Domain\Entity\Service; | ||
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\InstitutionId; | ||
|
||
|
@@ -56,22 +58,22 @@ public function findByServices(array $services): EntityConnectionCollection | |
$this->addEntitiesToCollection( | ||
$collection, | ||
$institutionId, | ||
$service, | ||
$this->getTestIdpsIndexed(), | ||
$service, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider using named parameters, then the order doesn't matter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never considered using that. in this case the service argument became optional, and needed to be moved to the bottom of the stack. Leaving this as-is. But thanks for the suggestion for using the NamedParameters. Going to read up on them. |
||
); | ||
} | ||
return $collection; | ||
} | ||
|
||
public function findByInstitutionId(InstitutionId $institutionId, Service $service): EntityConnectionCollection | ||
public function findByInstitutionId(InstitutionId $institutionId, ?Service $service): EntityConnectionCollection | ||
{ | ||
$collection = new EntityConnectionCollection(); | ||
$this->addIdpList($collection); | ||
$this->addEntitiesToCollection( | ||
$collection, | ||
$institutionId, | ||
$service, | ||
$this->getTestIdpsIndexed(), | ||
$service, | ||
); | ||
return $collection; | ||
} | ||
|
@@ -95,8 +97,8 @@ private function addIdpList(EntityConnectionCollection $collection): void | |
private function addEntitiesToCollection( | ||
EntityConnectionCollection $collection, | ||
InstitutionId $institutionId, | ||
Service $service, | ||
array $testIdpsIndexed | ||
array $testIdpsIndexed, | ||
?Service $service = null, | ||
): void { | ||
$list = []; | ||
$entities = $this->entityService->findPublishedTestEntitiesByInstitutionId($institutionId); | ||
|
@@ -110,27 +112,12 @@ private function addEntitiesToCollection( | |
// Skipping irrelevant entity types | ||
continue; | ||
} | ||
$metadata = $entity->getMetaData(); | ||
if ($metadata === null) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'No metadata available on entity with manage id: %s', | ||
$entity->getId() | ||
) | ||
); | ||
} | ||
if ($metadata->getNameEn() === null) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'No name:en available for entity with manage id: %s', | ||
$entity->getId() | ||
) | ||
); | ||
} | ||
$metadata = $this->assertValidMetadata($entity); | ||
if ($entity->getAllowedIdentityProviders()->isAllowAll()) { | ||
$serviceName = $service !== null ? $service->getOrganizationNameEn() : 'Unknown service name'; | ||
$list[$entity->getId()] = new EntityConnection( | ||
$metadata->getNameEn(), | ||
$service->getOrganizationNameEn(), | ||
$serviceName, | ||
$testIdpsIndexed, | ||
$testIdpsIndexed, | ||
); | ||
|
@@ -145,7 +132,7 @@ private function addEntitiesToCollection( | |
|
||
$list[$entity->getId()] = new EntityConnection( | ||
$metadata->getNameEn(), | ||
$service->getOrganizationNameEn(), | ||
$service !== null ? $service->getOrganizationNameEn() : 'Unknown service name', | ||
$testIdpsIndexed, | ||
$connectedIdps, | ||
); | ||
|
@@ -168,4 +155,26 @@ private function getTestIdpsIndexed(): array | |
|
||
return $testIdpsIndexed; | ||
} | ||
|
||
private function assertValidMetadata(ManageEntity $entity): MetaData | ||
{ | ||
$metadata = $entity->getMetaData(); | ||
if ($metadata === null) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'No metadata available on entity with manage id: %s', | ||
$entity->getId() | ||
) | ||
); | ||
} | ||
if ($metadata->getNameEn() === null) { | ||
throw new RuntimeException( | ||
sprintf( | ||
'No name:en available for entity with manage id: %s', | ||
$entity->getId() | ||
) | ||
); | ||
} | ||
return $metadata; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Copyright 2024 SURFnet B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
class EntrypointController extends AbstractController | ||
{ | ||
#[Route(path: '/', name: 'entrypoint', methods: ['GET'])] | ||
public function __invoke(): RedirectResponse | ||
{ | ||
// When surfconext responsible, go tho the connections page | ||
if ($this->isGranted('ROLE_SURFCONEXT_RESPONSIBLE')) { | ||
return $this->redirectToRoute('service_connections'); | ||
} | ||
// Otherwise start at the service overview page | ||
return $this->redirectToRoute('service_overview'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple to fix with a ? in front of the variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that could be a solution. But I do not want to loosen type safety, the creating side should be more defensive. And thats where this baseline entry came from.