Use BaseController

This commit is contained in:
Benoît Burnichon
2015-04-02 13:35:44 +02:00
parent 447029bc6a
commit 5f8dab86fd
9 changed files with 18 additions and 332 deletions

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Repositories\UserRepository;
@@ -20,49 +21,8 @@ use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class CollectionController
class CollectionController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* @return User|null
*/
private function getAuthenticatedUser()
{
/** @var Authenticator $authenticator */
$authenticator = $this->app['authentication'];
return $authenticator->getUser();
}
/**
* @return \ACL
*/
private function getAuthenticatedUserAcl()
{
/** @var ACLProvider $acl */
$acl = $this->app['acl'];
return $acl->get($this->getAuthenticatedUser());
}
/**
* @param string $template
* @param array $parameters
* @return string
*/
private function render($template, array $parameters = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render($template, $parameters);
}
/**
* Display collection information page
*
@@ -76,7 +36,7 @@ class CollectionController
$admins = [];
if ($this->getAuthenticatedUserAcl()->has_right_on_base($bas_id, 'manage')) {
if ($this->getAclForUser()->has_right_on_base($bas_id, 'manage')) {
/** @var \User_Query $query */
$query = $this->app['phraseanet.user-query'];
$admins = $query->on_base_ids([$bas_id])

View File

@@ -13,16 +13,15 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Geonames\Exception\ExceptionInterface;
use Alchemy\Geonames\Geoname;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Model\Entities\Session;
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
class ConnectedUsersController
class ConnectedUsersController extends Controller
{
/** @var Application */
private $app;
/** @var TranslatorInterface */
private $translator;
protected $moduleNames;
@@ -31,7 +30,7 @@ class ConnectedUsersController
public function __construct(Application $app)
{
$this->app = $app;
parent::__construct($app);
$this->translator = $app['translator'];
$this->logger = $app['monolog'];
}

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Cache\Cache;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Manipulator\ACLManipulator;
@@ -24,16 +25,8 @@ use Alchemy\Phrasea\Notification\Receiver;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class DashboardController
class DashboardController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Display admin dashboard page
*
@@ -161,18 +154,6 @@ class DashboardController
return $this->app->redirectPath('admin_dashboard');
}
/**
* @param string $name
* @param array $context
* @return string
*/
public function render($name, array $context = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render($name, $context);
}
/**
* @return UserRepository
*/

View File

@@ -13,23 +13,15 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DataboxController
class DataboxController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* @param Request $request
* @param integer $databox_id
@@ -772,68 +764,4 @@ class DataboxController
'total' => $total
]);
}
/**
* @return \appbox
*/
private function getApplicationBox()
{
return $this->app['phraseanet.appbox'];
}
/**
* @param int $id
* @return \databox
*/
private function findDataboxById($id)
{
$appbox = $this->getApplicationBox();
return $appbox->get_databox($id);
}
/**
* @param $name
* @param array $context
* @return string
*/
private function render($name, array $context = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render(
$name,
$context
);
}
/**
* @return ACLProvider
*/
private function getAclProvider()
{
return $this->app['acl'];
}
/**
* @return Authenticator
*/
private function getAuthenticator()
{
return $this->app['authentication'];
}
/**
* @param User|null $user
* @return \ACL
*/
private function getAclForUser(User $user = null)
{
$aclProvider = $this->getAclProvider();
if (null === $user) {
$user = $this->getAuthenticator()->getUser();
}
return $aclProvider->get($user);
}
}

View File

@@ -11,25 +11,15 @@
namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Controller\Controller;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DataboxesController
class DataboxesController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Get Databases control panel
*
@@ -273,68 +263,4 @@ class DataboxesController
}
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
}
/**
* @return \appbox
*/
private function getApplicationBox()
{
return $this->app['phraseanet.appbox'];
}
/**
* @param int $id
* @return \databox
*/
private function findDataboxById($id)
{
$appbox = $this->getApplicationBox();
return $appbox->get_databox($id);
}
/**
* @param $name
* @param array $context
* @return string
*/
private function render($name, array $context = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render(
$name,
$context
);
}
/**
* @return ACLProvider
*/
private function getAclProvider()
{
return $this->app['acl'];
}
/**
* @return Authenticator
*/
private function getAuthenticator()
{
return $this->app['authentication'];
}
/**
* @param User|null $user
* @return \ACL
*/
private function getAclForUser(User $user = null)
{
$aclProvider = $this->getAclProvider();
if (null === $user) {
$user = $this->getAuthenticator()->getUser();
}
return $aclProvider->get($user);
}
}

View File

@@ -11,22 +11,15 @@
namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Metadata\TagProvider;
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class FieldsController
class FieldsController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function updateFields(Application $app, Request $request, $sbas_id)
{
$fields = [];

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
use Alchemy\Phrasea\Helper\User as UserHelper;
use Alchemy\Phrasea\Model\Entities\FtpCredential;
@@ -30,16 +31,8 @@ use Goodby\CSV\Import\Standard\Interpreter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class UserController
class UserController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function editRightsAction(Request $request)
{
$rights = $this->getUserEditHelper($request);
@@ -925,19 +918,6 @@ class UserController
];
}
/**
* @param string $name
* @param array $context
* @return string
*/
private function render($name, array $context = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render($name, $context);
}
/**
* @param Request $request
* @return UserHelper\Edit
@@ -983,16 +963,6 @@ class UserController
return $exporter;
}
/**
* @return User|null
*/
private function getAuthenticatedUser()
{
/** @var Authenticator $authenticator */
$authenticator = $this->app['authentication'];
return $authenticator->getUser();
}
/**
* @param array $template
* @return array
@@ -1031,17 +1001,6 @@ class UserController
return $deny;
}
/**
* @param User $user
* @return \ACL
*/
private function getAclForUser(User $user)
{
/** @var ACLProvider $aclProvider */
$aclProvider = $this->app['acl'];
return $aclProvider->get($user);
}
/**
* @return RegistrationManipulator
*/

View File

@@ -24,16 +24,8 @@ use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class LightboxController
class LightboxController extends Controller
{
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function rootAction()
{
try {
@@ -60,28 +52,6 @@ class LightboxController
]);
}
/**
* @param string $template
* @param array $parameters
* @return Response
*/
private function renderResponse($template, array $parameters = [])
{
return new Response($this->render($template, $parameters));
}
/**
* @param string $template
* @param array $parameters
* @return string
*/
private function render($template, array $parameters = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render($template, $parameters);
}
/**
* @param int $sselcont_id
* @return Response
@@ -444,16 +414,6 @@ class LightboxController
return $this->app->json($ret);
}
/**
* @return mixed
*/
private function getAuthenticatedUser()
{
/** @var Authenticator $authentication */
$authentication = $this->app['authentication'];
return $authentication->getUser();
}
/**
* @param Basket $basket
* @return Response

View File

@@ -21,28 +21,8 @@ use Doctrine\DBAL\Connection;
use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request;
class SetupController
class SetupController extends Controller
{
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* @param string $template
* @param array $parameters
* @return string
*/
private function render($template, array $parameters = [])
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
return $twig->render($template, $parameters);
}
public function rootInstaller(Request $request)
{
$requirementsCollection = $this->getRequirementsCollection();