Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions components/ProtectedContentBundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@ Documentation is available in this repository via `.md` files but also packaged

A bundle that provides quick password protection on Contents.

## How does it work?
# How it works

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

Once a Password is set, the Content becomes Protected. In this situation you will have 2 new variables in the view full.
Allowing you do:

```twig
<h2>{{ ibexa_content_name(content) }}</h2>
{% if not canReadProtectedContent %}
<p>This content has been protected by a password</p>
<div class="protected-content-form">
{{ form(requestProtectedContentPasswordForm) }}
</div>
{% if requestProtectedContentPasswordForm is defined %}
<p>This content has been protected by a password</p>
<div class="protected-content-form">
{{ form(requestProtectedContentPasswordForm) }}
</div>
{% elseif requestProtectedContentEmailForm is defined %}
<p>This content has been protected by an email verification</p>
<div class="protected-content-form">
{{ form(requestProtectedContentEmailForm) }}
</div>
{% endif %}
{% else %}
{% for field in content.fieldsByLanguage(language|default(null)) %}
<h3>{{ field.fieldDefIdentifier }}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* NovaeZProtectedContentBundle.
*
* @package Novactive\Bundle\eZProtectedContentBundle
*
* @author Novactive
* @copyright 2023 Novactive
* @license https://github.com/Novactive/eZProtectedContentBundle/blob/master/LICENSE MIT Licence
*/

declare(strict_types=1);

namespace Novactive\Bundle\eZProtectedContentBundle\Command;

use Novactive\Bundle\eZProtectedContentBundle\Repository\ProtectedTokenStorageRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class CleanTokenCommand extends Command
{
public function __construct(
protected ProtectedTokenStorageRepository $protectedTokenStorageRepository,
) {
parent::__construct();
}

protected function configure(): void
{
$this
->setName('novaezprotectedcontent:cleantoken')
->setDescription('Remove expired token in the DB');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$entities = $this->protectedTokenStorageRepository->findExpired();

$io->comment(sprintf('%d entities to delete', count($entities)));

foreach ($entities as $entity) {
$this->protectedTokenStorageRepository->remove($entity);
}

$this->protectedTokenStorageRepository->flush();

$io->success(sprintf('%d entities deleted', count($entities)));
$io->success('Done.');

return Command::SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(
return new RedirectResponse(
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
'locationId' => $location->id,
]).
]).
'#ibexa-tab-location-view-protect-content#tab'
);
}
Expand All @@ -86,7 +86,7 @@ public function remove(
return new RedirectResponse(
$router->generate('ibexa.content.view', ['contentId' => $location->contentId,
'locationId' => $location->id,
]).
]).
'#ibexa-tab-location-view-protect-content#tab'
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,33 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class NovaeZProtectedContentExtension extends Extension
class NovaeZProtectedContentExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container)
{
$config = [
'orm' => [
'entity_mappings' => [
'eZProtectedContentBundle' => [
'type' => 'annotation',
'dir' => __DIR__.'/../Entity',
'prefix' => 'Novactive\Bundle\eZProtectedContentBundle\Entity',
'is_bundle' => false,
],
],
],
];

$container->prependExtensionConfig('ibexa', $config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/**
* @ORM\Entity()
* @ORM\Table(name="novaezprotectedcontent")
* @ORM\EntityListeners({"Novactive\Bundle\eZProtectedContentBundle\Listener\EntityContentLink"})
*/
class ProtectedAccess implements ContentInterface
{
Expand All @@ -40,8 +39,7 @@ class ProtectedAccess implements ContentInterface
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=false)
* @Assert\NotBlank()
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(max=255)
*/
protected $password;
Expand All @@ -53,13 +51,27 @@ class ProtectedAccess implements ContentInterface
*/
protected $enabled;

/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $asEmail = false;

/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $protectChildren;

/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
protected $emailMessage;

public function __construct()
{
$this->enabled = true;
Expand All @@ -78,12 +90,24 @@ public function setId(int $id): self
return $this;
}

public function getAsEmail(): bool
{
return $this->asEmail ?? false;
}

public function setAsEmail(bool $asEmail): self
{
$this->asEmail = $asEmail;

return $this;
}

public function getPassword(): string
{
return $this->password ?? '';
}

public function setPassword(string $password): self
public function setPassword(?string $password): self
{
$this->password = $password;

Expand Down Expand Up @@ -111,4 +135,14 @@ public function setProtectChildren(bool $protectChildren): void
{
$this->protectChildren = $protectChildren;
}

public function getEmailMessage(): ?string
{
return $this->emailMessage;
}

public function setEmailMessage(string $emailMessage): void
{
$this->emailMessage = $emailMessage;
}
}
Loading