Skip to content

Commit

Permalink
Add DPA and Privacy Policy URl on PQ form
Browse files Browse the repository at this point in the history
- New questions where added (dpatype + privacy policy url NL/EN)
- When saving an exisiting entity, also include the privacy questions.
  To achieve that goal, the priv. questions generator had to be called
  explicitly for the different entity type json generators.
  • Loading branch information
MKodde committed Jul 5, 2023
1 parent bac9671 commit 9d39076
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 33 deletions.
17 changes: 17 additions & 0 deletions assets/Resources/metadata/privacy_questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,22 @@
"urns": [
"coin:privacy:other_info"
]
},
{
"id": "dpaType",
"friendlyName": "DPAType",
"getterName": "getDpaType",
"urns": [
"coin:privacy:dpa_type"
]
},
{
"id": "privacyStatementUrl",
"friendlyName": "PrivacyStatementUrl",
"getterName": "getPrivacyStatementUrl",
"urns": [
"mdui:PrivacyStatementURL:nl",
"mdui:PrivacyStatementURL:en"
]
}
]
2 changes: 2 additions & 0 deletions migrations/Version20230620124841.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE privacy_questions DROP certification, DROP certification_location, DROP certification_valid_from, DROP certification_valid_to, DROP surfmarket_dpa_agreement, DROP surfnet_dpa_agreement, DROP sn_dpa_why_not, DROP privacy_policy, DROP privacy_policy_url');
$this->addSql('ALTER TABLE privacy_questions ADD dpa_type LONGTEXT DEFAULT NULL, ADD privacy_statement_url_nl LONGTEXT DEFAULT NULL, ADD privacy_statement_url_en LONGTEXT DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE privacy_questions ADD certification TINYINT(1) DEFAULT NULL, ADD certification_location VARCHAR(255) DEFAULT NULL, ADD certification_valid_from DATE DEFAULT NULL, ADD certification_valid_to DATE DEFAULT NULL, ADD surfmarket_dpa_agreement TINYINT(1) DEFAULT NULL, ADD surfnet_dpa_agreement TINYINT(1) DEFAULT NULL, ADD sn_dpa_why_not LONGTEXT DEFAULT NULL, ADD privacy_policy TINYINT(1) DEFAULT NULL, ADD privacy_policy_url VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE privacy_questions DROP dpa_type, DROP privacy_statement_url_nl, DROP privacy_statement_url_en');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

namespace Surfnet\ServiceProviderDashboard\Application\Command\PrivacyQuestions;

use DateTime;
use Surfnet\ServiceProviderDashboard\Application\Command\Command;
use Surfnet\ServiceProviderDashboard\Domain\Entity\PrivacyQuestions;
use Surfnet\ServiceProviderDashboard\Domain\Entity\Service;
use Surfnet\ServiceProviderDashboard\Domain\ValueObject\DpaType;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @SuppressWarnings(PHPMD.TooManyFields)
Expand Down Expand Up @@ -68,6 +69,22 @@ class PrivacyQuestionsCommand implements Command
*/
private $otherInfo;

/**
* @Assert\NotBlank()
* @Assert\Type("Surfnet\ServiceProviderDashboard\Domain\ValueObject\DpaType")
*/
private DpaType $dpaType;

/**
* @Assert\Url()
*/
public ?string $privacyStatementUrlNl = '';

/**
* @Assert\Url()
*/
public ?string $privacyStatementUrlEn = '';

/**
* @param string $whatData
*/
Expand Down Expand Up @@ -108,6 +125,11 @@ public function setOtherInfo($otherInfo)
$this->otherInfo = $otherInfo;
}

public function setDpaType(string $dpaType)
{
$this->dpaType = DpaType::fromString($dpaType);
}

/**
* @return string
*/
Expand Down Expand Up @@ -164,11 +186,16 @@ public function getMode()
return $this->mode;
}

public function getDpaType(): DpaType
{
return $this->dpaType;
}

public static function fromService(Service $service)
{
$command = new self;
$command->mode = self::MODE_CREATE;

$command->dpaType = DpaType::build(DpaType::DEFAULT);
$command->service = $service;
return $command;
}
Expand All @@ -184,7 +211,9 @@ public static function fromQuestions(PrivacyQuestions $questions)
$command->securityMeasures = $questions->getSecurityMeasures();
$command->service = $questions->getService();
$command->whatData = $questions->getWhatData();

$command->dpaType = DpaType::from($questions);
$command->privacyStatementUrlNl = $questions->getPrivacyStatementUrlNl();
$command->privacyStatementUrlEn = $questions->getPrivacyStatementUrlEn();
return $command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,12 @@ private function setDataFromCommand(PrivacyQuestionsCommand $command, PrivacyQue
$questions->setOtherInfo($command->getOtherInfo());
$questions->setSecurityMeasures($command->getSecurityMeasures());
$questions->setWhatData($command->getWhatData());
$questions->setDpaType($command->getDpaType()->type);
if ($command->privacyStatementUrlEn) {
$questions->setPrivacyStatementUrlEn($command->privacyStatementUrlEn);
}
if ($command->privacyStatementUrlNl) {
$questions->setPrivacyStatementUrlNl($command->privacyStatementUrlNl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ private function generateDataForExistingEntity(
if ($entity->isManageEntity() && !$entity->isExcludedFromPush()) {
$metadata['metaDataFields.coin:exclude_from_push'] = '0';
}
$this->privacyQuestionsMetadataGenerator->withMetadataPrefix();
$metadata += $this->privacyQuestionsMetadataGenerator->build($entity);

return $metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

namespace Surfnet\ServiceProviderDashboard\Application\Metadata\JsonGenerator;

use DateTime;
use stdClass;
use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity;
use Surfnet\ServiceProviderDashboard\Domain\Entity\PrivacyQuestions;
use Surfnet\ServiceProviderDashboard\Domain\Repository\AttributesMetadataRepository;

/**
Expand All @@ -41,6 +42,11 @@
*/
class PrivacyQuestionsMetadataGenerator implements MetadataGenerator
{
/**
* @var true
*/
private bool $addMetaDataPrefix = false;

public function __construct(private readonly AttributesMetadataRepository $repository)
{
}
Expand All @@ -54,21 +60,58 @@ public function build(ManageEntity $entity): array

if ($entity->getService()->isPrivacyQuestionsEnabled()) {
foreach ($privacyQuestions as $question) {
// Get the associated getter
if ($question->id === 'privacyStatementUrl') {
$privacyStatements = $privacyQuestionAnswers->privacyStatementUrls();
$privacyStatementsTranslated = [];
foreach ($privacyStatements as $urn => $value) {
$privacyStatementsTranslated[$this->buildKey($urn)] = $value;
}
$attributes += $privacyStatementsTranslated;
continue;
}

$getterName = $question->getterName;
if ($privacyQuestionAnswers !== null && method_exists($privacyQuestionAnswers, $getterName)) {
$answer = $privacyQuestionAnswers->$getterName();
if (!is_null($answer)) {
// Manage expects booleans as strings.
if (is_bool($answer)) {
$answer = ($answer) ? '1' : '0';
}
$attributes[$question->urns[0]] = $answer;
}
$this->buildPrivacyQuestion(
$attributes,
$getterName,
$privacyQuestionAnswers,
$question
);
}
}
}

return $attributes;
}

public function withMetadataPrefix(): void
{
$this->addMetaDataPrefix = true;
}

private function buildKey(string $urn)
{
if ($this->addMetaDataPrefix) {
return 'metaDataFields.' . $urn;
}
return $urn;
}

public function buildPrivacyQuestion(
array &$attributes,
string $getterName,
PrivacyQuestions $privacyQuestionAnswers,
mixed $question
): void {
$answer = $privacyQuestionAnswers->$getterName();
if (!is_null($answer)) {
// Manage expects booleans as strings.
if (is_bool($answer)) {
$answer = ($answer) ? '1' : '0';
}
$key = $this->buildKey($question->urns[0]);
$attributes[$key] = $answer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ private function generateDataForExistingEntity(
$metadata['state'] = $workflowState;
$metadata += $this->generateAllowedResourceServers($entity);
$this->setExcludeFromPush($metadata, $entity, true);

$this->privacyQuestionsMetadataGenerator->withMetadataPrefix();
$metadata += $this->privacyQuestionsMetadataGenerator->build($entity);

$metadata['revisionnote'] = $entity->getRevisionNote();
return $metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ private function generateDataForExistingEntity(
$metadata += $this->generateAllowedResourceServers($entity);
$this->setExcludeFromPush($metadata, $entity, true);

$this->privacyQuestionsMetadataGenerator->withMetadataPrefix();
$metadata += $this->privacyQuestionsMetadataGenerator->build($entity);

$metadata['revisionnote'] = $entity->getRevisionNote();

return $metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private function generateDataForExistingEntity(

$metadata += $differences->getDiff();
$this->setExcludeFromPush($metadata, $entity, true);

$this->privacyQuestionsMetadataGenerator->withMetadataPrefix();
$metadata += $this->privacyQuestionsMetadataGenerator->build($entity);

$metadata['revisionnote'] = $entity->getRevisionNote();

return $metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ class PrivacyQuestions
*/
private $service;

/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
private $dpaType;

/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
private $privacyStatementUrlNl;

/**
* @var string
* @ORM\Column(type="text", nullable=true)
*/
private $privacyStatementUrlEn;

public function setService(Service $service)
{
$this->service = $service;
Expand Down Expand Up @@ -168,4 +186,46 @@ public function setOtherInfo($otherInfo)
{
$this->otherInfo = $otherInfo;
}

public function setDpaType(string $dpaType): void
{
$this->dpaType = $dpaType;
}

public function getDpaType()
{
return $this->dpaType;
}

public function getPrivacyStatementUrlNl(): ?string
{
return $this->privacyStatementUrlNl;
}

public function setPrivacyStatementUrlNl(?string $privacyStatementUrlNl): void
{
$this->privacyStatementUrlNl = $privacyStatementUrlNl;
}

public function getPrivacyStatementUrlEn(): ?string
{
return $this->privacyStatementUrlEn;
}

public function setPrivacyStatementUrlEn(?string $privacyStatementUrlEn): void
{
$this->privacyStatementUrlEn = $privacyStatementUrlEn;
}

public function privacyStatementUrls(): array
{
$out = [];
if ($this->privacyStatementUrlEn) {
$out['mdui:PrivacyStatementURL:en'] = $this->privacyStatementUrlEn;
}
if ($this->privacyStatementUrlNl) {
$out['mdui:PrivacyStatementURL:nl'] = $this->privacyStatementUrlNl;
}
return $out;
}
}
Loading

0 comments on commit 9d39076

Please sign in to comment.