Moved gravatar and update checking settings to the settings-bundle system

This commit is contained in:
Jan Böhmer 2024-07-16 21:58:41 +02:00
parent 2bc50b2888
commit 2ef46cdd34
9 changed files with 90 additions and 25 deletions

View file

@ -63,7 +63,7 @@ class ToolsController extends AbstractController
'enabled_locales' => $this->getParameter('partdb.locale_menu'),
'demo_mode' => $this->getParameter('partdb.demo_mode'),
'gpdr_compliance' => $this->getParameter('partdb.gdpr_compliance'),
'use_gravatar' => $this->getParameter('partdb.users.use_gravatar'),
'use_gravatar' => $settings->system->privacy->useGravatar,
'email_password_reset' => $this->getParameter('partdb.users.email_pw_reset'),
'enviroment' => $this->getParameter('kernel.environment'),
'is_debug' => $this->getParameter('kernel.debug'),

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Services\System;
use App\Settings\SystemSettings\PrivacySettings;
use Psr\Log\LoggerInterface;
use Shivas\VersioningBundle\Service\VersionManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
@ -43,7 +44,7 @@ class UpdateAvailableManager
public function __construct(private readonly HttpClientInterface $httpClient,
private readonly CacheInterface $updateCache, private readonly VersionManagerInterface $versionManager,
private readonly bool $check_for_updates, private readonly LoggerInterface $logger,
private readonly PrivacySettings $privacySettings, private readonly LoggerInterface $logger,
#[Autowire(param: 'kernel.debug')] private readonly bool $is_dev_mode)
{
@ -83,7 +84,7 @@ class UpdateAvailableManager
public function isUpdateAvailable(): bool
{
//If we don't want to check for updates, we can return false
if (!$this->check_for_updates) {
if (!$this->privacySettings->checkForUpdates) {
return false;
}
@ -101,7 +102,7 @@ class UpdateAvailableManager
private function getLatestVersionInfo(): array
{
//If we don't want to check for updates, we can return dummy data
if (!$this->check_for_updates) {
if (!$this->privacySettings->checkForUpdates) {
return [
'version' => '0.0.1',
'url' => 'update-checking-disabled'

View file

@ -30,6 +30,7 @@ use App\Entity\Attachments\UserAttachment;
use App\Entity\UserSystem\User;
use App\Services\Attachments\AttachmentSubmitHandler;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Settings\SystemSettings\PrivacySettings;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -42,7 +43,7 @@ class UserAvatarHelper
public const IMG_DEFAULT_AVATAR_PATH = 'img/default_avatar.svg';
public function __construct(
private readonly bool $use_gravatar,
private readonly PrivacySettings $privacySettings,
private readonly Packages $packages,
private readonly AttachmentURLGenerator $attachmentURLGenerator,
private readonly EntityManagerInterface $entityManager,
@ -65,7 +66,7 @@ class UserAvatarHelper
}
//If not check if gravatar is enabled (then use gravatar URL)
if ($this->use_gravatar) {
if ($this->privacySettings->useGravatar) {
return $this->getGravatar($user, 200); //200px wide picture
}
@ -82,7 +83,7 @@ class UserAvatarHelper
}
//If not check if gravatar is enabled (then use gravatar URL)
if ($this->use_gravatar) {
if ($this->privacySettings->useGravatar) {
return $this->getGravatar($user, 50); //50px wide picture
}
@ -99,7 +100,7 @@ class UserAvatarHelper
}
//If not check if gravatar is enabled (then use gravatar URL)
if ($this->use_gravatar) {
if ($this->privacySettings->useGravatar) {
return $this->getGravatar($user, 150);
}

View file

@ -26,6 +26,7 @@ namespace App\Settings;
use App\Settings\SystemSettings\AttachmentsSettings;
use App\Settings\SystemSettings\CustomizationSettings;
use App\Settings\SystemSettings\HistorySettings;
use App\Settings\SystemSettings\PrivacySettings;
use Jbtronics\SettingsBundle\Settings\EmbeddedSettings;
use Jbtronics\SettingsBundle\Settings\Settings;
@ -35,6 +36,9 @@ class SystemSettings
#[EmbeddedSettings()]
public ?CustomizationSettings $customization = null;
#[EmbeddedSettings()]
public ?PrivacySettings $privacy = null;
#[EmbeddedSettings()]
public ?AttachmentsSettings $attachments = null;

View file

@ -0,0 +1,52 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\SystemSettings;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings]
class PrivacySettings
{
use SettingsTrait;
#[SettingsParameter(
label: new TM("settings.system.privacy.checkForUpdates"),
description: new TM("settings.system.privacy.checkForUpdates.description"),
envVar: 'bool:CHECK_FOR_UPDATES', envVarMode: EnvVarMode::OVERWRITE)]
public bool $checkForUpdates = true;
/**
* @var bool Use gravatars for user avatars, when user has no own avatar defined
*/
#[SettingsParameter(
label: new TM("settings.system.privacy.useGravatar"),
description: new TM("settings.system.privacy.useGravatar.description"),
envVar: 'bool:USE_GRAVATAR', envVarMode: EnvVarMode::OVERWRITE)]
public bool $useGravatar = false;
}