mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-21 18:19:08 +02:00
Use imports instead of FQNs
This commit is contained in:
parent
f63b6d7207
commit
5629215ce4
179 changed files with 792 additions and 597 deletions
|
@ -245,7 +245,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
protected function _new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?AbstractNamedDBElement $entity = null)
|
||||
{
|
||||
$new_entity = $entity instanceof \App\Entity\Base\AbstractNamedDBElement ? clone $entity : new $this->entity_class();
|
||||
$new_entity = $entity instanceof AbstractNamedDBElement ? clone $entity : new $this->entity_class();
|
||||
|
||||
$this->denyAccessUnlessGranted('read', $new_entity);
|
||||
|
||||
|
|
|
@ -73,11 +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 ($profile instanceof \App\Entity\LabelSystem\LabelProfile) {
|
||||
if ($profile instanceof LabelProfile) {
|
||||
$this->denyAccessUnlessGranted('read', $profile);
|
||||
}
|
||||
|
||||
$label_options = $profile instanceof \App\Entity\LabelSystem\LabelProfile ? $profile->getOptions() : new LabelOptions();
|
||||
$label_options = $profile instanceof 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');
|
||||
|
@ -91,7 +91,7 @@ class LabelController extends AbstractController
|
|||
$target_id = $request->query->get('target_id', null);
|
||||
$generate = $request->query->getBoolean('generate', false);
|
||||
|
||||
if (!$profile instanceof \App\Entity\LabelSystem\LabelProfile && is_string($target_type)) {
|
||||
if (!$profile instanceof LabelProfile && is_string($target_type)) {
|
||||
$label_options->setSupportedElement($target_type);
|
||||
}
|
||||
if (is_string($target_id)) {
|
||||
|
@ -108,7 +108,7 @@ 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() && $profile instanceof \App\Entity\LabelSystem\LabelProfile)) {
|
||||
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile instanceof LabelProfile)) {
|
||||
$target_id = (string) $form->get('target_id')->getData();
|
||||
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
|
||||
if ($targets !== []) {
|
||||
|
|
|
@ -141,7 +141,7 @@ class LogController extends AbstractController
|
|||
}
|
||||
|
||||
$log_element = $this->entityManager->find(AbstractLogEntry::class, $id);
|
||||
if (!$log_element instanceof \App\Entity\LogSystem\AbstractLogEntry) {
|
||||
if (!$log_element instanceof AbstractLogEntry) {
|
||||
throw new InvalidArgumentException('No log entry with the given ID is existing!');
|
||||
}
|
||||
|
||||
|
|
|
@ -210,13 +210,13 @@ class PartController extends AbstractController
|
|||
?Part $part = null, ?Project $project = null): Response
|
||||
{
|
||||
|
||||
if ($part instanceof \App\Entity\Parts\Part) {
|
||||
if ($part instanceof Part) {
|
||||
//Clone part
|
||||
$new_part = clone $part;
|
||||
} elseif ($project instanceof \App\Entity\ProjectSystem\Project) {
|
||||
} elseif ($project instanceof 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() instanceof \App\Entity\Parts\Part) {
|
||||
if ($project->getBuildPart() instanceof Part) {
|
||||
$this->addFlash('error', 'part.new_build_part.error.build_part_already_exists');
|
||||
return $this->redirectToRoute('part_edit', ['id' => $project->getBuildPart()->getID()]);
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ class PartController extends AbstractController
|
|||
|
||||
$cid = $request->get('category', null);
|
||||
$category = $cid ? $em->find(Category::class, $cid) : null;
|
||||
if ($category instanceof \App\Entity\Parts\Category && !$new_part->getCategory() instanceof \App\Entity\Parts\Category) {
|
||||
if ($category instanceof Category && !$new_part->getCategory() instanceof Category) {
|
||||
$new_part->setCategory($category);
|
||||
$new_part->setDescription($category->getDefaultDescription());
|
||||
$new_part->setComment($category->getDefaultComment());
|
||||
|
@ -237,19 +237,19 @@ class PartController extends AbstractController
|
|||
|
||||
$fid = $request->get('footprint', null);
|
||||
$footprint = $fid ? $em->find(Footprint::class, $fid) : null;
|
||||
if ($footprint instanceof \App\Entity\Parts\Footprint && !$new_part->getFootprint() instanceof \App\Entity\Parts\Footprint) {
|
||||
if ($footprint instanceof Footprint && !$new_part->getFootprint() instanceof Footprint) {
|
||||
$new_part->setFootprint($footprint);
|
||||
}
|
||||
|
||||
$mid = $request->get('manufacturer', null);
|
||||
$manufacturer = $mid ? $em->find(Manufacturer::class, $mid) : null;
|
||||
if ($manufacturer instanceof \App\Entity\Parts\Manufacturer && !$new_part->getManufacturer() instanceof \App\Entity\Parts\Manufacturer) {
|
||||
if ($manufacturer instanceof Manufacturer && !$new_part->getManufacturer() instanceof Manufacturer) {
|
||||
$new_part->setManufacturer($manufacturer);
|
||||
}
|
||||
|
||||
$store_id = $request->get('storelocation', null);
|
||||
$storelocation = $store_id ? $em->find(Storelocation::class, $store_id) : null;
|
||||
if ($storelocation instanceof \App\Entity\Parts\Storelocation && $new_part->getPartLots()->isEmpty()) {
|
||||
if ($storelocation instanceof Storelocation && $new_part->getPartLots()->isEmpty()) {
|
||||
$partLot = new PartLot();
|
||||
$partLot->setStorageLocation($storelocation);
|
||||
$partLot->setInstockUnknown(true);
|
||||
|
@ -258,7 +258,7 @@ class PartController extends AbstractController
|
|||
|
||||
$supplier_id = $request->get('supplier', null);
|
||||
$supplier = $supplier_id ? $em->find(Supplier::class, $supplier_id) : null;
|
||||
if ($supplier instanceof \App\Entity\Parts\Supplier && $new_part->getOrderdetails()->isEmpty()) {
|
||||
if ($supplier instanceof Supplier && $new_part->getOrderdetails()->isEmpty()) {
|
||||
$orderdetail = new Orderdetail();
|
||||
$orderdetail->setSupplier($supplier);
|
||||
$new_part->addOrderdetail($orderdetail);
|
||||
|
@ -329,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 instanceof \App\Entity\Parts\PartLot) {
|
||||
if(!$partLot instanceof PartLot) {
|
||||
throw new \RuntimeException('Part lot not found!');
|
||||
}
|
||||
//Ensure that the partlot belongs to the part
|
||||
|
|
|
@ -193,7 +193,7 @@ class ProjectController extends AbstractController
|
|||
#[Route(path: '/{id}/add_parts', name: 'project_add_parts', requirements: ['id' => '\d+'])]
|
||||
public function addPart(Request $request, EntityManagerInterface $entityManager, ?Project $project): Response
|
||||
{
|
||||
if($project instanceof \App\Entity\ProjectSystem\Project) {
|
||||
if($project instanceof Project) {
|
||||
$this->denyAccessUnlessGranted('edit', $project);
|
||||
} else {
|
||||
$this->denyAccessUnlessGranted('@projects.edit');
|
||||
|
@ -203,7 +203,7 @@ class ProjectController extends AbstractController
|
|||
$builder->add('project', StructuralEntityType::class, [
|
||||
'class' => Project::class,
|
||||
'required' => true,
|
||||
'disabled' => $project instanceof \App\Entity\ProjectSystem\Project, //If a project is given, disable the field
|
||||
'disabled' => $project instanceof Project, //If a project is given, disable the field
|
||||
'data' => $project,
|
||||
'constraints' => [
|
||||
new NotNull()
|
||||
|
|
|
@ -71,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): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
public function requestPwReset(PasswordResetManager $passwordReset, Request $request): RedirectResponse|Response
|
||||
{
|
||||
if (!$this->allow_email_pw_reset) {
|
||||
throw new AccessDeniedHttpException('The password reset via email is disabled!');
|
||||
|
@ -114,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): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher, ?string $user = null, ?string $token = null): RedirectResponse|Response
|
||||
{
|
||||
if (!$this->allow_email_pw_reset) {
|
||||
throw new AccessDeniedHttpException('The password reset via email is disabled!');
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
|
@ -59,7 +60,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@parts.read') && $this->isGranted('@categories.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Category::class, $category, 'list_parts_root');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return new JsonResponse($tree);
|
||||
|
@ -72,7 +73,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@parts.read') && $this->isGranted('@footprints.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint, 'list_parts_root');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@parts.read') && $this->isGranted('@storelocations.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Storelocation::class, $location, 'list_parts_root');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return new JsonResponse($tree);
|
||||
|
@ -97,7 +98,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@parts.read') && $this->isGranted('@manufacturers.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer, 'list_parts_root');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return new JsonResponse($tree);
|
||||
|
@ -110,7 +111,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@parts.read') && $this->isGranted('@suppliers.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier, 'list_parts_root');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return new JsonResponse($tree);
|
||||
|
@ -123,7 +124,7 @@ class TreeController extends AbstractController
|
|||
if ($this->isGranted('@projects.read')) {
|
||||
$tree = $this->treeGenerator->getTreeView(Project::class, $device, 'devices');
|
||||
} else {
|
||||
return new JsonResponse("Access denied", \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
|
||||
return new JsonResponse("Access denied", Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return new JsonResponse($tree);
|
||||
|
|
|
@ -22,6 +22,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parameters\AttachmentTypeParameter;
|
||||
use App\Entity\Parameters\CategoryParameter;
|
||||
use App\Entity\Parameters\ProjectParameter;
|
||||
|
@ -83,7 +87,7 @@ class TypeaheadController extends AbstractController
|
|||
$serializer = new Serializer($normalizers, $encoders);
|
||||
$data = $serializer->serialize($result, 'json');
|
||||
|
||||
return new JsonResponse($data, \Symfony\Component\HttpFoundation\Response::HTTP_OK, [], true);
|
||||
return new JsonResponse($data, Response::HTTP_OK, [], true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +126,7 @@ class TypeaheadController extends AbstractController
|
|||
foreach ($parts as $part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
|
||||
if($preview_attachment instanceof \App\Entity\Attachments\Attachment) {
|
||||
if($preview_attachment instanceof Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
|
||||
} else {
|
||||
$preview_url = '';
|
||||
|
@ -132,8 +136,8 @@ class TypeaheadController extends AbstractController
|
|||
$data[] = [
|
||||
'id' => $part->getID(),
|
||||
'name' => $part->getName(),
|
||||
'category' => $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getName() : '',
|
||||
'category' => $part->getCategory() instanceof Category ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() instanceof Footprint ? $part->getFootprint()->getName() : '',
|
||||
'description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
|
@ -176,6 +180,6 @@ class TypeaheadController extends AbstractController
|
|||
$serializer = new Serializer($normalizers, $encoders);
|
||||
$data = $serializer->serialize($array, 'json');
|
||||
|
||||
return new JsonResponse($data, \Symfony\Component\HttpFoundation\Response::HTTP_OK, [], true);
|
||||
return new JsonResponse($data, Response::HTTP_OK, [], true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AdminPages\BaseAdminController;
|
||||
use App\DataTables\LogDataTable;
|
||||
use App\Entity\Attachments\UserAttachment;
|
||||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
|
@ -47,7 +48,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
#[Route(path: '/user')]
|
||||
class UserController extends AdminPages\BaseAdminController
|
||||
class UserController extends BaseAdminController
|
||||
{
|
||||
protected string $entity_class = User::class;
|
||||
protected string $twig_template = 'admin/user_admin.html.twig';
|
||||
|
@ -180,7 +181,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 (!$user instanceof \App\Entity\UserSystem\User) {
|
||||
if (!$user instanceof User) {
|
||||
$tmp = $this->getUser();
|
||||
if (!$tmp instanceof User) {
|
||||
throw new InvalidArgumentException('Userinfo only works for database users!');
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\UserSystem\U2FKey;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Entity\UserSystem\WebauthnKey;
|
||||
|
@ -118,7 +119,7 @@ class UserSettingsController extends AbstractController
|
|||
$key_repo = $entityManager->getRepository(U2FKey::class);
|
||||
/** @var U2FKey|null $u2f */
|
||||
$u2f = $key_repo->find($key_id);
|
||||
if (!$u2f instanceof \App\Entity\UserSystem\U2FKey) {
|
||||
if (!$u2f instanceof U2FKey) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
|
@ -140,7 +141,7 @@ class UserSettingsController extends AbstractController
|
|||
$key_repo = $entityManager->getRepository(WebauthnKey::class);
|
||||
/** @var WebauthnKey|null $key */
|
||||
$key = $key_repo->find($key_id);
|
||||
if (!$key instanceof \App\Entity\UserSystem\WebauthnKey) {
|
||||
if (!$key instanceof WebauthnKey) {
|
||||
$this->addFlash('error', 'tfa_u2f.u2f_delete.not_existing');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
|
@ -166,7 +167,7 @@ class UserSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route(path: '/invalidate_trustedDevices', name: 'tfa_trustedDevices_invalidate', methods: ['DELETE'])]
|
||||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager): \RuntimeException|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager): \RuntimeException|RedirectResponse
|
||||
{
|
||||
if ($this->demo_mode) {
|
||||
throw new RuntimeException('You can not do 2FA things in demo mode');
|
||||
|
@ -203,7 +204,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): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager, FormFactoryInterface $formFactory, UserAvatarHelper $avatarHelper): RedirectResponse|Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
@ -243,7 +244,7 @@ class UserSettingsController extends AbstractController
|
|||
|
||||
/** @var Form $form We need a form implementation for the next calls */
|
||||
//Remove the avatar attachment from the user if requested
|
||||
if ($form->getClickedButton() && 'remove_avatar' === $form->getClickedButton()->getName() && $user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
|
||||
if ($form->getClickedButton() && 'remove_avatar' === $form->getClickedButton()->getName() && $user->getMasterPictureAttachment() instanceof Attachment) {
|
||||
$em->remove($user->getMasterPictureAttachment());
|
||||
$user->setMasterPictureAttachment(null);
|
||||
$page_need_reload = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue