Skip to content

Commit

Permalink
feat: Made Gravatar optional with roadiz_core.useGravatar config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed May 14, 2024
1 parent 5829df7 commit 6e8c396
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions config/packages/roadiz_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ roadiz_core:
staticDomainName: ~
documentsLibDir: 'lib/Documents/src'
useNativeJsonColumnType: true
useGravatar: false
medias:
unsplash_client_id: '%env(string:APP_UNSPLASH_CLIENT_ID)%'
soundcloud_client_id: '%env(string:APP_SOUNDCLOUD_CLIENT_ID)%'
Expand Down
1 change: 1 addition & 0 deletions lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ services:
$recaptchaPublicKey: '%roadiz_core.medias.recaptcha_public_key%'
$recaptchaPrivateKey: '%roadiz_core.medias.recaptcha_private_key%'
$webResponseClass: '%roadiz_core.web_response_class%'
$useGravatar: '%roadiz_core.use_gravatar%'

RZ\Roadiz\CoreBundle\:
resource: '../src/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('hideRoadizVersion')
->defaultValue(false)
->end()
->booleanNode('useGravatar')
->defaultTrue()
->end()
->scalarNode('documentsLibDir')->defaultValue(
'vendor/roadiz/documents/src'
)->info('Relative path to Roadiz Documents lib sources from project directory.')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setParameter('roadiz_core.app_namespace', $config['appNamespace']);
$container->setParameter('roadiz_core.app_version', $config['appVersion']);
$container->setParameter('roadiz_core.use_gravatar', $config['useGravatar']);
$container->setParameter('roadiz_core.health_check_token', $config['healthCheckToken']);
$container->setParameter('roadiz_core.inheritance_type', $config['inheritance']['type']);
$container->setParameter('roadiz_core.max_versions_showed', $config['maxVersionsShowed']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,13 @@

final class UserLifeCycleSubscriber implements EventSubscriber
{
private UserViewer $userViewer;
private EventDispatcherInterface $dispatcher;
private PasswordHasherFactoryInterface $passwordHasherFactory;
private LoggerInterface $logger;

/**
* @param UserViewer $userViewer
* @param EventDispatcherInterface $dispatcher
* @param PasswordHasherFactoryInterface $passwordHasherFactory
* @param LoggerInterface $logger
*/
public function __construct(
UserViewer $userViewer,
EventDispatcherInterface $dispatcher,
PasswordHasherFactoryInterface $passwordHasherFactory,
LoggerInterface $logger
private readonly UserViewer $userViewer,
private readonly EventDispatcherInterface $dispatcher,
private readonly PasswordHasherFactoryInterface $passwordHasherFactory,
private readonly LoggerInterface $logger,
private readonly bool $useGravatar
) {
$this->userViewer = $userViewer;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
$this->passwordHasherFactory = $passwordHasherFactory;
}

/**
Expand Down Expand Up @@ -94,9 +80,11 @@ public function preUpdate(PreUpdateEventArgs $event): void
$user->setPictureUrl($url);
} catch (\Exception $e) {
$user->setFacebookName('');
$user->setPictureUrl($user->getGravatarUrl());
if ($this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
} else {
} elseif ($this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
Expand Down Expand Up @@ -201,7 +189,7 @@ public function prePersist(LifecycleEventArgs $event): void
/*
* Force a Gravatar image if not defined
*/
if (empty($user->getPictureUrl())) {
if (empty($user->getPictureUrl()) && $this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/RoadizRozierBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
$soundcloudClientId: '%roadiz_core.medias.soundcloud_client_id%'
$allowNodeTypeEdition: '%kernel.debug%'
$forceSslOnRedirectUri: '%roadiz_rozier.open_id.force_ssl_on_redirect_uri%'
$useGravatar: '%roadiz_core.use_gravatar%'

RZ\Roadiz\RozierBundle\:
resource: '../src/'
Expand Down
15 changes: 14 additions & 1 deletion lib/Rozier/src/Controllers/Users/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@

namespace Themes\Rozier\Controllers\Users;

use JMS\Serializer\SerializerInterface;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Entity\Role;
use RZ\Roadiz\CoreBundle\Entity\User;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Controllers\AbstractAdminWithBulkController;
use Themes\Rozier\Forms\UserDetailsType;
use Themes\Rozier\Forms\UserType;
use Twig\Error\RuntimeError;

class UsersController extends AbstractAdminWithBulkController
{
public function __construct(
FormFactoryInterface $formFactory,
SerializerInterface $serializer,
UrlGeneratorInterface $urlGenerator,
private readonly bool $useGravatar
) {
parent::__construct($formFactory, $serializer, $urlGenerator);
}


protected function supports(PersistableInterface $item): bool
{
return $item instanceof User;
Expand Down Expand Up @@ -123,7 +136,7 @@ protected function createUpdateEvent(PersistableInterface $item)
/*
* If pictureUrl is empty, use default Gravatar image.
*/
if ($item->getPictureUrl() == '') {
if ($item->getPictureUrl() == '' && $this->useGravatar) {
$item->setPictureUrl($item->getGravatarUrl());
}

Expand Down

0 comments on commit 6e8c396

Please sign in to comment.