Skip to content

Commit

Permalink
[TASK] Make author fields optional
Browse files Browse the repository at this point in the history
Due to data minimization, users should not be required to enter their email address or website to use the Site Package Builder.

The vendor many ppl use is not the same
as the company name. Also, not everyone works in a company (freelancers, universities, ...) and some customers or organizations want their own vendor no matter who created the site package.

Make vendor its own field.
  • Loading branch information
linawolf committed Nov 30, 2024
1 parent 124f6dd commit 9dd6fdc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/Controller/SitePackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function new(Request $request): Response
$form = $this->createNewSitePackageForm($sitepackage);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$sitepackage->setVendorName(StringUtility::stringToUpperCamelCase($sitepackage->getAuthor()->getCompany()));
$sitepackage->setVendorName(StringUtility::stringToUpperCamelCase($sitepackage->getVendorName()));
$sitepackage->setVendorNameAlternative(StringUtility::camelCaseToLowerCaseDashed($sitepackage->getVendorName()));
$sitepackage->setPackageName(StringUtility::stringToUpperCamelCase($sitepackage->getTitle()));
$sitepackage->setPackageNameAlternative(StringUtility::camelCaseToLowerCaseDashed($sitepackage->getPackageName()));
Expand Down Expand Up @@ -90,7 +90,6 @@ public function edit(Request $request): Response
$form = $this->createEditSitePackageForm($sitepackage);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$sitepackage->setVendorName(StringUtility::stringToUpperCamelCase($sitepackage->getAuthor()->getCompany()));
$sitepackage->setVendorNameAlternative(StringUtility::camelCaseToLowerCaseDashed($sitepackage->getVendorName()));
$sitepackage->setPackageName(StringUtility::stringToUpperCamelCase($sitepackage->getTitle()));
$sitepackage->setPackageNameAlternative(StringUtility::camelCaseToLowerCaseDashed($sitepackage->getPackageName()));
Expand Down
7 changes: 5 additions & 2 deletions src/Entity/SitePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class SitePackage implements \JsonSerializable
#[Assert\NotBlank]
private float $typo3Version = 13.4;

private string $vendorName;

private string $vendorNameAlternative;

#[Assert\NotBlank(message: 'Please enter a title for your site package')]
#[Assert\Length(min: 3)]
#[Assert\Regex(pattern: '/^[A-Za-z0-9\x7f-\xff .:&-]+$/', message: 'Only letters, numbers and spaces are allowed')]
private string $title;

#[Assert\NotBlank(message: 'Please enter a vendor, CamelCase')]
#[Assert\Length(min: 3)]
#[Assert\Regex(pattern: '/^[A-Za-z0-9]+$/', message: 'Only letters and numbers are allowed')]
private string $vendorName;

#[Assert\Regex(pattern: '/^[A-Za-z0-9\x7f-\xff .,:!?&-]+$/', message: 'Only letters, numbers and spaces are allowed')]
private string $description;

Expand Down
8 changes: 1 addition & 7 deletions src/Entity/SitePackage/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@
*/
class Author implements \JsonSerializable
{
#[Assert\NotBlank(message: "Please enter the authors' name.")]
#[Assert\Length(min: 3)]
private string $name;

#[Assert\NotBlank(message: "Please enter the authors' email address.")]
#[Assert\Email(message: "The email '{{ value }}' is not a valid email.")]
private string $email;

#[Assert\NotBlank(message: "Please enter the authors' company.")]
#[Assert\Length(min: 3)]
#[Assert\Regex(pattern: '/^[A-Za-z0-9\x7f-\xff .:&-]+$/', message: 'Only letters, numbers and spaces are allowed')]
#[Assert\Regex(pattern: '/^[\p{L}\p{N} .:&-]+$/u', message: 'Invalid characters in company name.')]
private string $company;

#[Assert\NotBlank(message: "Please enter the authors' homepage URL.")]
#[Assert\Url]
private string $homepage;

Expand Down
8 changes: 8 additions & 0 deletions src/Form/AuthorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'required' => false,
'empty_data' => '',
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'John Doe',
Expand All @@ -45,6 +47,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
])
->add('email', EmailType::class, [
'required' => false,
'empty_data' => '',
'attr' => [
'autocomplete' => 'off',
'placeholder' => '[email protected]',
Expand All @@ -54,6 +58,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
])
->add('company', TextType::class, [
'required' => false,
'empty_data' => '',
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Company Inc.',
Expand All @@ -63,6 +69,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
])
->add('homepage', TextType::class, [
'required' => false,
'empty_data' => '',
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'https://www.example.com',
Expand Down
11 changes: 10 additions & 1 deletion src/Form/SitePackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'placeholder' => 'My Site Package',
],
'documentation' => [
'example' => 'My SitePackage',
'example' => 'My Site Package',
],
])
->add('vendor_name', TextType::class, [
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'MyCompany',
],
'documentation' => [
'example' => 'MyCompany',
],
])
->add('description', TextareaType::class, [
Expand Down
32 changes: 21 additions & 11 deletions templates/sitepackage/success.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,27 @@
<dt class="col-sm-3">Composer</dt>
<dd class="col-sm-9">{{ sitepackage.vendorNameAlternative }}/{{ sitepackage.packageNameAlternative }}</dd>
</dl>
<h3>Author</h3>
<dl class="row">
<dt class="col-sm-3">Name</dt>
<dd class="col-sm-9">{{ sitepackage.author.name }}</dd>
<dt class="col-sm-3">E-Mail</dt>
<dd class="col-sm-9">{{ sitepackage.author.email }}</dd>
<dt class="col-sm-3">Company</dt>
<dd class="col-sm-9">{{ sitepackage.author.company }}</dd>
<dt class="col-sm-3">Homepage</dt>
<dd class="col-sm-9">{{ sitepackage.author.homepage }}</dd>
</dl>
{%- if sitepackage.author.name or sitepackage.author.email or sitepackage.author.company or sitepackage.author.homepage %}
<h3>Author</h3>
<dl class="row">
{%- if sitepackage.author.name %}
<dt class="col-sm-3">Name</dt>
<dd class="col-sm-9">{{ sitepackage.author.name }}</dd>
{%- endif %}
{%- if sitepackage.author.email %}
<dt class="col-sm-3">E-Mail</dt>
<dd class="col-sm-9">{{ sitepackage.author.email }}</dd>
{%- endif %}
{%- if sitepackage.author.company %}
<dt class="col-sm-3">Company</dt>
<dd class="col-sm-9">{{ sitepackage.author.company }}</dd>
{%- endif %}
{%- if sitepackage.author.homepage %}
<dt class="col-sm-3">Homepage</dt>
<dd class="col-sm-9">{{ sitepackage.author.homepage }}</dd>
{%- endif %}
</dl>
{%- endif %}
<p>
<a href="{{ path('sitepackage_new') }}" class="btn btn-light">
<span class="btn-text">Restart</span>
Expand Down
16 changes: 2 additions & 14 deletions tests/Functional/Controller/Api/SitePackageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function createSitePackage(): void
'base_package' => 'bootstrap_package',
'typo3_version' => 13.4,
'title' => 'My Site Package',
'vendor_name' => 'MyVendor',
'description' => 'Project Configuration for Client',
'repository_url' => 'https://github.com/FriendsOfTYPO3/introduction',
'author' => [
Expand Down Expand Up @@ -85,26 +86,13 @@ public function validationMissingCheck(): void
$responseContent = json_decode((string)$response->getContent(), true, 512, JSON_THROW_ON_ERROR);
self::assertSame($responseContent, [
'errors' => [
'Please enter a vendor, CamelCase',
'typo3_version' => [
'The selected choice is invalid.',
],
'title' => [
'Please enter a title for your site package',
],
'author' => [
'name' => [
'Please enter the authors\' name.',
],
'email' => [
'Please enter the authors\' email address.',
],
'company' => [
'Please enter the authors\' company.',
],
'homepage' => [
'Please enter the authors\' homepage URL.',
],
],
],
]);
}
Expand Down

0 comments on commit 9dd6fdc

Please sign in to comment.