mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -72,29 +72,16 @@ abstract class BaseAdminController extends AbstractController
|
|||
protected string $route_base = '';
|
||||
protected string $attachment_class = '';
|
||||
protected ?string $parameter_class = '';
|
||||
|
||||
protected UserPasswordHasherInterface $passwordEncoder;
|
||||
protected TranslatorInterface $translator;
|
||||
protected AttachmentSubmitHandler $attachmentSubmitHandler;
|
||||
protected EventCommentHelper $commentHelper;
|
||||
|
||||
protected HistoryHelper $historyHelper;
|
||||
protected TimeTravel $timeTravel;
|
||||
protected DataTableFactory $dataTableFactory;
|
||||
/**
|
||||
* @var EventDispatcher|EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
protected LabelGenerator $labelGenerator;
|
||||
protected LabelExampleElementsGenerator $barcodeExampleGenerator;
|
||||
|
||||
protected EntityManagerInterface $entityManager;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, UserPasswordHasherInterface $passwordEncoder,
|
||||
AttachmentSubmitHandler $attachmentSubmitHandler,
|
||||
EventCommentHelper $commentHelper, HistoryHelper $historyHelper, TimeTravel $timeTravel,
|
||||
DataTableFactory $dataTableFactory, EventDispatcherInterface $eventDispatcher, LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||
LabelGenerator $labelGenerator, EntityManagerInterface $entityManager)
|
||||
public function __construct(protected TranslatorInterface $translator, protected UserPasswordHasherInterface $passwordEncoder,
|
||||
protected AttachmentSubmitHandler $attachmentSubmitHandler,
|
||||
protected EventCommentHelper $commentHelper, protected HistoryHelper $historyHelper, protected TimeTravel $timeTravel,
|
||||
protected DataTableFactory $dataTableFactory, EventDispatcherInterface $eventDispatcher, protected LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||
protected LabelGenerator $labelGenerator, protected EntityManagerInterface $entityManager)
|
||||
{
|
||||
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
||||
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
||||
|
@ -107,18 +94,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
if ('' === $this->parameter_class || ($this->parameter_class && !is_a($this->parameter_class, AbstractParameter::class, true))) {
|
||||
throw new InvalidArgumentException('You have to override the $parameter_class value with a valid Parameter class in your subclass!');
|
||||
}
|
||||
|
||||
$this->translator = $translator;
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
$this->attachmentSubmitHandler = $attachmentSubmitHandler;
|
||||
$this->commentHelper = $commentHelper;
|
||||
$this->historyHelper = $historyHelper;
|
||||
$this->timeTravel = $timeTravel;
|
||||
$this->dataTableFactory = $dataTableFactory;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->barcodeExampleGenerator = $barcodeExampleGenerator;
|
||||
$this->labelGenerator = $labelGenerator;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?DateTime
|
||||
|
@ -177,7 +153,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
$form_options = [
|
||||
'attachment_class' => $this->attachment_class,
|
||||
'parameter_class' => $this->parameter_class,
|
||||
'disabled' => null !== $timeTravel_timestamp,
|
||||
'disabled' => $timeTravel_timestamp instanceof \DateTime,
|
||||
];
|
||||
|
||||
//Disable editing of options, if user is not allowed to use twig...
|
||||
|
@ -269,13 +245,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
protected function _new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?AbstractNamedDBElement $entity = null)
|
||||
{
|
||||
if (null === $entity) {
|
||||
/** @var AbstractStructuralDBElement|User $new_entity */
|
||||
$new_entity = new $this->entity_class();
|
||||
} else {
|
||||
/** @var AbstractStructuralDBElement|User $new_entity */
|
||||
$new_entity = clone $entity;
|
||||
}
|
||||
$new_entity = $entity instanceof \App\Entity\Base\AbstractNamedDBElement ? clone $entity : new $this->entity_class();
|
||||
|
||||
$this->denyAccessUnlessGranted('read', $new_entity);
|
||||
|
||||
|
@ -287,42 +257,37 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
//Perform additional actions
|
||||
if ($this->additionalActionNew($form, $new_entity)) {
|
||||
//Upload passed files
|
||||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var FormInterface $attachment */
|
||||
$options = [
|
||||
'secure_attachment' => $attachment['secureFile']->getData(),
|
||||
'download_url' => $attachment['downloadURL']->getData(),
|
||||
];
|
||||
//Perform additional actions
|
||||
if ($form->isSubmitted() && $form->isValid() && $this->additionalActionNew($form, $new_entity)) {
|
||||
//Upload passed files
|
||||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var FormInterface $attachment */
|
||||
$options = [
|
||||
'secure_attachment' => $attachment['secureFile']->getData(),
|
||||
'download_url' => $attachment['downloadURL']->getData(),
|
||||
];
|
||||
|
||||
try {
|
||||
$this->attachmentSubmitHandler->handleFormSubmit(
|
||||
$attachment->getData(),
|
||||
$attachment['file']->getData(),
|
||||
$options
|
||||
);
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator->trans(
|
||||
'attachment.download_failed'
|
||||
).' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
try {
|
||||
$this->attachmentSubmitHandler->handleFormSubmit(
|
||||
$attachment->getData(),
|
||||
$attachment['file']->getData(),
|
||||
$options
|
||||
);
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator->trans(
|
||||
'attachment.download_failed'
|
||||
).' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
|
||||
$em->persist($new_entity);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'entity.created_flash');
|
||||
|
||||
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]);
|
||||
}
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
$em->persist($new_entity);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'entity.created_flash');
|
||||
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && !$form->isValid()) {
|
||||
|
@ -369,7 +334,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (UnexpectedValueException $e) {
|
||||
catch (UnexpectedValueException) {
|
||||
$this->addFlash('error', 'parts.import.flash.error.invalid_file');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,8 +64,6 @@ class CurrencyController extends BaseAdminController
|
|||
protected string $attachment_class = CurrencyAttachment::class;
|
||||
protected ?string $parameter_class = CurrencyParameter::class;
|
||||
|
||||
protected ExchangeRateUpdater $exchangeRateUpdater;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
UserPasswordHasherInterface $passwordEncoder,
|
||||
|
@ -78,10 +76,8 @@ class CurrencyController extends BaseAdminController
|
|||
LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||
LabelGenerator $labelGenerator,
|
||||
EntityManagerInterface $entityManager,
|
||||
ExchangeRateUpdater $exchangeRateUpdater
|
||||
protected ExchangeRateUpdater $exchangeRateUpdater
|
||||
) {
|
||||
$this->exchangeRateUpdater = $exchangeRateUpdater;
|
||||
|
||||
parent::__construct(
|
||||
$translator,
|
||||
$passwordEncoder,
|
||||
|
|
|
@ -45,9 +45,6 @@ class ManufacturerController extends BaseAdminController
|
|||
protected string $attachment_class = ManufacturerAttachment::class;
|
||||
protected ?string $parameter_class = ManufacturerParameter::class;
|
||||
|
||||
/**
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
#[Route(path: '/{id}', name: 'manufacturer_delete', methods: ['DELETE'])]
|
||||
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
|
||||
{
|
||||
|
|
|
@ -37,15 +37,8 @@ use Symfony\Contracts\Cache\CacheInterface;
|
|||
|
||||
class HomepageController extends AbstractController
|
||||
{
|
||||
protected CacheInterface $cache;
|
||||
protected KernelInterface $kernel;
|
||||
protected DataTableFactory $dataTable;
|
||||
|
||||
public function __construct(CacheInterface $cache, KernelInterface $kernel, DataTableFactory $dataTable)
|
||||
public function __construct(protected CacheInterface $cache, protected KernelInterface $kernel, protected DataTableFactory $dataTable)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->kernel = $kernel;
|
||||
$this->dataTable = $dataTable;
|
||||
}
|
||||
|
||||
public function getBanner(): string
|
||||
|
|
|
@ -62,20 +62,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
#[Route(path: '/label')]
|
||||
class LabelController extends AbstractController
|
||||
{
|
||||
protected LabelGenerator $labelGenerator;
|
||||
protected EntityManagerInterface $em;
|
||||
protected ElementTypeNameGenerator $elementTypeNameGenerator;
|
||||
protected RangeParser $rangeParser;
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(LabelGenerator $labelGenerator, EntityManagerInterface $em, ElementTypeNameGenerator $elementTypeNameGenerator,
|
||||
RangeParser $rangeParser, TranslatorInterface $translator)
|
||||
public function __construct(protected LabelGenerator $labelGenerator, protected EntityManagerInterface $em, protected ElementTypeNameGenerator $elementTypeNameGenerator, protected RangeParser $rangeParser, protected TranslatorInterface $translator)
|
||||
{
|
||||
$this->labelGenerator = $labelGenerator;
|
||||
$this->em = $em;
|
||||
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
|
||||
$this->rangeParser = $rangeParser;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
#[Route(path: '/dialog', name: 'label_dialog')]
|
||||
|
@ -85,15 +73,11 @@ class LabelController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('@labels.create_labels');
|
||||
|
||||
//If we inherit a LabelProfile, the user need to have access to it...
|
||||
if (null !== $profile) {
|
||||
if ($profile instanceof \App\Entity\LabelSystem\LabelProfile) {
|
||||
$this->denyAccessUnlessGranted('read', $profile);
|
||||
}
|
||||
|
||||
if ($profile) {
|
||||
$label_options = $profile->getOptions();
|
||||
} else {
|
||||
$label_options = new LabelOptions();
|
||||
}
|
||||
$label_options = $profile instanceof \App\Entity\LabelSystem\LabelProfile ? $profile->getOptions() : new LabelOptions();
|
||||
|
||||
//We have to disable the options, if twig mode is selected and user is not allowed to use it.
|
||||
$disable_options = 'twig' === $label_options->getLinesMode() && !$this->isGranted('@labels.use_twig');
|
||||
|
@ -107,7 +91,7 @@ class LabelController extends AbstractController
|
|||
$target_id = $request->query->get('target_id', null);
|
||||
$generate = $request->query->getBoolean('generate', false);
|
||||
|
||||
if (null === $profile && is_string($target_type)) {
|
||||
if (!$profile instanceof \App\Entity\LabelSystem\LabelProfile && is_string($target_type)) {
|
||||
$label_options->setSupportedElement($target_type);
|
||||
}
|
||||
if (is_string($target_id)) {
|
||||
|
@ -124,10 +108,10 @@ class LabelController extends AbstractController
|
|||
$filename = 'invalid.pdf';
|
||||
|
||||
//Generate PDF either when the form is submitted and valid, or the form was not submit yet, and generate is set
|
||||
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && null !== $profile)) {
|
||||
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile instanceof \App\Entity\LabelSystem\LabelProfile)) {
|
||||
$target_id = (string) $form->get('target_id')->getData();
|
||||
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
|
||||
if (!empty($targets)) {
|
||||
if ($targets !== []) {
|
||||
try {
|
||||
$pdf_data = $this->labelGenerator->generateLabel($form_options, $targets);
|
||||
$filename = $this->getLabelName($targets[0], $profile);
|
||||
|
|
|
@ -52,20 +52,13 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
#[Route(path: '/log')]
|
||||
class LogController extends AbstractController
|
||||
{
|
||||
protected EntityManagerInterface $entityManager;
|
||||
protected TimeTravel $timeTravel;
|
||||
protected DBElementRepository $dbRepository;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, TimeTravel $timeTravel)
|
||||
public function __construct(protected EntityManagerInterface $entityManager, protected TimeTravel $timeTravel)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->timeTravel = $timeTravel;
|
||||
$this->dbRepository = $entityManager->getRepository(AbstractDBElement::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/', name: 'log_view')]
|
||||
public function showLogs(Request $request, DataTableFactory $dataTable): Response
|
||||
{
|
||||
|
@ -96,8 +89,6 @@ class LogController extends AbstractController
|
|||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param AbstractLogEntry $logEntry
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/{id}/details', name: 'log_details')]
|
||||
public function logDetails(AbstractLogEntry $logEntry, LogEntryExtraFormatter $logEntryExtraFormatter,
|
||||
|
@ -150,7 +141,7 @@ class LogController extends AbstractController
|
|||
}
|
||||
|
||||
$log_element = $this->entityManager->find(AbstractLogEntry::class, $id);
|
||||
if (null === $log_element) {
|
||||
if (!$log_element instanceof \App\Entity\LogSystem\AbstractLogEntry) {
|
||||
throw new InvalidArgumentException('No log entry with the given ID is existing!');
|
||||
}
|
||||
|
||||
|
|
|
@ -62,16 +62,8 @@ use function Symfony\Component\Translation\t;
|
|||
#[Route(path: '/part')]
|
||||
class PartController extends AbstractController
|
||||
{
|
||||
protected PricedetailHelper $pricedetailHelper;
|
||||
protected PartPreviewGenerator $partPreviewGenerator;
|
||||
protected EventCommentHelper $commentHelper;
|
||||
|
||||
public function __construct(PricedetailHelper $pricedetailHelper,
|
||||
PartPreviewGenerator $partPreviewGenerator, EventCommentHelper $commentHelper)
|
||||
public function __construct(protected PricedetailHelper $pricedetailHelper, protected PartPreviewGenerator $partPreviewGenerator, protected EventCommentHelper $commentHelper)
|
||||
{
|
||||
$this->pricedetailHelper = $pricedetailHelper;
|
||||
$this->partPreviewGenerator = $partPreviewGenerator;
|
||||
$this->commentHelper = $commentHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,11 +210,13 @@ class PartController extends AbstractController
|
|||
?Part $part = null, ?Project $project = null): Response
|
||||
{
|
||||
|
||||
if ($part) { //Clone part
|
||||
if ($part instanceof \App\Entity\Parts\Part) {
|
||||
//Clone part
|
||||
$new_part = clone $part;
|
||||
} else if ($project) { //Initialize a new part for a build part from the given project
|
||||
} elseif ($project instanceof \App\Entity\ProjectSystem\Project) {
|
||||
//Initialize a new part for a build part from the given project
|
||||
//Ensure that the project has not already a build part
|
||||
if ($project->getBuildPart() !== null) {
|
||||
if ($project->getBuildPart() instanceof \App\Entity\Parts\Part) {
|
||||
$this->addFlash('error', 'part.new_build_part.error.build_part_already_exists');
|
||||
return $this->redirectToRoute('part_edit', ['id' => $project->getBuildPart()->getID()]);
|
||||
}
|
||||
|
@ -235,7 +229,7 @@ class PartController extends AbstractController
|
|||
|
||||
$cid = $request->get('category', null);
|
||||
$category = $cid ? $em->find(Category::class, $cid) : null;
|
||||
if (null !== $category && null === $new_part->getCategory()) {
|
||||
if ($category instanceof \App\Entity\Parts\Category && !$new_part->getCategory() instanceof \App\Entity\Parts\Category) {
|
||||
$new_part->setCategory($category);
|
||||
$new_part->setDescription($category->getDefaultDescription());
|
||||
$new_part->setComment($category->getDefaultComment());
|
||||
|
@ -243,19 +237,19 @@ class PartController extends AbstractController
|
|||
|
||||
$fid = $request->get('footprint', null);
|
||||
$footprint = $fid ? $em->find(Footprint::class, $fid) : null;
|
||||
if (null !== $footprint && null === $new_part->getFootprint()) {
|
||||
if ($footprint instanceof \App\Entity\Parts\Footprint && !$new_part->getFootprint() instanceof \App\Entity\Parts\Footprint) {
|
||||
$new_part->setFootprint($footprint);
|
||||
}
|
||||
|
||||
$mid = $request->get('manufacturer', null);
|
||||
$manufacturer = $mid ? $em->find(Manufacturer::class, $mid) : null;
|
||||
if (null !== $manufacturer && null === $new_part->getManufacturer()) {
|
||||
if ($manufacturer instanceof \App\Entity\Parts\Manufacturer && !$new_part->getManufacturer() instanceof \App\Entity\Parts\Manufacturer) {
|
||||
$new_part->setManufacturer($manufacturer);
|
||||
}
|
||||
|
||||
$store_id = $request->get('storelocation', null);
|
||||
$storelocation = $store_id ? $em->find(Storelocation::class, $store_id) : null;
|
||||
if (null !== $storelocation && $new_part->getPartLots()->isEmpty()) {
|
||||
if ($storelocation instanceof \App\Entity\Parts\Storelocation && $new_part->getPartLots()->isEmpty()) {
|
||||
$partLot = new PartLot();
|
||||
$partLot->setStorageLocation($storelocation);
|
||||
$partLot->setInstockUnknown(true);
|
||||
|
@ -264,7 +258,7 @@ class PartController extends AbstractController
|
|||
|
||||
$supplier_id = $request->get('supplier', null);
|
||||
$supplier = $supplier_id ? $em->find(Supplier::class, $supplier_id) : null;
|
||||
if (null !== $supplier && $new_part->getOrderdetails()->isEmpty()) {
|
||||
if ($supplier instanceof \App\Entity\Parts\Supplier && $new_part->getOrderdetails()->isEmpty()) {
|
||||
$orderdetail = new Orderdetail();
|
||||
$orderdetail->setSupplier($supplier);
|
||||
$new_part->addOrderdetail($orderdetail);
|
||||
|
@ -335,7 +329,7 @@ class PartController extends AbstractController
|
|||
if ($this->isCsrfTokenValid('part_withraw' . $part->getID(), $request->request->get('_csfr'))) {
|
||||
//Retrieve partlot from the request
|
||||
$partLot = $em->find(PartLot::class, $request->request->get('lot_id'));
|
||||
if($partLot === null) {
|
||||
if(!$partLot instanceof \App\Entity\Parts\PartLot) {
|
||||
throw new \RuntimeException('Part lot not found!');
|
||||
}
|
||||
//Ensure that the partlot belongs to the part
|
||||
|
@ -375,7 +369,7 @@ class PartController extends AbstractController
|
|||
default:
|
||||
throw new \RuntimeException("Unknown action!");
|
||||
}
|
||||
} catch (AccessDeniedException $exception) {
|
||||
} catch (AccessDeniedException) {
|
||||
$this->addFlash('error', t('part.withdraw.access_denied'));
|
||||
goto err;
|
||||
}
|
||||
|
|
|
@ -36,22 +36,10 @@ use UnexpectedValueException;
|
|||
|
||||
class PartImportExportController extends AbstractController
|
||||
{
|
||||
private PartsTableActionHandler $partsTableActionHandler;
|
||||
private EntityImporter $entityImporter;
|
||||
private EventCommentHelper $commentHelper;
|
||||
|
||||
public function __construct(PartsTableActionHandler $partsTableActionHandler,
|
||||
EntityImporter $entityImporter, EventCommentHelper $commentHelper)
|
||||
public function __construct(private readonly PartsTableActionHandler $partsTableActionHandler, private readonly EntityImporter $entityImporter, private readonly EventCommentHelper $commentHelper)
|
||||
{
|
||||
$this->partsTableActionHandler = $partsTableActionHandler;
|
||||
$this->entityImporter = $entityImporter;
|
||||
$this->commentHelper = $commentHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/parts/import', name: 'parts_import')]
|
||||
public function importParts(Request $request): Response
|
||||
{
|
||||
|
@ -116,16 +104,13 @@ class PartImportExportController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/parts/export', name: 'parts_export', methods: ['GET'])]
|
||||
public function exportParts(Request $request, EntityExporter $entityExporter): Response
|
||||
{
|
||||
$ids = $request->query->get('ids', '');
|
||||
$parts = $this->partsTableActionHandler->idStringToArray($ids);
|
||||
|
||||
if (empty($parts)) {
|
||||
if ($parts === []) {
|
||||
throw new \RuntimeException('No parts found!');
|
||||
}
|
||||
|
||||
|
|
|
@ -48,18 +48,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class PartListsController extends AbstractController
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
private NodesListBuilder $nodesListBuilder;
|
||||
private DataTableFactory $dataTableFactory;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, NodesListBuilder $nodesListBuilder, DataTableFactory $dataTableFactory, TranslatorInterface $translator)
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly NodesListBuilder $nodesListBuilder, private readonly DataTableFactory $dataTableFactory, private readonly TranslatorInterface $translator)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->nodesListBuilder = $nodesListBuilder;
|
||||
$this->dataTableFactory = $dataTableFactory;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
#[Route(path: '/table/action', name: 'table_action', methods: ['POST'])]
|
||||
|
@ -100,8 +90,6 @@ class PartListsController extends AbstractController
|
|||
|
||||
/**
|
||||
* Disable the given form interface after creation of the form by removing and reattaching the form.
|
||||
* @param FormInterface $form
|
||||
* @return void
|
||||
*/
|
||||
private function disableFormFieldAfterCreation(FormInterface $form, bool $disabled = true): void
|
||||
{
|
||||
|
@ -109,12 +97,12 @@ class PartListsController extends AbstractController
|
|||
$attrs['disabled'] = $disabled;
|
||||
|
||||
$parent = $form->getParent();
|
||||
if ($parent === null) {
|
||||
if (!$parent instanceof \Symfony\Component\Form\FormInterface) {
|
||||
throw new \RuntimeException('This function can only be used on form fields that are children of another form!');
|
||||
}
|
||||
|
||||
$parent->remove($form->getName());
|
||||
$parent->add($form->getName(), get_class($form->getConfig()->getType()->getInnerType()), $attrs);
|
||||
$parent->add($form->getName(), $form->getConfig()->getType()->getInnerType()::class, $attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +113,6 @@ class PartListsController extends AbstractController
|
|||
* @param callable|null $form_changer A function that is called with the form object as parameter. This function can be used to customize the form
|
||||
* @param array $additonal_template_vars Any additional template variables that should be passed to the template
|
||||
* @param array $additional_table_vars Any additional variables that should be passed to the table creation
|
||||
* @return Response
|
||||
*/
|
||||
protected function showListWithFilter(Request $request, string $template, ?callable $filter_changer = null, ?callable $form_changer = null, array $additonal_template_vars = [], array $additional_table_vars = []): Response
|
||||
{
|
||||
|
@ -172,9 +159,6 @@ class PartListsController extends AbstractController
|
|||
], $additonal_template_vars));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/category/{id}/parts', name: 'part_list_category')]
|
||||
public function showCategory(Category $category, Request $request): Response
|
||||
{
|
||||
|
@ -193,9 +177,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/footprint/{id}/parts', name: 'part_list_footprint')]
|
||||
public function showFootprint(Footprint $footprint, Request $request): Response
|
||||
{
|
||||
|
@ -214,9 +195,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/manufacturer/{id}/parts', name: 'part_list_manufacturer')]
|
||||
public function showManufacturer(Manufacturer $manufacturer, Request $request): Response
|
||||
{
|
||||
|
@ -235,9 +213,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/store_location/{id}/parts', name: 'part_list_store_location')]
|
||||
public function showStorelocation(Storelocation $storelocation, Request $request): Response
|
||||
{
|
||||
|
@ -256,9 +231,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/supplier/{id}/parts', name: 'part_list_supplier')]
|
||||
public function showSupplier(Supplier $supplier, Request $request): Response
|
||||
{
|
||||
|
@ -277,9 +249,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/parts/by_tag/{tag}', name: 'part_list_tags', requirements: ['tag' => '.*'])]
|
||||
public function showTag(string $tag, Request $request): Response
|
||||
{
|
||||
|
@ -321,9 +290,6 @@ class PartListsController extends AbstractController
|
|||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
#[Route(path: '/parts/search', name: 'parts_search')]
|
||||
public function showSearch(Request $request, DataTableFactory $dataTable): Response
|
||||
{
|
||||
|
@ -343,9 +309,6 @@ class PartListsController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/parts', name: 'parts_show_all')]
|
||||
public function showAll(Request $request): Response
|
||||
{
|
||||
|
|
|
@ -50,11 +50,8 @@ use function Symfony\Component\Translation\t;
|
|||
#[Route(path: '/project')]
|
||||
class ProjectController extends AbstractController
|
||||
{
|
||||
private DataTableFactory $dataTableFactory;
|
||||
|
||||
public function __construct(DataTableFactory $dataTableFactory)
|
||||
public function __construct(private readonly DataTableFactory $dataTableFactory)
|
||||
{
|
||||
$this->dataTableFactory = $dataTableFactory;
|
||||
}
|
||||
|
||||
#[Route(path: '/{id}/info', name: 'project_info', requirements: ['id' => '\d+'])]
|
||||
|
@ -180,9 +177,7 @@ class ProjectController extends AbstractController
|
|||
if (count ($errors) > 0) {
|
||||
$this->addFlash('error', t('project.bom_import.flash.invalid_entries'));
|
||||
}
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$this->addFlash('error', t('project.bom_import.flash.invalid_file', ['%message%' => $e->getMessage()]));
|
||||
} catch (SyntaxError $e) {
|
||||
} catch (\UnexpectedValueException|SyntaxError $e) {
|
||||
$this->addFlash('error', t('project.bom_import.flash.invalid_file', ['%message%' => $e->getMessage()]));
|
||||
}
|
||||
}
|
||||
|
@ -194,15 +189,11 @@ class ProjectController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Project|null $project
|
||||
*/
|
||||
#[Route(path: '/add_parts', name: 'project_add_parts_no_id')]
|
||||
#[Route(path: '/{id}/add_parts', name: 'project_add_parts', requirements: ['id' => '\d+'])]
|
||||
public function addPart(Request $request, EntityManagerInterface $entityManager, ?Project $project): Response
|
||||
{
|
||||
if($project) {
|
||||
if($project instanceof \App\Entity\ProjectSystem\Project) {
|
||||
$this->denyAccessUnlessGranted('edit', $project);
|
||||
} else {
|
||||
$this->denyAccessUnlessGranted('@projects.edit');
|
||||
|
@ -212,7 +203,7 @@ class ProjectController extends AbstractController
|
|||
$builder->add('project', StructuralEntityType::class, [
|
||||
'class' => Project::class,
|
||||
'required' => true,
|
||||
'disabled' => $project !== null, //If a project is given, disable the field
|
||||
'disabled' => $project instanceof \App\Entity\ProjectSystem\Project, //If a project is given, disable the field
|
||||
'data' => $project,
|
||||
'constraints' => [
|
||||
new NotNull()
|
||||
|
@ -224,7 +215,7 @@ class ProjectController extends AbstractController
|
|||
|
||||
//Preset the BOM entries with the selected parts, when the form was not submitted yet
|
||||
$preset_data = new ArrayCollection();
|
||||
foreach (explode(',', $request->get('parts', '')) as $part_id) {
|
||||
foreach (explode(',', (string) $request->get('parts', '')) as $part_id) {
|
||||
$part = $entityManager->getRepository(Part::class)->find($part_id);
|
||||
if (null !== $part) {
|
||||
//If there is already a BOM entry for this part, we use this one (we edit it then)
|
||||
|
|
|
@ -32,15 +32,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class RedirectController extends AbstractController
|
||||
{
|
||||
protected string $default_locale;
|
||||
protected TranslatorInterface $translator;
|
||||
protected bool $enforce_index_php;
|
||||
|
||||
public function __construct(string $default_locale, TranslatorInterface $translator, bool $enforce_index_php)
|
||||
public function __construct(protected string $default_locale, protected TranslatorInterface $translator, protected bool $enforce_index_php)
|
||||
{
|
||||
$this->default_locale = $default_locale;
|
||||
$this->translator = $translator;
|
||||
$this->enforce_index_php = $enforce_index_php;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,13 +54,8 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
#[Route(path: '/scan')]
|
||||
class ScanController extends AbstractController
|
||||
{
|
||||
protected BarcodeRedirector $barcodeParser;
|
||||
protected BarcodeNormalizer $barcodeNormalizer;
|
||||
|
||||
public function __construct(BarcodeRedirector $barcodeParser, BarcodeNormalizer $barcodeNormalizer)
|
||||
public function __construct(protected BarcodeRedirector $barcodeParser, protected BarcodeNormalizer $barcodeNormalizer)
|
||||
{
|
||||
$this->barcodeParser = $barcodeParser;
|
||||
$this->barcodeNormalizer = $barcodeNormalizer;
|
||||
}
|
||||
|
||||
#[Route(path: '', name: 'scan_dialog')]
|
||||
|
@ -79,10 +74,10 @@ class ScanController extends AbstractController
|
|||
|
||||
try {
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
|
||||
} catch (EntityNotFoundException $exception) {
|
||||
} catch (EntityNotFoundException) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
}
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
} catch (InvalidArgumentException) {
|
||||
$this->addFlash('error', 'scan.format_unknown');
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +96,7 @@ class ScanController extends AbstractController
|
|||
$this->addFlash('success', 'scan.qr_success');
|
||||
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
|
||||
} catch (EntityNotFoundException $exception) {
|
||||
} catch (EntityNotFoundException) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
|
||||
return $this->redirectToRoute('homepage');
|
||||
|
|
|
@ -48,13 +48,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
protected TranslatorInterface $translator;
|
||||
protected bool $allow_email_pw_reset;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, bool $allow_email_pw_reset)
|
||||
public function __construct(protected TranslatorInterface $translator, protected bool $allow_email_pw_reset)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->allow_email_pw_reset = $allow_email_pw_reset;
|
||||
}
|
||||
|
||||
#[Route(path: '/login', name: 'login', methods: ['GET', 'POST'])]
|
||||
|
@ -76,7 +71,7 @@ class SecurityController extends AbstractController
|
|||
* @return RedirectResponse|Response
|
||||
*/
|
||||
#[Route(path: '/pw_reset/request', name: 'pw_reset_request')]
|
||||
public function requestPwReset(PasswordResetManager $passwordReset, Request $request)
|
||||
public function requestPwReset(PasswordResetManager $passwordReset, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
if (!$this->allow_email_pw_reset) {
|
||||
throw new AccessDeniedHttpException('The password reset via email is disabled!');
|
||||
|
@ -119,7 +114,7 @@ class SecurityController extends AbstractController
|
|||
* @return RedirectResponse|Response
|
||||
*/
|
||||
#[Route(path: '/pw_reset/new_pw/{user}/{token}', name: 'pw_reset_new_pw')]
|
||||
public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher, ?string $user = null, ?string $token = null)
|
||||
public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher, ?string $user = null, ?string $token = null): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
if (!$this->allow_email_pw_reset) {
|
||||
throw new AccessDeniedHttpException('The password reset via email is disabled!');
|
||||
|
@ -189,7 +184,7 @@ class SecurityController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route(path: '/logout', name: 'logout')]
|
||||
public function logout(): void
|
||||
public function logout(): never
|
||||
{
|
||||
throw new RuntimeException('Will be intercepted before getting here');
|
||||
}
|
||||
|
|
|
@ -42,15 +42,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
#[Route(path: '/select_api')]
|
||||
class SelectAPIController extends AbstractController
|
||||
{
|
||||
private NodesListBuilder $nodesListBuilder;
|
||||
private TranslatorInterface $translator;
|
||||
private StructuralEntityChoiceHelper $choiceHelper;
|
||||
|
||||
public function __construct(NodesListBuilder $nodesListBuilder, TranslatorInterface $translator, StructuralEntityChoiceHelper $choiceHelper)
|
||||
public function __construct(private readonly NodesListBuilder $nodesListBuilder, private readonly TranslatorInterface $translator, private readonly StructuralEntityChoiceHelper $choiceHelper)
|
||||
{
|
||||
$this->nodesListBuilder = $nodesListBuilder;
|
||||
$this->translator = $translator;
|
||||
$this->choiceHelper = $choiceHelper;
|
||||
}
|
||||
|
||||
#[Route(path: '/category', name: 'select_category')]
|
||||
|
@ -92,17 +85,12 @@ class SelectAPIController extends AbstractController
|
|||
3 => $this->translator->trans('export.level.full'),
|
||||
];
|
||||
|
||||
return $this->json(array_map(static function ($key, $value) {
|
||||
return [
|
||||
'text' => $value,
|
||||
'value' => $key,
|
||||
];
|
||||
}, array_keys($entries), $entries));
|
||||
return $this->json(array_map(static fn($key, $value) => [
|
||||
'text' => $value,
|
||||
'value' => $key,
|
||||
], array_keys($entries), $entries));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/label_profiles', name: 'select_label_profiles')]
|
||||
public function labelProfiles(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
|
@ -121,9 +109,6 @@ class SelectAPIController extends AbstractController
|
|||
return $this->json($nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/label_profiles_lot', name: 'select_label_profiles_lot')]
|
||||
public function labelProfilesLot(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
|
|
|
@ -77,7 +77,7 @@ class ToolsController extends AbstractController
|
|||
'php_version' => PHP_VERSION,
|
||||
'php_uname' => php_uname('a'),
|
||||
'php_sapi' => PHP_SAPI,
|
||||
'php_extensions' => array_merge(get_loaded_extensions()),
|
||||
'php_extensions' => [...get_loaded_extensions()],
|
||||
'php_opcache_enabled' => ini_get('opcache.enable'),
|
||||
'php_upload_max_filesize' => ini_get('upload_max_filesize'),
|
||||
'php_post_max_size' => ini_get('post_max_size'),
|
||||
|
@ -91,32 +91,22 @@ class ToolsController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/builtin_footprints', name: 'tools_builtin_footprints_viewer')]
|
||||
public function builtInFootprintsViewer(BuiltinAttachmentsFinder $builtinAttachmentsFinder, AttachmentURLGenerator $urlGenerator): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('@tools.builtin_footprints_viewer');
|
||||
|
||||
$grouped_footprints = $builtinAttachmentsFinder->getListOfFootprintsGroupedByFolder();
|
||||
$grouped_footprints = array_map(function($group) use ($urlGenerator) {
|
||||
return array_map(function($placeholder_filepath) use ($urlGenerator) {
|
||||
return [
|
||||
'filename' => basename($placeholder_filepath),
|
||||
'assets_path' => $urlGenerator->placeholderPathToAssetPath($placeholder_filepath),
|
||||
];
|
||||
}, $group);
|
||||
}, $grouped_footprints);
|
||||
$grouped_footprints = array_map(fn($group) => array_map(fn($placeholder_filepath) => [
|
||||
'filename' => basename((string) $placeholder_filepath),
|
||||
'assets_path' => $urlGenerator->placeholderPathToAssetPath($placeholder_filepath),
|
||||
], $group), $grouped_footprints);
|
||||
|
||||
return $this->render('tools/builtin_footprints_viewer/builtin_footprints_viewer.html.twig', [
|
||||
'grouped_footprints' => $grouped_footprints,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
#[Route(path: '/ic_logos', name: 'tools_ic_logos')]
|
||||
public function icLogos(): Response
|
||||
{
|
||||
|
|
|
@ -40,11 +40,8 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
#[Route(path: '/tree')]
|
||||
class TreeController extends AbstractController
|
||||
{
|
||||
protected TreeViewGenerator $treeGenerator;
|
||||
|
||||
public function __construct(TreeViewGenerator $treeGenerator)
|
||||
public function __construct(protected TreeViewGenerator $treeGenerator)
|
||||
{
|
||||
$this->treeGenerator = $treeGenerator;
|
||||
}
|
||||
|
||||
#[Route(path: '/tools', name: 'tree_tools')]
|
||||
|
|
|
@ -55,13 +55,8 @@ use Symfony\Component\Serializer\Serializer;
|
|||
#[Route(path: '/typeahead')]
|
||||
class TypeaheadController extends AbstractController
|
||||
{
|
||||
protected AttachmentURLGenerator $urlGenerator;
|
||||
protected Packages $assets;
|
||||
|
||||
public function __construct(AttachmentURLGenerator $URLGenerator, Packages $assets)
|
||||
public function __construct(protected AttachmentURLGenerator $urlGenerator, protected Packages $assets)
|
||||
{
|
||||
$this->urlGenerator = $URLGenerator;
|
||||
$this->assets = $assets;
|
||||
}
|
||||
|
||||
#[Route(path: '/builtInResources/search', name: 'typeahead_builtInRessources')]
|
||||
|
@ -93,45 +88,26 @@ class TypeaheadController extends AbstractController
|
|||
|
||||
/**
|
||||
* This function map the parameter type to the class, so we can access its repository
|
||||
* @param string $type
|
||||
* @return class-string
|
||||
*/
|
||||
private function typeToParameterClass(string $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'category':
|
||||
return CategoryParameter::class;
|
||||
case 'part':
|
||||
return PartParameter::class;
|
||||
case 'device':
|
||||
return ProjectParameter::class;
|
||||
case 'footprint':
|
||||
return FootprintParameter::class;
|
||||
case 'manufacturer':
|
||||
return ManufacturerParameter::class;
|
||||
case 'storelocation':
|
||||
return StorelocationParameter::class;
|
||||
case 'supplier':
|
||||
return SupplierParameter::class;
|
||||
case 'attachment_type':
|
||||
return AttachmentTypeParameter::class;
|
||||
case 'group':
|
||||
return GroupParameter::class;
|
||||
case 'measurement_unit':
|
||||
return MeasurementUnitParameter::class;
|
||||
case 'currency':
|
||||
return Currency::class;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid parameter type: '.$type);
|
||||
}
|
||||
return match ($type) {
|
||||
'category' => CategoryParameter::class,
|
||||
'part' => PartParameter::class,
|
||||
'device' => ProjectParameter::class,
|
||||
'footprint' => FootprintParameter::class,
|
||||
'manufacturer' => ManufacturerParameter::class,
|
||||
'storelocation' => StorelocationParameter::class,
|
||||
'supplier' => SupplierParameter::class,
|
||||
'attachment_type' => AttachmentTypeParameter::class,
|
||||
'group' => GroupParameter::class,
|
||||
'measurement_unit' => MeasurementUnitParameter::class,
|
||||
'currency' => Currency::class,
|
||||
default => throw new \InvalidArgumentException('Invalid parameter type: '.$type),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @return JsonResponse
|
||||
*/
|
||||
#[Route(path: '/parts/search/{query}', name: 'typeahead_parts')]
|
||||
public function parts(EntityManagerInterface $entityManager, PartPreviewGenerator $previewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator, string $query = ""): JsonResponse
|
||||
|
@ -146,7 +122,7 @@ class TypeaheadController extends AbstractController
|
|||
foreach ($parts as $part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
|
||||
if($preview_attachment !== null) {
|
||||
if($preview_attachment instanceof \App\Entity\Attachments\Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
|
||||
} else {
|
||||
$preview_url = '';
|
||||
|
@ -156,8 +132,8 @@ class TypeaheadController extends AbstractController
|
|||
$data[] = [
|
||||
'id' => $part->getID(),
|
||||
'name' => $part->getName(),
|
||||
'category' => $part->getCategory() ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() ? $part->getFootprint()->getName() : '',
|
||||
'category' => $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getName() : '',
|
||||
'description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
|
@ -166,10 +142,6 @@ class TypeaheadController extends AbstractController
|
|||
return new JsonResponse($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @return JsonResponse
|
||||
*/
|
||||
#[Route(path: '/parameters/{type}/search/{query}', name: 'typeahead_parameters', requirements: ['type' => '.+'])]
|
||||
public function parameters(string $type, EntityManagerInterface $entityManager, string $query = ""): JsonResponse
|
||||
{
|
||||
|
|
|
@ -180,7 +180,7 @@ class UserController extends AdminPages\BaseAdminController
|
|||
public function userInfo(?User $user, Packages $packages, Request $request, DataTableFactory $dataTableFactory): Response
|
||||
{
|
||||
//If no user id was passed, then we show info about the current user
|
||||
if (null === $user) {
|
||||
if (!$user instanceof \App\Entity\UserSystem\User) {
|
||||
$tmp = $this->getUser();
|
||||
if (!$tmp instanceof User) {
|
||||
throw new InvalidArgumentException('Userinfo only works for database users!');
|
||||
|
|
|
@ -54,16 +54,13 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
#[Route(path: '/user')]
|
||||
class UserSettingsController extends AbstractController
|
||||
{
|
||||
protected bool $demo_mode;
|
||||
|
||||
/**
|
||||
* @var EventDispatcher|EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
public function __construct(bool $demo_mode, EventDispatcherInterface $eventDispatcher)
|
||||
public function __construct(protected bool $demo_mode, EventDispatcherInterface $eventDispatcher)
|
||||
{
|
||||
$this->demo_mode = $demo_mode;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
|
@ -121,49 +118,43 @@ class UserSettingsController extends AbstractController
|
|||
$key_repo = $entityManager->getRepository(U2FKey::class);
|
||||
/** @var U2FKey|null $u2f */
|
||||
$u2f = $key_repo->find($key_id);
|
||||
if (null === $u2f) {
|
||||
if (!$u2f instanceof \App\Entity\UserSystem\U2FKey) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
//User can only delete its own U2F keys
|
||||
if ($u2f->getUser() !== $user) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.access_denied');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
$backupCodeManager->disableBackupCodesIfUnused($user);
|
||||
$entityManager->remove($u2f);
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', 'tfa.u2f.u2f_delete.success');
|
||||
|
||||
$security_event = new SecurityEvent($user);
|
||||
$this->eventDispatcher->dispatch($security_event, SecurityEvents::U2F_REMOVED);
|
||||
} else if ($request->request->has('webauthn_key_id')) {
|
||||
} elseif ($request->request->has('webauthn_key_id')) {
|
||||
$key_id = $request->request->get('webauthn_key_id');
|
||||
$key_repo = $entityManager->getRepository(WebauthnKey::class);
|
||||
/** @var WebauthnKey|null $key */
|
||||
$key = $key_repo->find($key_id);
|
||||
if (null === $key) {
|
||||
if (!$key instanceof \App\Entity\UserSystem\WebauthnKey) {
|
||||
$this->addFlash('error', 'tfa_u2f.u2f_delete.not_existing');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
//User can only delete its own U2F keys
|
||||
if ($key->getUser() !== $user) {
|
||||
$this->addFlash('error', 'tfa_u2f.u2f_delete.access_denied');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
$backupCodeManager->disableBackupCodesIfUnused($user);
|
||||
$entityManager->remove($key);
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', 'tfa.u2f.u2f_delete.success');
|
||||
|
||||
$security_event = new SecurityEvent($user);
|
||||
$this->eventDispatcher->dispatch($security_event, SecurityEvents::U2F_REMOVED);
|
||||
}
|
||||
|
@ -174,11 +165,8 @@ class UserSettingsController extends AbstractController
|
|||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RuntimeException|RedirectResponse
|
||||
*/
|
||||
#[Route(path: '/invalidate_trustedDevices', name: 'tfa_trustedDevices_invalidate', methods: ['DELETE'])]
|
||||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager)
|
||||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager): \RuntimeException|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
{
|
||||
if ($this->demo_mode) {
|
||||
throw new RuntimeException('You can not do 2FA things in demo mode');
|
||||
|
@ -215,7 +203,7 @@ class UserSettingsController extends AbstractController
|
|||
* @return RedirectResponse|Response
|
||||
*/
|
||||
#[Route(path: '/settings', name: 'user_settings')]
|
||||
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager, FormFactoryInterface $formFactory, UserAvatarHelper $avatarHelper)
|
||||
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager, FormFactoryInterface $formFactory, UserAvatarHelper $avatarHelper): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
@ -254,13 +242,11 @@ class UserSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
/** @var Form $form We need a form implementation for the next calls */
|
||||
if ($form->getClickedButton() && 'remove_avatar' === $form->getClickedButton()->getName()) {
|
||||
//Remove the avatar attachment from the user if requested
|
||||
if ($user->getMasterPictureAttachment() !== null) {
|
||||
$em->remove($user->getMasterPictureAttachment());
|
||||
$user->setMasterPictureAttachment(null);
|
||||
$page_need_reload = true;
|
||||
}
|
||||
//Remove the avatar attachment from the user if requested
|
||||
if ($form->getClickedButton() && 'remove_avatar' === $form->getClickedButton()->getName() && $user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
|
||||
$em->remove($user->getMasterPictureAttachment());
|
||||
$user->setMasterPictureAttachment(null);
|
||||
$page_need_reload = true;
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
|
|
@ -33,11 +33,8 @@ use function Symfony\Component\Translation\t;
|
|||
|
||||
class WebauthnKeyRegistrationController extends AbstractController
|
||||
{
|
||||
private bool $demo_mode;
|
||||
|
||||
public function __construct(bool $demo_mode)
|
||||
public function __construct(private readonly bool $demo_mode)
|
||||
{
|
||||
$this->demo_mode = $demo_mode;
|
||||
}
|
||||
|
||||
#[Route(path: '/webauthn/register', name: 'webauthn_register')]
|
||||
|
@ -73,7 +70,7 @@ class WebauthnKeyRegistrationController extends AbstractController
|
|||
//Check the response
|
||||
try {
|
||||
$new_key = $registrationHelper->checkRegistrationResponse($webauthnResponse);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
$this->addFlash('error', t('tfa_u2f.add_key.registration_error'));
|
||||
return $this->redirectToRoute('webauthn_register');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue