Skip to content

Commit ba1d405

Browse files
committed
Merge remote-tracking branch 'origin/feat-108625-ibexa-4-form-mail-protection' into feat-108625-ibexa-4-form-mail-protection
2 parents d0bc60e + eb26c0f commit ba1d405

21 files changed

+697
-268
lines changed

components/ProtectedContentBundle/README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,30 @@ Documentation is available in this repository via `.md` files but also packaged
1717

1818
A bundle that provides quick password protection on Contents.
1919

20-
## How does it work?
20+
# How it works
2121

2222
Allows you to add 1 on N password on a Content in the Admin UI.
23+
Once a protection is set, the Content becomes Protected.
24+
In this situation you can have 3 new variables in the view full
25+
- canReadProtectedContent (always)
26+
- requestProtectedContentPasswordForm (if content is protected by password)
27+
- requestProtectedContentEmailForm (if content is protected with email verification)
2328

24-
Once a Password is set, the Content becomes Protected. In this situation you will have 2 new variables in the view full.
2529
Allowing you do:
26-
2730
```twig
28-
<h2>{{ ibexa_content_name(content) }}</h2>
31+
<h2>{{ ez_content_name(content) }}</h2>
2932
{% if not canReadProtectedContent %}
30-
<p>This content has been protected by a password</p>
31-
<div class="protected-content-form">
32-
{{ form(requestProtectedContentPasswordForm) }}
33-
</div>
33+
{% if requestProtectedContentPasswordForm is defined %}
34+
<p>This content has been protected by a password</p>
35+
<div class="protected-content-form">
36+
{{ form(requestProtectedContentPasswordForm) }}
37+
</div>
38+
{% elseif requestProtectedContentEmailForm is defined %}
39+
<p>This content has been protected by an email verification</p>
40+
<div class="protected-content-form">
41+
{{ form(requestProtectedContentEmailForm) }}
42+
</div>
43+
{% endif %}
3444
{% else %}
3545
{% for field in content.fieldsByLanguage(language|default(null)) %}
3646
<h3>{{ field.fieldDefIdentifier }}</h3>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* NovaeZProtectedContentBundle.
5+
*
6+
* @package Novactive\Bundle\eZProtectedContentBundle
7+
*
8+
* @author Novactive
9+
* @copyright 2023 Novactive
10+
* @license https://github.com/Novactive/eZProtectedContentBundle/blob/master/LICENSE MIT Licence
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace Novactive\Bundle\eZProtectedContentBundle\Command;
16+
17+
use Novactive\Bundle\eZProtectedContentBundle\Repository\ProtectedTokenStorageRepository;
18+
use Symfony\Component\Console\Command\Command;
19+
use Symfony\Component\Console\Input\InputInterface;
20+
use Symfony\Component\Console\Output\OutputInterface;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
22+
23+
class CleanTokenCommand extends Command
24+
{
25+
public function __construct(
26+
protected ProtectedTokenStorageRepository $protectedTokenStorageRepository,
27+
) {
28+
parent::__construct();
29+
}
30+
31+
protected function configure(): void
32+
{
33+
$this
34+
->setName('novaezprotectedcontent:cleantoken')
35+
->setDescription('Remove expired token in the DB');
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function execute(InputInterface $input, OutputInterface $output): int
42+
{
43+
$io = new SymfonyStyle($input, $output);
44+
45+
$entities = $this->protectedTokenStorageRepository->findExpired();
46+
47+
$io->comment(sprintf('%d entities to delete', count($entities)));
48+
49+
foreach ($entities as $entity) {
50+
$this->protectedTokenStorageRepository->remove($entity);
51+
}
52+
53+
$this->protectedTokenStorageRepository->flush();
54+
55+
$io->success(sprintf('%d entities deleted', count($entities)));
56+
$io->success('Done.');
57+
58+
return Command::SUCCESS;
59+
}
60+
}

components/ProtectedContentBundle/bundle/Controller/Admin/ProtectedAccessController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function handle(
6262
return new RedirectResponse(
6363
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
6464
'locationId' => $location->id,
65-
]).
65+
]).
6666
'#ibexa-tab-location-view-protect-content#tab'
6767
);
6868
}
@@ -86,7 +86,7 @@ public function remove(
8686
return new RedirectResponse(
8787
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
8888
'locationId' => $location->id,
89-
]).
89+
]).
9090
'#ibexa-tab-location-view-protect-content#tab'
9191
);
9292
}

components/ProtectedContentBundle/bundle/Core/SiteAccessAwareEntityManagerFactory.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

components/ProtectedContentBundle/bundle/DependencyInjection/NovaeZProtectedContentExtension.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,33 @@
1616

1717
use Symfony\Component\Config\FileLocator;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1920
use Symfony\Component\DependencyInjection\Loader;
2021
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2122

22-
class NovaeZProtectedContentExtension extends Extension
23+
class NovaeZProtectedContentExtension extends Extension implements PrependExtensionInterface
2324
{
2425
public function load(array $configs, ContainerBuilder $container): void
2526
{
2627
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2728
$loader->load('services.yaml');
2829
}
30+
31+
public function prepend(ContainerBuilder $container)
32+
{
33+
$config = [
34+
'orm' => [
35+
'entity_mappings' => [
36+
'eZProtectedContentBundle' => [
37+
'type' => 'annotation',
38+
'dir' => __DIR__.'/../Entity',
39+
'prefix' => 'Novactive\Bundle\eZProtectedContentBundle\Entity',
40+
'is_bundle' => false,
41+
],
42+
],
43+
],
44+
];
45+
46+
$container->prependExtensionConfig('ibexa', $config);
47+
}
2948
}

components/ProtectedContentBundle/bundle/Entity/ProtectedAccess.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/**
2222
* @ORM\Entity()
2323
* @ORM\Table(name="novaezprotectedcontent")
24-
* @ORM\EntityListeners({"Novactive\Bundle\eZProtectedContentBundle\Listener\EntityContentLink"})
2524
*/
2625
class ProtectedAccess implements ContentInterface
2726
{
@@ -40,8 +39,7 @@ class ProtectedAccess implements ContentInterface
4039
/**
4140
* @var string
4241
*
43-
* @ORM\Column(type="string", length=255, nullable=false)
44-
* @Assert\NotBlank()
42+
* @ORM\Column(type="string", length=255, nullable=true)
4543
* @Assert\Length(max=255)
4644
*/
4745
protected $password;
@@ -53,13 +51,27 @@ class ProtectedAccess implements ContentInterface
5351
*/
5452
protected $enabled;
5553

54+
/**
55+
* @var bool
56+
*
57+
* @ORM\Column(type="boolean", nullable=false)
58+
*/
59+
protected $asEmail = false;
60+
5661
/**
5762
* @var bool
5863
*
5964
* @ORM\Column(type="boolean", nullable=false)
6065
*/
6166
protected $protectChildren;
6267

68+
/**
69+
* @var string
70+
*
71+
* @ORM\Column(type="string", nullable=true)
72+
*/
73+
protected $emailMessage;
74+
6375
public function __construct()
6476
{
6577
$this->enabled = true;
@@ -78,12 +90,24 @@ public function setId(int $id): self
7890
return $this;
7991
}
8092

93+
public function getAsEmail(): bool
94+
{
95+
return $this->asEmail ?? false;
96+
}
97+
98+
public function setAsEmail(bool $asEmail): self
99+
{
100+
$this->asEmail = $asEmail;
101+
102+
return $this;
103+
}
104+
81105
public function getPassword(): string
82106
{
83107
return $this->password ?? '';
84108
}
85109

86-
public function setPassword(string $password): self
110+
public function setPassword(?string $password): self
87111
{
88112
$this->password = $password;
89113

@@ -111,4 +135,14 @@ public function setProtectChildren(bool $protectChildren): void
111135
{
112136
$this->protectChildren = $protectChildren;
113137
}
138+
139+
public function getEmailMessage(): ?string
140+
{
141+
return $this->emailMessage;
142+
}
143+
144+
public function setEmailMessage(string $emailMessage): void
145+
{
146+
$this->emailMessage = $emailMessage;
147+
}
114148
}

0 commit comments

Comments
 (0)