Skip to content

Commit

Permalink
Display revision notes when publishing new entity
Browse files Browse the repository at this point in the history
This note does not contain the Jira ticket number as it is not created
yet. The jira ticket relies on the Manage ID to be present.

Catch 22
  • Loading branch information
MKodde committed Jul 17, 2024
1 parent 6bfd56f commit 7f22213
Show file tree
Hide file tree
Showing 36 changed files with 390 additions and 145 deletions.
5 changes: 0 additions & 5 deletions ci/qa/phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2871,11 +2871,6 @@
'count' => 2,
'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$manageId of class Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\ValueObject\\\\Ticket constructor expects string, string\\|null given\\.$#',
'count' => 2,
'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#3 \\$entityName of class Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\ValueObject\\\\Ticket constructor expects string, string\\|null given\\.$#',
'count' => 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ class PublishEntityTestCommand implements Command
public function __construct(
#[Assert\Type(ManageEntity::class)]
private readonly ManageEntity $manageEntity,
private readonly Contact $applicant,
) {
}

public function getManageEntity(): ManageEntity
{
return $this->manageEntity;
}

public function getApplicant(): Contact
{
return $this->applicant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@
namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity;

use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Validator\Constraints as SpDashboardAssert;

class ResetOidcSecretCommand implements Command
{
public function __construct(
private readonly ManageEntity $manageEntity,
private readonly Contact $applicant,
) {
}

public function getManageEntity(): ManageEntity
{
return $this->manageEntity;
}

public function getApplicant(): Contact
{
return $this->applicant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity;

use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\IdentityProvider;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Service;
Expand All @@ -37,6 +38,7 @@ public function __construct(
])]
private array $selected,
private bool $selectAll,
private readonly Contact $applicant,
) {
}

Expand Down Expand Up @@ -73,4 +75,9 @@ public function setSelectAll($selectAll): void
{
$this->selectAll = (bool)$selectAll;
}

public function getApplicant(): Contact
{
return $this->applicant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity;

use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\IdentityProvider;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -45,6 +46,7 @@ public function __construct(
new Assert\Type(type: IdentityProvider::class),
])]
public array $institutionEntities,
public readonly Contact $applicant,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Surfnet\ServiceProviderDashboard\Application\Service\MailService;
use Surfnet\ServiceProviderDashboard\Application\Service\TicketService;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Domain\Repository\PublishEntityRepository;
use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException;
Expand Down Expand Up @@ -80,17 +81,13 @@ public function handle(PublishProductionCommandInterface $command): void
$entity->getMetaData()->getNameEn()
)
);
$publishResponse = $this->publishClient->publish($entity, $pristineEntity);
$publishResponse = $this->publishClient->publish(
$entity,
$pristineEntity,
$command->getApplicant(),
);
if (array_key_exists('id', $publishResponse)) {
$entity->setId($publishResponse['id']);

$this->logger->info(
sprintf(
'Updating status of "%s" to published',
$entity->getMetaData()->getNameEn()
)
);

// No need to create a Jira ticket when resetting the client secret
if ($command instanceof PublishEntityProductionCommand && !$command->isClientReset()) {
$this->ticketService->createJiraTicket(
Expand All @@ -101,6 +98,12 @@ public function handle(PublishProductionCommandInterface $command): void
$this->descriptionTranslationKey
);
}
$this->logger->info(
sprintf(
'Updating status of "%s" to published',
$entity->getMetaData()->getNameEn()
)
);
} else {
$this->logger->error(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException;
use Surfnet\ServiceProviderDashboard\Application\Service\EntityServiceInterface;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Domain\Repository\PublishEntityRepository;
use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException;
Expand Down Expand Up @@ -60,7 +62,11 @@ public function handle(PublishEntityTestCommand $command): void
)
);

$publishResponse = $this->publishClient->publish($entity, $pristineEntity);
$publishResponse = $this->publishClient->publish(
$entity,
$pristineEntity,
$command->getApplicant(),
);
if (array_key_exists('id', $publishResponse)) {
if ($this->isNewResourceServer($entity)) {
$this->requestStack->getSession()->getFlashBag()->add('wysiwyg', 'entity.list.oidcng_connection.info.html');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function handle(ResetOidcSecretCommand $command): void
$publishCommand->markPublishClientReset();
$this->commandBus->handle($publishCommand);
} elseif ($entity->getEnvironment() === Constants::ENVIRONMENT_TEST) {
$publishCommand = new PublishEntityTestCommand($entity);
$publishCommand = new PublishEntityTestCommand($entity, $command->getApplicant());
$this->commandBus->handle($publishCommand);
}
if (!$entity->isExcludedFromPush()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handle(UpdateEntityAclCommand $command): void
$allowedIdps = new AllowedIdentityProviders($idps, $command->isSelectAll());
$entity->getAllowedIdentityProviders()->merge($allowedIdps);
try {
$this->publishClient->publish($entity, $entity, 'ACL');
$this->publishClient->publish($entity, $entity, $command->getApplicant(), 'ACL');
} catch (PublishMetadataException $e) {
$this->logger->error(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(UpdateEntityIdpsCommand $command): void
$allowedIdps = new AllowedIdentityProviders($idps, $allowedAll);
$entity->getAllowedIdentityProviders()->merge($allowedIdps);
try {
$this->publishClient->publish($entity, $entity, 'ACL');
$this->publishClient->publish($entity, $entity, $command->applicant, 'ACL');
} catch (Exception $e) {
$this->logger->error(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ interface GeneratorInterface
/**
* Convert a new, unpublished entity to json-serializable array.
*/
public function generateForNewEntity(ManageEntity $entity, string $workflowState): array;
public function generateForNewEntity(
ManageEntity $entity,
string $workflowState,
Contact $contact,
): array;

/**
* Convert entity to an array for the manage merge-write API call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber;
use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
Expand All @@ -44,13 +45,22 @@ public function __construct(
) {
}

public function generateForNewEntity(ManageEntity $entity, string $workflowState): array
{
public function generateForNewEntity(
ManageEntity $entity,
string $workflowState,
ContactEntity $contact,
): array {
// the type for entities is always saml because manage is using saml internally
return [
$payload = [
'data' => $this->generateDataForNewEntity($entity, $workflowState),
'type' => 'saml20_sp',
];
$payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
);
return $payload;
}

public function generateForExistingEntity(
Expand All @@ -75,20 +85,22 @@ public function generateEntityChangeRequest(
ContactEntity $contact,
JiraTicketNumber $jiraTicketNumber,
): array {
$revisionNote = (string) new ChangeRequestRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
$jiraTicketNumber,
);
$payload = [
'metaDataId' => $entity->getId(),
'type' => 'saml20_sp',
'pathUpdates' => $this->generateForChangeRequest($entity, $differences),
'auditData' => [
'user' => $contact->getEmailAddress(),
'notes' => $revisionNote,
],
];
$payload['note'] = (string) new ChangeRequestRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
$jiraTicketNumber,
);
$payload['note'] = $revisionNote;
return $payload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ public function addStrategy($identifier, GeneratorInterface $generator): void
/**
* @throws JsonGeneratorStrategyNotFoundException
*/
public function generateForNewEntity(ManageEntity $entity, string $workflowState): array
{
return $this->getStrategy($entity->getProtocol()->getProtocol())->generateForNewEntity($entity, $workflowState);
public function generateForNewEntity(
ManageEntity $entity,
string $workflowState,
Contact $contact,
): array {
return $this->getStrategy($entity->getProtocol()->getProtocol())->generateForNewEntity(
$entity,
$workflowState,
$contact,
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber;
use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
Expand All @@ -49,13 +50,22 @@ public function __construct(
) {
}

public function generateForNewEntity(ManageEntity $entity, string $workflowState): array
{
public function generateForNewEntity(
ManageEntity $entity,
string $workflowState,
ContactEntity $contact,
): array {
// The Oauth Client Credential Client is actually an oidc10_rp entity
return [
$payload = [
'data' => $this->generateDataForNewEntity($entity, $workflowState),
'type' => 'oidc10_rp',
];
$payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
);
return $payload;
}

public function generateForExistingEntity(
Expand Down Expand Up @@ -96,23 +106,22 @@ public function generateEntityChangeRequest(
ContactEntity $contact,
JiraTicketNumber $jiraTicketNumber,
): array {
$revisionNote = (string) new ChangeRequestRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
$jiraTicketNumber,
);
$payload = [
'metaDataId' => $entity->getId(),
'type' => 'oidc10_rp',
'pathUpdates' => $this->generateForChangeRequest($differences),
'auditData' => [
'user' => $contact->getEmailAddress(),
'notes' => $revisionNote
],
];

$payload['note'] = (string) new ChangeRequestRevisionNote(
$entity->getComments(),
$contact->getDisplayName(),
$contact->getEmailAddress(),
$jiraTicketNumber,
);


$payload['note'] = $revisionNote;
return $payload;
}

Expand Down
Loading

0 comments on commit 7f22213

Please sign in to comment.