feat(altcha): remove feature flag for security
Some checks reported warnings
Cadoles/hydra-sql/pipeline/head This commit is unstable
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable

This commit is contained in:
2025-04-14 16:33:12 +02:00
parent 303b0279f8
commit 79337efef0
6 changed files with 2 additions and 93 deletions

View File

@ -1,37 +0,0 @@
<?php
namespace App\Flag\Controller;
use App\Flag\FlagAccessor;
use App\Flag\FlagEnum;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Exception\JsonException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class FlagController extends AbstractController
{
#[Route('/flag/{flagName}', name: 'flag_update', methods: ['PUT'])]
public function updateFlag(CacheItemPoolInterface $cache, Request $request, string $flagName): Response
{
try {
FlagEnum::from($flagName);
$flagValue = \json_decode($request->getContent(), true, flags: JSON_THROW_ON_ERROR)[FlagAccessor::FLAG_VALUE];
} catch (\ValueError $e) {
throw new \InvalidArgumentException('invalid flag name provided');
} catch (JsonException $e) {
throw new \InvalidArgumentException('invalid json format');
}
$flag = $cache->getItem($flagName);
$flag->set($flagValue);
$cache->save($flag);
return new JsonResponse(
[\sprintf('flag %s has been %s.', $flagName, $flagValue ? 'enabled' : 'disabled')]
);
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace App\Flag;
use Psr\Cache\CacheItemPoolInterface;
class FlagAccessor
{
public const FLAG_VALUE = 'flagValue';
public function __construct(
private readonly CacheItemPoolInterface $cache
) {
}
public function isFlagEnabled(FlagEnum $flagName, bool $fallbackValue = false): bool
{
$flagValue = $this->cache->getItem($flagName->value)->get();
if (null === $flagValue) {
return $fallbackValue;
}
return (bool) $flagValue;
}
}

View File

@ -1,8 +0,0 @@
<?php
namespace App\Flag;
enum FlagEnum: string
{
case Altcha = 'altcha';
}

View File

@ -3,8 +3,6 @@
namespace App\Form;
use App\Altcha\Form\AltchaType;
use App\Flag\FlagAccessor;
use App\Flag\FlagEnum;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -14,7 +12,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class LoginType extends AbstractType
{
public function __construct(
private readonly FlagAccessor $flagAccessor,
private readonly bool $altchaEnabled
) {
}
@ -32,7 +29,7 @@ class LoginType extends AbstractType
])
;
if ($this->flagAccessor->isFlagEnabled(FlagEnum::Altcha, $this->altchaEnabled)) {
if ($this->altchaEnabled) {
$builder->add('altcha', AltchaType::class, [
'translation_domain' => 'form',
'label' => 'altcha.widget.title',