Skip to content

Commit

Permalink
Merge branch 'feature/type-of-service-ccc' into feature/type-of-servi…
Browse files Browse the repository at this point in the history
…ce-manage
  • Loading branch information
MKodde committed Jul 8, 2024
2 parents d6a7da4 + 078820c commit 2ae127c
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 70 deletions.
5 changes: 0 additions & 5 deletions ci/qa/phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,6 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Application/Factory/EntityDetailFactory.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getCoin\\(\\) on Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\Entity\\\\Entity\\\\MetaData\\|null\\.$#',
'count' => 2,
'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Application/Factory/EntityDetailFactory.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getContacts\\(\\) on Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\Entity\\\\Entity\\\\MetaData\\|null\\.$#',
'count' => 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Surfnet\ServiceProviderDashboard\Domain\Entity\Service;
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\Contact;
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\TypeOfService;
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\TypeOfServiceCollection;

interface SaveEntityCommandInterface extends Command
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,6 @@ class SaveOauthClientCredentialClientCommand implements SaveEntityCommandInterfa
#[Assert\Url]
private $applicationUrl;

/** @var TypeOfService[] */
#[Assert\All([
new Assert\NotBlank(),
new Assert\Type(type: TypeOfService::class),
])]
#[Assert\Count(
min: 1,
max: 3,
minMessage: 'validator.type-of-service.min',
maxMessage: 'validator.type-of-service.max',
)]
private array $typeOfService;

/**
* @var string
*/
Expand Down Expand Up @@ -550,19 +537,9 @@ public function getAcsLocations(): ?array
return null;
}

/**
* @return TypeOfService[]
*/
public function getTypeOfService(): array
{
return $this->typeOfService;
}

/**
* @param TypeOfService[] $typeOfService
*/
public function setTypeOfService(array $typeOfService): void
{
$this->typeOfService = $typeOfService;
// not implemented for oauth_ccc entities
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function buildFrom(ManageEntity $manageEntity): EntityDetail
$manageEntity->getMetaData()->getNameEn(),
$manageEntity->getMetaData()->getDescriptionNl(),
$manageEntity->getMetaData()->getDescriptionEn(),
$manageEntity->getMetaData()->getCoin()->getApplicationUrl(),
$manageEntity->getMetaData()->getCoin()->getEula(),
$manageEntity->getMetaData()?->getCoin()->getApplicationUrl(),
$manageEntity->getMetaData()?->getCoin()->getEula(),
$manageEntity->getMetaData()->getContacts()->findAdministrativeContact(),
$manageEntity->getMetaData()->getContacts()->findTechnicalContact(),
$manageEntity->getMetaData()->getContacts()->findSupportContact(),
Expand All @@ -106,7 +106,8 @@ public function buildFrom(ManageEntity $manageEntity): EntityDetail
$playgroundEnabled,
$accessTokenValidity,
$isPublicClient,
$resourceServers
$resourceServers,
$manageEntity->getMetaData()?->getCoin()->getTypeOfService()->getServicesAsArray()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ private function buildOrganizationFromCommand(SaveEntityCommandInterface $comman

private function buildCoinFromCommand(SaveEntityCommandInterface $command): Coin
{
$typeOfService = new TypeOfServiceCollection();
$typeOfServiceCollection = new TypeOfServiceCollection();
foreach ($command->getTypeOfService() as $typeOfService) {
$typeOfService->add($typeOfService);
$typeOfServiceCollection->add($typeOfService);
}

return new Coin(
Expand All @@ -223,7 +223,7 @@ private function buildCoinFromCommand(SaveEntityCommandInterface $command): Coin
null,
null,
$command->getApplicationUrl(),
$typeOfService,
$typeOfServiceCollection,
$command->getEulaUrl(),
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class EntityDetail
{
public $organizationUnitNameAttribute;
/**
* @param ManageEntity[]|null $resourceServers
* @param ManageEntity[]|null $resourceServers
* @param array<string>|null $typeOfService
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -66,6 +67,7 @@ public function __construct(
private readonly ?int $accessTokenValidity,
private readonly ?bool $isPublicClient,
private readonly ?array $resourceServers,
private readonly ?array $typeOfService,
) {
}

Expand Down Expand Up @@ -260,4 +262,12 @@ public function getResourceServers(): ?array
{
return $this->resourceServers;
}

/**
* @return array<string>|null
*/
public function typeOfService(): ?array
{
return $this->typeOfService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,16 @@ public function getServicesAsEnglishString(): string
}
return implode(',', $commasSeperated);
}

/**
* @return array<string>
*/
public function getServicesAsArray(): array
{
$services = [];
foreach ($this->types as $type) {
$services[] = $type->typeEn;
}
return $services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use Surfnet\ServiceProviderDashboard\Application\Service\EntityServiceInterface;
use Surfnet\ServiceProviderDashboard\Application\Factory\EntityDetailFactory;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Service\AuthorizationService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

use Surfnet\ServiceProviderDashboard\Application\Command\Entity\SaveOauthClientCredentialClientCommand;
use Surfnet\ServiceProviderDashboard\Application\Command\Entity\SaveOidcngEntityCommand;
use Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepository;
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\TypeOfService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
Expand All @@ -40,7 +38,6 @@ class OauthClientCredentialEntityType extends AbstractType
{
public function __construct(
private readonly OidcngResourceServerOptionsFactory $oidcngResourceServerOptionsFactory,
private readonly TypeOfServiceRepository $typeOfServiceProvider
) {
}

Expand Down Expand Up @@ -168,22 +165,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
]
)
->add(
'typeOfService',
ChoiceType::class,
[
'required' => false,
'choices' => $this->typeOfServiceProvider->getTypesOfServiceChoices(),
'choice_value' => fn(TypeOfService $tos): string => $tos->typeEn,
'choice_label' => fn(TypeOfService $tos): string => $tos->typeEn,
'expanded' => true,
'multiple' => true,
'attr' => [
'class' => 'type-of-service',
'data-help' => 'entity.edit.information.typeOfService',
],
]
)
->add(
'eulaUrl',
TextType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'typeOfService',
ChoiceType::class,
[
'required' => false,
'required' => true,
'choices' => $this->typeOfServiceProvider->getTypesOfServiceChoices(),
'choice_value' => fn(TypeOfService $tos): string => $tos->typeEn,
'choice_label' => fn(TypeOfService $tos): string => $tos->typeEn,
'choice_attr' => fn(): array => [
'class' => 'decorated',
'data-parsley-mincheck' => 1,
'data-parsley-maxcheck' => 3,
],
'expanded' => true,
'multiple' => true,
'attr' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'typeOfService',
ChoiceType::class,
[
'required' => false,
'required' => true,
'choices' => $this->typeOfServiceProvider->getTypesOfServiceChoices(),
'choice_value' => fn(TypeOfService $tos): string => $tos->typeEn,
'choice_label' => fn(TypeOfService $tos): string => $tos->typeEn,
'choice_attr' => fn(): array => [
'class' => 'decorated',
'data-parsley-mincheck' => 1,
'data-parsley-maxcheck' => 3,
],
'expanded' => true,
'multiple' => true,
'attr' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ entity:
redirect_uris: Redirect URIs
playground_enabled: Playground enabled?
name_id_format: NameID format
type_of_service: Type of service
subject_type: Subject type
certificate: Certificate
logo_url: Logo URL
Expand Down
4 changes: 4 additions & 0 deletions templates/EntityDetail/detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
{% if entity.protocol == "saml20" %}
{% include '@Dashboard/EntityDetail/detailTextField.html.twig' with {label: 'entity.detail.metadata.entity_id'|trans, value: entity.entityId, informationPopup: 'entity.edit.information.entityId'} %}
{% include '@Dashboard/EntityDetail/detailTextField.html.twig' with {label: 'entity.detail.metadata.name_id_format'|trans, value: entity.nameIdFormat|replace({'urn:oasis:names:tc:SAML:2.0:nameid-format:': ''}), informationPopup: 'entity.edit.information.nameIdFormat'} %}
{% include '@Dashboard/EntityDetail/detailListField.html.twig' with {label: 'entity.detail.metadata.type_of_service'|trans, value: entity.typeOfService, informationPopup: 'entity.edit.information.typeOfService'} %}

{% endif %}

{% if entity.protocol == "oidcng" %}
Expand All @@ -33,6 +35,8 @@
{% include '@Dashboard/EntityDetail/detailBooleanField.html.twig' with {label: 'entity.detail.metadata.playground_enabled'|trans, value: entity.playgroundEnabled, informationPopup: 'entity.edit.information.enablePlayground'} %}
{% include '@Dashboard/EntityDetail/detailBooleanField.html.twig' with {label: 'entity.detail.metadata.is_public_client'|trans, value: entity.publicClient, informationPopup: 'entity.edit.information.isPublicClient'} %}
{% include '@Dashboard/EntityDetail/detailTextField.html.twig' with {label: 'entity.detail.metadata.access_token_validity'|trans, value: entity.accessTokenValidity, informationPopup: 'entity.edit.information.accessTokenValidity'} %}
{% include '@Dashboard/EntityDetail/detailListField.html.twig' with {label: 'entity.detail.metadata.type_of_service'|trans, value: entity.typeOfService, informationPopup: 'entity.edit.information.typeOfService'} %}

{% endif %}

{% if entity.protocol == "oauth20_rs" %}
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Domain/Entity/Entity/CoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ public function test_it_can_merge_data(Coin $coin, Coin $newData, Coin $expectat
public function provideCoinTestData()
{
yield [
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1),
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1),
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1)
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1)
];
yield [
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1),
new Coin('signatureMethod', null, 'https://www.example.com', null, 'https://example.com', null, 'https://example.com/eula', 1),
new Coin('signatureMethod', null, 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1),
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
new Coin('signatureMethod', null, 'https://www.example.com', null, 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
new Coin('signatureMethod', null, 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
];
yield [
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', null, 'https://example.com/eula', 1),
new Coin(null, null, null, null, null, null, null, null),
new Coin(null, null, null, '1', null, null, null, null)
new Coin('signatureMethod', '23', 'https://www.example.com', '1', 'https://example.com', new TypeOfServiceCollection(), 'https://example.com/eula', 1),
new Coin(null, null, null, null, null, new TypeOfServiceCollection(), null, null),
new Coin(null, null, null, '1', null, new TypeOfServiceCollection(), null, null)
];
}
public function provideCoinTestDataWithTypeOfService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public function test_it_has_all_sp_dashboard_attributes()
"applicationUrl",
"teamID",
"originalMetadataUrl",
"typeOfService",
];

$attributes = $this->repository->findAllSpDashboardAttributes();

$this->assertCount(4, $attributes);
$this->assertCount(5, $attributes);
foreach ($attributes as $attribute) {
$this->assertContains($attribute->id, $expectedAttributes);
}
Expand Down

0 comments on commit 2ae127c

Please sign in to comment.