Unverified Commit 7c3be100 authored by Sebastian Castro's avatar Sebastian Castro
Browse files

Fixs service injection in controller, and other stuff

parent 32f2caa3
......@@ -35,7 +35,7 @@ USE_AS_SAAS=false
CONTACT_EMAIL=contact@localhost.fr
INSTANCE_NAME=GoGoCarto
BASE_PROTOCOL=https
BASE_PROTOCOL=http
BASE_URL=saas.localhost # my-site.com
BASE_PATH=/GoGoCarto/web/app_dev.php
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "859fa5df749eb01ea5858c2abfc6c77b",
"content-hash": "27252bcff4f0f4bbd366f42378f7347b",
"packages": [
{
"name": "alcaeus/mongo-php-adapter",
......@@ -8189,6 +8189,55 @@
],
"time": "2020-01-13T11:15:53+00:00"
},
{
"name": "symfony/process",
"version": "4.4.x-dev",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "f5697ab4cb14a5deed7473819e63141bf5352c36"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/f5697ab4cb14a5deed7473819e63141bf5352c36",
"reference": "f5697ab4cb14a5deed7473819e63141bf5352c36",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2020-01-09T09:50:08+00:00"
},
{
"name": "symfony/property-access",
"version": "4.4.x-dev",
......
......@@ -4,13 +4,13 @@ fos_user:
user_class: App\Document\User
registration:
form:
type: gogo_user_registration
type: App\Application\Sonata\UserBundle\Form\Type\RegistrationFormType
confirmation:
enabled: true
from_email:
address: "%from_email%"
sender_name: "%env(instance_name)%"
sender_name: "%instance_name%"
group:
group_class: App\Application\Sonata\UserBundle\Document\Group
......
framework:
default_locale: en
default_locale: fr
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
......
......@@ -14,7 +14,6 @@ twig:
oauth_google: '%env(oauth_google_id)%'
oauth_facebook: '%env(oauth_facebook_id)%'
paths:
"%kernel.root_dir%/../templates/bundles/SonataUserBundle": UserBundle
"%kernel.root_dir%/../web": RootDir
form_themes:
- '@SonataFormatter/Form/formatter.html.twig'
......@@ -3,32 +3,32 @@ vich_uploader:
mappings:
default_file:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: vich_uploader.namer_origname
import_file:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
image:
upload_destination: '%kernel.root_dir%/../web'
# inject_on_load: true
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: vich_uploader.namer_origname
element_image:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: vich_uploader.namer_origname
delete_on_remove: true
element_file:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: vich_uploader.namer_origname
delete_on_remove: true
partner_image:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: ~
config_image:
upload_destination: '%kernel.root_dir%/../web'
directory_namer: gogo.upload_directory_namer
directory_namer: App\Services\UploadDirectoryNamer
namer: ~
# if you add new image class, don't forget to add the relevant service in services_admin.yml
\ No newline at end of file
# ELEMENTS
gogo_api_ui:
path: /api
defaults: { _controller: App\Controller\APIController::apiUi }
defaults: { _controller: App\Controller\APIController::apiUiAction }
gogo_api_elements_from_text:
path: /api/elements/search
......
......@@ -9,10 +9,11 @@ parameters:
locale: fr
router.request_context.host: '%env(string:BASE_URL)%'
router.request_context.base_url: '%env(BASE_PATH)%'
from_email: "%env(FROM_EMAIL)"
from_email: "%env(FROM_EMAIL)%"
use_as_saas: '%env(USE_AS_SAAS)%'
images_max_filesize: "%env(IMAGES_MAX_FILESIZE)%"
files_max_filesize: "%env(FILES_MAX_FILESIZE)%"
base_protocol: '%env(BASE_PROTOCOL)%'
base_path: '%env(BASE_PATH)%'
base_url: '%env(BASE_URL)%'
instance_name: '%env(INSTANCE_NAME)%'
......@@ -68,7 +69,6 @@ services:
gogo_user.registration.form.type:
class: App\Application\Sonata\UserBundle\Form\Type\RegistrationFormType
public: true
arguments: [ "%fos_user.model.user.class%" ]
tags:
- { name: "form.type", alias: "gogo_user_registration"}
......@@ -114,11 +114,67 @@ services:
- "@security.authorization_checker"
- [ROLE_SUPER_ADMIN]
App\Services\UploadDirectoryNamer:
class: App\Services\UploadDirectoryNamer
public: true
arguments: []
App\Services\GoGoCartoJsService:
arguments:
$baseProtocol: '%base_protocol%'
gogo.async.factory:
class: App\Services\AsyncServiceFactory
arguments:
$rootDir: '%kernel.root_dir%'
gogo.async:
class: App\Services\AsyncService
factory: 'gogo.async.factory:createAsyncService'
# # SONATA BLOCKS
# EVENT LISTENERS
gogo.image_resizer:
class: App\EventListener\ImageResizer
arguments:
- '%env(IMAGE_RESIZE_WIDTH)%'
tags:
- { name: doctrine_mongodb.odm.event_listener, event: postPersist }
gogo.config_listener:
class: App\EventListener\ConfigurationListener
tags:
- { name: doctrine_mongodb.odm.event_listener, event: preUpdate }
arguments: [ "@gogo.async" ]
gogo.element_json_generator:
class: App\EventListener\ElementJsonGenerator
public: true
tags:
- { name: doctrine_mongodb.odm.event_listener, event: preFlush }
gogo.taxonomy_json_generator:
class: App\EventListener\TaxonomyJsonGenerator
public: true
arguments: [ '@jms_serializer' ]
tags:
- { name: doctrine_mongodb.odm.event_listener, event: postPersist }
- { name: doctrine_mongodb.odm.event_listener, event: postFlush }
- { name: doctrine_mongodb.odm.event_listener, event: preFlush }
- { name: doctrine_mongodb.odm.event_listener, event: postUpdate }
gogo.db_integrity:
class: App\EventListener\DatabaseIntegrityWatcher
public: true
arguments: ["@gogo.async"]
tags:
- { name: doctrine_mongodb.odm.event_listener, event: preRemove }
- { name: doctrine_mongodb.odm.event_listener, event: preFlush }
- { name: doctrine_mongodb.odm.event_listener, event: preUpdate }
# SONATA BLOCKS
gogo.block.service.monitoring:
class: App\Block\MonitoringElementsBlockService
public: true
arguments: [ "@twig", "@doctrine.odm.mongodb.document_manager" ]
tags:
- { name: sonata.block }
......
......@@ -24,6 +24,7 @@ use App\Application\Sonata\UserBundle\Form\Type\RegistrationFormType;
use App\Document\User;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Doctrine\ODM\MongoDB\DocumentManager;
use FOS\UserBundle\Doctrine\UserManager;
/**
* This class is inspired from the FOS RegistrationController.
......@@ -113,11 +114,11 @@ class RegistrationFOSUser1Controller extends Controller
*
* @throws NotFoundHttpException
*/
public function checkEmailAction()
public function checkEmailAction(UserManager $userManager)
{
$email = $this->get('session')->get('fos_user_send_confirmation_email/email');
$this->get('session')->remove('fos_user_send_confirmation_email/email');
$user = $this->get('fos_user.user_manager')->findUserByEmail($email);
$user = $userManager->findUserByEmail($email);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email));
......@@ -137,9 +138,9 @@ class RegistrationFOSUser1Controller extends Controller
*
* @throws NotFoundHttpException
*/
public function confirmAction($token)
public function confirmAction($token, UserManager $userManager)
{
$user = $this->get('fos_user.user_manager')->findUserByConfirmationToken($token);
$user = $userManager->findUserByConfirmationToken($token);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
......@@ -149,7 +150,7 @@ class RegistrationFOSUser1Controller extends Controller
$user->setEnabled(true);
$user->setLastLogin(new \DateTime());
$this->get('fos_user.user_manager')->updateUser($user);
$userManager->updateUser($user);
if ($redirectRoute = $this->getParameter('sonata.user.register.confirm.redirect_route')) {
$response = $this->redirect($this->generateUrl(
$redirectRoute,
......
......@@ -255,7 +255,7 @@ class APIController extends GoGoController
}
$options = $dm->getRepository('App\Document\Option')->findAll();
return $this->render('BiopenCoreBundle:api:api-ui.html.twig', array('options' => $options));
return $this->render('api/api-ui.html.twig', array('options' => $options, 'config' => $config));
}
public function getManifestAction(DocumentManager $dm)
......@@ -273,7 +273,7 @@ class APIController extends GoGoController
}
if (!$imageData) {
$imgUrl = $this->getRequest()->getUriForPath('/assets/img/default-icon.png');
if ($this->container->get('kernel')->getEnvironment() == 'dev') {
if ($this->container->getParameter('kernel.environment') == 'dev') {
$imgUrl = str_replace('app_dev.php/', '', $imgUrl);
}
try {
......
<?php
namespace App\Controller;
namespace App\Controller\Admin;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
......
......@@ -54,10 +54,11 @@ class CoreController extends GoGoController
public function partnersAction(DocumentManager $dm)
{
$repository = $dm->getRepository('App\Document\Partner');
$config = $dm->getRepository('App\Document\Configuration')->findConfiguration();
$listPartners = $repository->findAllOrderedByPosition();
return $this->render('partners.html.twig', array('listPartners' => $listPartners));
return $this->render('partners.html.twig', array('listPartners' => $listPartners, 'config' => $config));
}
public function helpAction()
......
......@@ -14,12 +14,13 @@ namespace App\Controller;
use App\Controller\GoGoController;
use Symfony\Component\HttpFoundation\Request;
use App\Services\GoGoCartoJsService;
class DirectoryController extends GoGoController
{
public function renderAction(Request $request)
public function renderAction(Request $request, GoGoCartoJsService $gogoJsService)
{
$gogoConfig = $this->get('gogo.gogocartojs_service')->getConfig();
return $this->render('BiopenGeoDirectoryBundle:directory:directory.html.twig', array('gogoConfig' => $gogoConfig));
$gogoConfig = $gogoJsService->getConfig();
return $this->render('directory/directory.html.twig', array('gogoConfig' => $gogoConfig));
}
}
......@@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Document\Element;
use Doctrine\ODM\MongoDB\DocumentManager;
use App\Services\ElementActionService;
class DuplicatesController extends GoGoController
{
......@@ -46,11 +47,11 @@ class DuplicatesController extends GoGoController
}
$dm->flush();
return $this->render('BiopenGeoDirectoryBundle:duplicates:duplicates-index.html.twig', array('duplicatesNode' => $duplicatesNode, 'controller' => $this, 'optionsNames' => $optionsNames, 'leftDuplicatesToProceedCount' => $leftDuplicatesToProceedCount));
return $this->render('duplicates/duplicates-index.html.twig', array('duplicatesNode' => $duplicatesNode, 'controller' => $this, 'optionsNames' => $optionsNames, 'leftDuplicatesToProceedCount' => $leftDuplicatesToProceedCount));
}
// Will mark all the
public function markAsNonDuplicateAction(Request $request, DocumentManager $dm)
public function markAsNonDuplicateAction(Request $request, DocumentManager $dm, ElementActionService $elementActionService)
{
if($request->isXmlHttpRequest())
{
......@@ -59,8 +60,6 @@ class DuplicatesController extends GoGoController
$element = $dm->getRepository('App\Document\Element')->find($request->get('elementId'));
$elementActionService = $this->container->get('gogo.element_action_service');
$element->setIsDuplicateNode(false);
$duplicates = $element->getPotentialDuplicates() ? $element->getPotentialDuplicates()->toArray() : [];
// if no potential duplicates, element has already been resolved, nothing to do
......
......@@ -8,11 +8,8 @@
* @license MIT License
* @Last Modified time: 2018-07-08 16:44:57
*/
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Controller\GoGoController;
......@@ -26,19 +23,26 @@ use App\Services\ElementFormService;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use FOS\UserBundle\Security\LoginManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use joshtronic\LoremIpsum;
use App\Services\ElementActionService;
class ElementFormController extends GoGoController
{
public function addAction(Request $request, SessionInterface $session, DocumentManager $dm, ConfigurationService $configService, ElementDuplicatesService $duplicateService, ElementFormService $elementFormService)
public function addAction(Request $request, SessionInterface $session, DocumentManager $dm,
ConfigurationService $configService, ElementDuplicatesService $duplicateService,
ElementFormService $elementFormService, UserManagerInterface $userManager,
ElementActionService $elementActionService, LoginManagerInterface $loginManager)
{
return $this->renderForm(new Element(), false, $request, $session, $dm, $configService, $duplicateService, $elementFormService);
return $this->renderForm(new Element(), false, $request, $session, $dm, $configService, $duplicateService, $elementFormService, $userManager, $elementActionService, $loginManager);
}
public function editAction($id, Request $request, SessionInterface $session, DocumentManager $dm, ConfigurationService $configService, ElementDuplicatesService $duplicateService, ElementFormService $elementFormService)
public function editAction($id, Request $request, SessionInterface $session, DocumentManager $dm,
ConfigurationService $configService, ElementDuplicatesService $duplicateService,
ElementFormService $elementFormService, UserManagerInterface $userManager,
ElementActionService $elementActionService, LoginManagerInterface $loginManager)
{
$element = $dm->getRepository('App\Document\Element')->find($id);
......@@ -51,7 +55,7 @@ class ElementFormController extends GoGoController
|| $configService->isUserAllowed('directModeration')
|| ($element->isPending() && $element->getRandomHash() == $request->get('hash')))
{
return $this->renderForm($element, true, $request, $session, $dm, $configService, $duplicateService, $elementFormService);
return $this->renderForm($element, true, $request, $session, $dm, $configService, $duplicateService, $elementFormService, $userManager, $elementActionService, $loginManager);
}
else
{
......@@ -61,11 +65,10 @@ class ElementFormController extends GoGoController
}
// render for both Add and Edit actions
private function renderForm($element, $editMode, $request, $session, $dm, $configService, $duplicateService, $elementFormService)
private function renderForm($element, $editMode, $request, $session, $dm, $configService, $duplicateService,
$elementFormService, $userManager, $elementActionService)
{
if (null === $element) {
throw new NotFoundHttpException("Cet élément n'existe pas.");
}
if (null === $element) { throw new NotFoundHttpException("Cet élément n'existe pas."); }
$addOrEditComplete = false;
$userRoles = [];
......@@ -81,8 +84,8 @@ class ElementFormController extends GoGoController
{
// creating simple form to let user enter a email address
$loginform = $this->get('form.factory')->createNamedBuilder('user', 'form')
->add('email', 'email', array('required' => false))
->getForm();
->add('email', 'email', array('required' => false))
->getForm();
$userEmail = $request->request->get('user')['email'];
$emailAlreadyUsed = false;
......@@ -224,8 +227,6 @@ class ElementFormController extends GoGoController
if ($inputPassword)
{
$userManager = $this->container->get('fos_user.user_manager');
// Create our user and set details
$user = $userManager->createUser();
$user->setUserName($userEmail);
......@@ -240,12 +241,11 @@ class ElementFormController extends GoGoController
$text = 'Votre compte a bien été créé ! Vous pouvez maintenant compléter <a href="'. $this->generateUrl('gogo_user_profile') .'" >votre profil</a> !';
$session->getFlashBag()->add('success', $text);
$this->authenticateUser($user);
$this->authenticateUser($user, $loginManager);
}
if ($this->isRealModification($element, $request))
{
$elementActionService = $this->container->get('gogo.element_action_service');
$message = $request->get('admin-message');
if ($isAllowedDirectModeration || $isMinorModification)
......@@ -354,10 +354,10 @@ class ElementFormController extends GoGoController
}
}
protected function authenticateUser($user)
protected function authenticateUser($user, $loginManager)
{
try {
$this->container->get('fos_user.security.login_manager')->loginUser(
$loginManager->loginUser(
$this->getParameter('fos_user.firewall_name'),
$user, null);
} catch (AccountStatusException $ex) {
......
......@@ -16,20 +16,24 @@ namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\ODM\MongoDB\DocumentManager;
use App\Document\Element;
use App\Document\ElementStatus;
use App\Document\UserInteractionReport;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Services\ConfigurationService;
use App\Services\ElementVoteService;
use App\Services\MailService;
use App\Services\ElementActionService;
class ElementInteractionController extends Controller
{
public function voteAction(Request $request, DocumentManager $dm)
public function voteAction(Request $request, DocumentManager $dm, ConfigurationService $confService,
ElementVoteService $voteService)
{
if (!$this->container->get('gogo.config_service')->isUserAllowed('vote', $request))
if (!$confService->isUserAllowed('vote', $request))
return $this->returnResponse($dm, false,"Désolé, vous n'êtes pas autorisé à voter !");
// CHECK REQUEST IS VALID
......@@ -38,15 +42,16 @@ class ElementInteractionController extends Controller
$element = $dm->getRepository('App\Document\Element')->find($request->get('elementId'));
$resultMessage = $this->get('gogo.element_vote_service')
->voteForElement($element, $request->get('value'), $request->get('comment'), $request->get('userEmail'));
$resultMessage = $voteService->voteForElement($element, $request->get('value'),
$request->get('comment'),
$request->get('userEmail'));
return $this->returnResponse($dm, true, $resultMessage, $element->getStatus());
}
public function reportErrorAction(Request $request, DocumentManager $dm)
public function reportErrorAction(Request $request, DocumentManager $dm, ConfigurationService $confService)
{
if (!$this->container->get('gogo.config_service')->isUserAllowed('report', $request))
if (!$confService->isUserAllowed('report', $request))
return $this->returnResponse($dm, false,"Désolé, vous n'êtes pas autorisé à signaler d'erreurs !");
// CHECK REQUEST IS VALID
......@@ -71,9 +76,10 @@ class ElementInteractionController extends Controller
return $this->returnResponse($dm, true, "Merci, votre signalement a bien été enregistré !");
}
public function deleteAction(Request $request, DocumentManager $dm)
public function deleteAction(Request $request, DocumentManager $dm, ConfigurationService $confService,
ElementActionService $elementActionService)
{
if (!$this->container->get('gogo.config_service')->isUserAllowed('delete', $request))
if (!$confService->isUserAllowed('delete', $request))
return $this->returnResponse($dm, false,"Désolé, vous n'êtes pas autorisé à supprimer un élément !");
// CHECK REQUEST IS VALID
......@@ -83,7 +89,6 @@ class ElementInteractionController extends Controller
$element = $dm->getRepository('App\Document\Element')->find($request->get('elementId'));
$dm->persist($element);
$elementActionService = $this->container->get('gogo.element_action_service');
$elementActionService->delete($element, true, $request->get('message'));
$dm->flush();
......@@ -91,9 +96,11 @@ class ElementInteractionController extends Controller
return $this->returnResponse($dm, true, "L'élément a bien été supprimé");
}
public function resolveReportsAction(Request $request, DocumentManager $dm)
public function resolveReportsAction(Request $request, DocumentManager $dm,
ConfigurationService $confService,
ElementActionService $elementActionService)
{
if (!$this->container->get('gogo.config_service')->isUserAllowed('directModeration', $request))
if (!$confService->isUserAllowed('directModeration', $request))
return $this->returnResponse($dm, false,"Désolé, vous n'êtes pas autorisé à modérer cet élément !");
// CHECK REQUEST IS VALID
......@@ -102,7 +109,6 @@ class ElementInteractionController extends Controller
$element = $dm->getRepository('App\Document\Element')->find($request->get('elementId'));
$elementActionService = $this->container->get('gogo.element_action_service');
$elementActionService->resolveReports($element, $request->get('comment'), true);
$dm->persist($element);
......@@ -111,9 +117,10 @@ class ElementInteractionController extends Controller
return $this->returnResponse($dm, true, "L'élément a bien été modéré");
}
public function sendMailAction(Request $request, DocumentManager $dm)
public function sendMailAction(Request $request, DocumentManager $dm, ConfigurationService $confService,
MailService $mailService)
{
if (!$this->container->get('gogo.config_service')->isUserAllowed('sendMail', $request))
if (!$confService->isUserAllowed('sendMail', $request))
return $this->returnResponse($dm, false,"Désolé, vous n'êtes pas autorisé à envoyer des mails !");