Skip to content

Commit

Permalink
Add new paramter in TermsVersionSignatureFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Feb 27, 2024
1 parent 7e4a6e9 commit 374faa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Domain/Factory/TermsVersionSignatureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public function __construct(SecurityInterface $security, TranslatorInterface $tr
$this->termsGuardManager = $termsGuardManager;
}

public function __invoke(TermsVersion $version, TermsSubjectInterface $subject): TermsVersionSignature
public function __invoke(TermsVersion $version, TermsSubjectInterface $subject, ?TermsUserInterface $signatory = null): TermsVersionSignature
{
$guard = $this->termsGuardManager->getGuardFor($version->getTerms()->getSlug() ?? '', $subject);
$subjectName = $guard !== null ? $guard->getSubjectName($subject) : null;
$subjectName = $subjectName ?? $this->translator->trans('terms_module.pdf_signature.subject_not_found', [], 'terms_module');

$user = $this->security->getUser();
$signatory = $signatory ?? $user;

$entity = new TermsVersionSignature();

Expand All @@ -50,9 +51,9 @@ public function __invoke(TermsVersion $version, TermsSubjectInterface $subject):
$entity->setSignedBy($user->getUsername());
}

if ($user instanceof TermsUserInterface) {
$entity->setSignedByName($user->getTermsDisplayName());
$entity->setSignedByNameForSort($user->getTermsDisplayNameForSort());
if ($signatory instanceof TermsUserInterface) {
$entity->setSignedByName($signatory->getTermsDisplayName());
$entity->setSignedByNameForSort($signatory->getTermsDisplayNameForSort());
}

return $entity;
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/UseCase/SignTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace RichId\TermsModuleBundle\Domain\UseCase;

use RichId\TermsModuleBundle\Domain\Entity\TermsSubjectInterface;
use RichId\TermsModuleBundle\Domain\Entity\TermsUserInterface;
use RichId\TermsModuleBundle\Domain\Event\TermsSignedEvent;
use RichId\TermsModuleBundle\Domain\Factory\TermsVersionSignatureFactory;
use RichId\TermsModuleBundle\Domain\Fetcher\GetTermsVersionToSign;
Expand Down Expand Up @@ -44,12 +45,12 @@ public function __construct(
$this->getTermsVersionToSign = $getTermsVersionToSign;
}

public function __invoke(string $termsSlug, TermsSubjectInterface $subject, ?bool $accepted): Response
public function __invoke(string $termsSlug, TermsSubjectInterface $subject, ?bool $accepted, ?TermsUserInterface $signatory = null): Response
{
$lastVersion = ($this->getTermsVersionToSign)($termsSlug, $subject);

if ($accepted === true) {
$signature = ($this->termsVersionSignatureFactory)($lastVersion, $subject);
$signature = ($this->termsVersionSignatureFactory)($lastVersion, $subject, $signatory);
$this->entityRecoder->saveSignature($signature);
}

Expand Down

0 comments on commit 374faa3

Please sign in to comment.