mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Update controllers
This commit is contained in:
@@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
abstract class AbstractDelivery implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function deliverContent(Request $request, \Session_Handler $session, \record_adapter $record, $subdef, $watermark, $stamp, Application $app)
|
||||
public function deliverContent(Request $request, \record_adapter $record, $subdef, $watermark, $stamp, Application $app)
|
||||
{
|
||||
$file = $record->get_subdef($subdef);
|
||||
|
||||
@@ -39,7 +39,7 @@ abstract class AbstractDelivery implements ControllerProviderInterface
|
||||
$log_id = null;
|
||||
try {
|
||||
$registry = $app['phraseanet.registry'];
|
||||
$logger = $session->get_logger($record->get_databox());
|
||||
$logger = $app['phraseanet.logger']($record->get_databox());
|
||||
$log_id = $logger->get_id();
|
||||
|
||||
$referrer = 'NO REFERRER';
|
||||
|
@@ -31,14 +31,12 @@ class Collection implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
if (null !== $response = $app['firewall']->requireAdmin($app)) {
|
||||
return $response;
|
||||
}
|
||||
$response = $app['firewall']->requireRightOnBase($app['request']->attributes->get('bas_id'), 'canadmin');
|
||||
|
||||
if (!$app['phraseanet.user']->ACL()->has_right_on_base($app['request']->attributes->get('bas_id'), 'canadmin')) {
|
||||
$app->abort(403);
|
||||
}
|
||||
});
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a collection
|
||||
|
@@ -28,13 +28,69 @@ class ConnectedUsers implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
|
||||
$response = $app['firewall']->requireAccessToModule('Admin');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/', function(Application $app, Request $request) {
|
||||
return new Response(
|
||||
$app['twig']->render(
|
||||
'admin/connected-users.html.twig', array('datas' => \Session_Handler::get_active_sessions($app)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
$dql = 'SELECT s FROM Entities\Session s
|
||||
LEFT JOIN s.modules m
|
||||
WHERE
|
||||
s.created > (CURRENT_TIMESTAMP() - 15 * 60)
|
||||
OR m.created > (CURRENT_TIMESTAMP() - 5 * 60)
|
||||
ORDER BY s.created DESC';
|
||||
|
||||
$query = $app['EM']->createQuery($dql);
|
||||
$sessions = $query->getResult();
|
||||
|
||||
$ret = array(
|
||||
'sessions' => $sessions,
|
||||
'applications' => array(
|
||||
'0' => 0,
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
'4' => 0,
|
||||
'5' => 0,
|
||||
'6' => 0,
|
||||
'7' => 0,
|
||||
'8' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($sessions as $session) {
|
||||
foreach ($session->getModules() as $module) {
|
||||
if (isset($ret['applications'][$module->getModuleId()])) {
|
||||
$ret['applications'][$module->getModuleId()]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $datas = $app['geonames']->find_geoname_from_ip($row['ip']);
|
||||
//
|
||||
// if ($datas['city']) {
|
||||
// $infos = $datas['city'] . ' (' . $datas['country'] . ')';
|
||||
// } elseif ($datas['fips']) {
|
||||
// $infos = $datas['fips'] . ' (' . $datas['country'] . ')';
|
||||
// } elseif ($datas['country']) {
|
||||
// $infos = $datas['country'];
|
||||
// } else {
|
||||
// $infos = '';
|
||||
// }
|
||||
//
|
||||
// $session['ip_infos'] = $infos;
|
||||
|
||||
|
||||
return new Response($app['twig']->render('admin/connected-users.html.twig', array('data' => $ret)));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
|
@@ -29,8 +29,13 @@ class Dashboard implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
return $app['firewall']->requireAdmin($app);
|
||||
});
|
||||
|
||||
$response = $app['firewall']->requireAdmin();
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get admin dashboard
|
||||
|
@@ -30,26 +30,15 @@ class Databox implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
return $app['firewall']->requireAdmin($app);
|
||||
|
||||
$response = $app['firewall']->requireAccessToModule('admin')
|
||||
->requireAccessToSbas($request->attributes->get('databox_id'));
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Create Database
|
||||
*
|
||||
* name : admin_database_new
|
||||
*
|
||||
* description : Create Database
|
||||
*
|
||||
* method : POST
|
||||
*
|
||||
* parameters : none
|
||||
*
|
||||
* return : Redirect Response
|
||||
*/
|
||||
$controllers->post('/', $this->call('createDatabase'))
|
||||
->bind('admin_database_new');
|
||||
|
||||
/**
|
||||
* Get admin database
|
||||
*
|
||||
@@ -82,23 +71,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/delete/', $this->call('deleteBase'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_delete');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
/**
|
||||
* Mount a database
|
||||
*
|
||||
* name : admin_database_mount
|
||||
*
|
||||
* description : Upgrade all databases
|
||||
*
|
||||
* method : POST
|
||||
*
|
||||
* parameters : none
|
||||
*
|
||||
* return : Redirect Response
|
||||
*/
|
||||
$controllers->post('/mount/', $this->call('databaseMount'))
|
||||
->bind('admin_database_mount');
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_delete');
|
||||
|
||||
/**
|
||||
* Unmount a database
|
||||
@@ -115,7 +94,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/unmount/', $this->call('unmountDatabase'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_unmount');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_unmount');
|
||||
|
||||
/**
|
||||
* Empty a database
|
||||
@@ -132,7 +117,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/empty/', $this->call('emptyDatabase'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_empty');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_empty');
|
||||
|
||||
/**
|
||||
* Reorder database collection
|
||||
@@ -149,7 +140,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/{databox_id}/collections/order/', $this->call('getReorder'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_display_collections_order');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_display_collections_order');
|
||||
|
||||
/**
|
||||
* Reorder database collection
|
||||
@@ -166,7 +163,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/collections/order/', $this->call('setReorder'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_submit_collections_order');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_submit_collections_order');
|
||||
|
||||
/**
|
||||
* Create new collection
|
||||
@@ -183,7 +186,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/collection/', $this->call('createCollection'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_submit_collection');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_submit_collection');
|
||||
|
||||
/**
|
||||
* Get database CGU
|
||||
@@ -200,7 +209,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/{databox_id}/cgus/', $this->call('getDatabaseCGU'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_display_cgus');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_modify_struct');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_display_cgus');
|
||||
|
||||
/**
|
||||
* Update database CGU
|
||||
@@ -217,7 +232,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/cgus/', $this->call('updateDatabaseCGU'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_submit_cgus');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_modify_struct');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_submit_cgus');
|
||||
|
||||
/**
|
||||
* Update document information
|
||||
@@ -234,7 +255,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/{databox_id}/informations/documents/', $this->call('progressBarInfos'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_display_document_information');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_display_document_information');
|
||||
|
||||
/**
|
||||
* Get document details
|
||||
@@ -251,7 +278,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/{databox_id}/informations/details/', $this->call('getDetails'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_display_document_details');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_display_document_details');
|
||||
|
||||
/**
|
||||
* Mount collection on collection
|
||||
@@ -269,7 +302,13 @@ class Databox implements ControllerProviderInterface
|
||||
$controllers->post('/{databox_id}/collection/{collection_id}/mount/', $this->call('mountCollection'))
|
||||
->assert('databox_id', '\d+')
|
||||
->assert('collection_id', '\d+')
|
||||
->bind('admin_database_mount_collection');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_mount_collection');
|
||||
|
||||
/**
|
||||
* Get a new collection form
|
||||
@@ -286,7 +325,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/{databox_id}/collection/', $this->call('getNewCollection'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_display_new_collection_form');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_display_new_collection_form');
|
||||
|
||||
/**
|
||||
* Add databox logo
|
||||
@@ -303,7 +348,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/logo/', $this->call('sendLogoPdf'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_submit_logo');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_submit_logo');
|
||||
|
||||
/**
|
||||
* Delete databox logo
|
||||
@@ -320,7 +371,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/logo/delete/', $this->call('deleteLogoPdf'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_delete_logo');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_delete_logo');
|
||||
|
||||
/**
|
||||
* Clear databox logs
|
||||
@@ -337,7 +394,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/clear-logs/', $this->call('clearLogs'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_clear_logs');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_clear_logs');
|
||||
|
||||
/**
|
||||
* Reindex database
|
||||
@@ -354,7 +417,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/reindex/', $this->call('reindex'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_reindex');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_reindex');
|
||||
|
||||
/**
|
||||
* Set database indexable
|
||||
@@ -371,7 +440,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/indexable/', $this->call('setIndexable'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_set_indexable');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_set_indexable');
|
||||
|
||||
/**
|
||||
* Set database name
|
||||
@@ -388,7 +463,13 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->post('/{databox_id}/view-name/', $this->call('changeViewName'))
|
||||
->assert('databox_id', '\d+')
|
||||
->bind('admin_database_rename');
|
||||
->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireRightOnSbas($request->attributes->get('databox_id'), 'bas_manage');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
})->bind('admin_database_rename');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
@@ -433,15 +514,10 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
public function getDatabaseCGU(Application $app, Request $request, $databox_id)
|
||||
{
|
||||
if ( ! $app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
|
||||
$app->abort(403);
|
||||
}
|
||||
|
||||
|
||||
return new Response($app['twig']->render('admin/databox/cgus.html.twig', array(
|
||||
'languages' => $app->getAvailableLanguages(),
|
||||
'cgus' => $app['phraseanet.appbox']->get_databox($databox_id)->get_cgus(),
|
||||
'current_locale' => \Session_Handler::get_locale()
|
||||
'current_locale' => $app['locale']
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -529,7 +605,7 @@ class Databox implements ControllerProviderInterface
|
||||
$success = false;
|
||||
|
||||
try {
|
||||
$app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), ! ! $request->request->get('indexable', false));
|
||||
$app['phraseanet.appbox']->set_databox_indexable($app['phraseanet.appbox']->get_databox($databox_id), !!$request->request->get('indexable', false));
|
||||
$success = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -557,15 +633,11 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
public function updateDatabaseCGU(Application $app, Request $request, $databox_id)
|
||||
{
|
||||
if ( ! $app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
|
||||
$app->abort(403);
|
||||
}
|
||||
|
||||
$databox = $app['phraseanet.appbox']->get_databox($databox_id);
|
||||
|
||||
try {
|
||||
foreach ($request->request->get('TOU', array()) as $loc => $terms) {
|
||||
$databox->update_cgus($loc, $terms, ! ! $request->request->get('valid', false));
|
||||
$databox->update_cgus($loc, $terms, !!$request->request->get('valid', false));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -575,154 +647,6 @@ class Databox implements ControllerProviderInterface
|
||||
return $app->redirect('/admin/databox/' . $databox_id . '/cgus/?success=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new databox
|
||||
*
|
||||
* @param Application $app The silex application
|
||||
* @param Request $request The current HTTP request
|
||||
* @param integer $databox_id The requested databox
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function createDatabase(Application $app, Request $request)
|
||||
{
|
||||
if ('' === $dbName = $request->request->get('new_dbname', '')) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?error=no-empty');
|
||||
}
|
||||
|
||||
if (\p4string::hasAccent($dbName)) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?error=special-chars');
|
||||
}
|
||||
|
||||
$registry = $app['phraseanet.registry'];
|
||||
|
||||
if ((null === $request->request->get('new_settings')) && (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
||||
|
||||
$configuration = $app['phraseanet.configuration'];
|
||||
$choosenConnexion = $configuration->getPhraseanet()->get('database');
|
||||
$connexion = $configuration->getConnexion($choosenConnexion);
|
||||
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
|
||||
$dataTemplate = new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||
|
||||
try {
|
||||
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $user, $password, $dbName, array(), $registry);
|
||||
} catch (\PDOException $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=database-failed');
|
||||
}
|
||||
|
||||
try {
|
||||
$base = \databox::create($app, $connbas, $dataTemplate, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$app['phraseanet.user']->ACL()->delete_data_from_cache();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=base-failed');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
null !== $request->request->get('new_settings')
|
||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||
&& (null !== $port = $request->request->get('new_port'))
|
||||
&& (null !== $userDb = $request->request->get('new_user'))
|
||||
&& (null !== $passwordDb = $request->request->get('new_password'))
|
||||
&& (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
||||
|
||||
try {
|
||||
$data_template = new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $userDb, $passwordDb, $dbName, array(), $registry);
|
||||
try {
|
||||
$base = \databox::create($app, $connbas, $data_template, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=base-failed');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=database-failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mount a databox
|
||||
*
|
||||
* @param Application $app The silex application
|
||||
* @param Request $request The current HTTP request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function databaseMount(Application $app, Request $request)
|
||||
{
|
||||
if ('' === $dbName = trim($request->request->get('new_dbname', ''))) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=no-empty');
|
||||
}
|
||||
|
||||
if (\p4string::hasAccent($dbName)) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=special-chars');
|
||||
}
|
||||
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
$registry = $app['phraseanet.registry'];
|
||||
|
||||
if ((null === $request->request->get('new_settings'))) {
|
||||
try {
|
||||
$configuration = $app['phraseanet.configuration'];
|
||||
$connexion = $configuration->getConnexion();
|
||||
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$base = \databox::mount($app, $hostname, $port, $user, $password, $dbName, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=mount-failed');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
null !== $request->request->get('new_settings')
|
||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||
&& (null !== $port = $request->request->get('new_port'))
|
||||
&& (null !== $userDb = $request->request->get('new_user'))
|
||||
&& (null !== $passwordDb = $request->request->get('new_password'))) {
|
||||
|
||||
try {
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$base = \databox::mount($app, $hostname, $port, $userDb, $passwordDb, $dbName, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=mount-failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mount a collection on a databox
|
||||
*
|
||||
@@ -736,10 +660,6 @@ class Databox implements ControllerProviderInterface
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
$user = $app['phraseanet.user'];
|
||||
|
||||
if ( ! $user->ACL()->has_right_on_sbas($databox_id, 'bas_manage')) {
|
||||
$app->abort(403);
|
||||
}
|
||||
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
try {
|
||||
$baseId = \collection::mount_collection($app, $app['phraseanet.appbox']->get_databox($databox_id), $collection_id, $user);
|
||||
@@ -988,7 +908,7 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
public function progressBarInfos(Application $app, Request $request, $databox_id)
|
||||
{
|
||||
if ( ! $app['request']->isXmlHttpRequest() || 'json' !== $app['request']->getRequestFormat()) {
|
||||
if (!$app['request']->isXmlHttpRequest() || 'json' !== $app['request']->getRequestFormat()) {
|
||||
$app->abort(400, _('Bad request format, only JSON is allowed'));
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,13 @@ class Databoxes implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
return $app['firewall']->requireAdmin($app);
|
||||
});
|
||||
$response = $app['firewall']->requireAdmin();
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Get Databases control panel
|
||||
@@ -50,6 +55,38 @@ class Databoxes implements ControllerProviderInterface
|
||||
->bind('admin_databases');
|
||||
|
||||
|
||||
/**
|
||||
* Create Database
|
||||
*
|
||||
* name : admin_database_new
|
||||
*
|
||||
* description : Create Database
|
||||
*
|
||||
* method : POST
|
||||
*
|
||||
* parameters : none
|
||||
*
|
||||
* return : Redirect Response
|
||||
*/
|
||||
$controllers->post('/', $this->call('createDatabase'))
|
||||
->bind('admin_database_new');
|
||||
|
||||
/**
|
||||
* Mount a database
|
||||
*
|
||||
* name : admin_database_mount
|
||||
*
|
||||
* description : Upgrade all databases
|
||||
*
|
||||
* method : POST
|
||||
*
|
||||
* parameters : none
|
||||
*
|
||||
* return : Redirect Response
|
||||
*/
|
||||
$controllers->post('/mount/', $this->call('databaseMount'))
|
||||
->bind('admin_database_mount');
|
||||
|
||||
/**
|
||||
* Upgrade all databases
|
||||
*
|
||||
@@ -159,6 +196,154 @@ class Databoxes implements ControllerProviderInterface
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new databox
|
||||
*
|
||||
* @param Application $app The silex application
|
||||
* @param Request $request The current HTTP request
|
||||
* @param integer $databox_id The requested databox
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function createDatabase(Application $app, Request $request)
|
||||
{
|
||||
if ('' === $dbName = $request->request->get('new_dbname', '')) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?error=no-empty');
|
||||
}
|
||||
|
||||
if (\p4string::hasAccent($dbName)) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?error=special-chars');
|
||||
}
|
||||
|
||||
$registry = $app['phraseanet.registry'];
|
||||
|
||||
if ((null === $request->request->get('new_settings')) && (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
||||
|
||||
$configuration = $app['phraseanet.configuration'];
|
||||
$choosenConnexion = $configuration->getPhraseanet()->get('database');
|
||||
$connexion = $configuration->getConnexion($choosenConnexion);
|
||||
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
|
||||
$dataTemplate = new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||
|
||||
try {
|
||||
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $user, $password, $dbName, array(), $registry);
|
||||
} catch (\PDOException $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=database-failed');
|
||||
}
|
||||
|
||||
try {
|
||||
$base = \databox::create($app, $connbas, $dataTemplate, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$app['phraseanet.user']->ACL()->delete_data_from_cache();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=base-failed');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
null !== $request->request->get('new_settings')
|
||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||
&& (null !== $port = $request->request->get('new_port'))
|
||||
&& (null !== $userDb = $request->request->get('new_user'))
|
||||
&& (null !== $passwordDb = $request->request->get('new_password'))
|
||||
&& (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
||||
|
||||
try {
|
||||
$data_template = new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $userDb, $passwordDb, $dbName, array(), $registry);
|
||||
try {
|
||||
$base = \databox::create($app, $connbas, $data_template, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=base-failed');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=database-failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mount a databox
|
||||
*
|
||||
* @param Application $app The silex application
|
||||
* @param Request $request The current HTTP request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function databaseMount(Application $app, Request $request)
|
||||
{
|
||||
if ('' === $dbName = trim($request->request->get('new_dbname', ''))) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=no-empty');
|
||||
}
|
||||
|
||||
if (\p4string::hasAccent($dbName)) {
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=special-chars');
|
||||
}
|
||||
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
$registry = $app['phraseanet.registry'];
|
||||
|
||||
if ((null === $request->request->get('new_settings'))) {
|
||||
try {
|
||||
$configuration = $app['phraseanet.configuration'];
|
||||
$connexion = $configuration->getConnexion();
|
||||
|
||||
$hostname = $connexion->get('host');
|
||||
$port = $connexion->get('port');
|
||||
$user = $connexion->get('user');
|
||||
$password = $connexion->get('password');
|
||||
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$base = \databox::mount($app, $hostname, $port, $user, $password, $dbName, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=mount-failed');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
null !== $request->request->get('new_settings')
|
||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||
&& (null !== $port = $request->request->get('new_port'))
|
||||
&& (null !== $userDb = $request->request->get('new_user'))
|
||||
&& (null !== $passwordDb = $request->request->get('new_password'))) {
|
||||
|
||||
try {
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$base = \databox::mount($app, $hostname, $port, $userDb, $passwordDb, $dbName, $registry);
|
||||
$base->registerAdmin($app['phraseanet.user']);
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
|
||||
} catch (\Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return $app->redirect('/admin/databoxes/?success=0&error=mount-failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade all databases
|
||||
*
|
||||
|
@@ -40,10 +40,8 @@ class Publications implements ControllerProviderInterface
|
||||
|
||||
$controllers->post('/create/', function(PhraseaApplication $app, Request $request) {
|
||||
|
||||
$user = $app['phraseanet.user'];
|
||||
|
||||
$feed = \Feed_Adapter::create(
|
||||
$app, $user, $request->request->get('title'), $request->request->get('subtitle')
|
||||
$app, $app['phraseanet.user'], $request->request->get('title'), $request->request->get('subtitle')
|
||||
);
|
||||
|
||||
if ($request->request->get('public') == '1') {
|
||||
|
@@ -28,8 +28,18 @@ class Root implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->get('/', function(Application $app, Request $request) {
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
|
||||
$response = $app['firewall']->requireAccessToModule('admin');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
$controllers->get('/', function(Application $app, Request $request) {
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
$user = $app['phraseanet.user'];
|
||||
|
||||
|
@@ -37,8 +37,12 @@ class Setup implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
return $app['firewall']->requireAdmin($app);
|
||||
});
|
||||
$response = $app['firewall']->requireAdmin();
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get globals values
|
||||
|
@@ -30,8 +30,12 @@ class Sphinx implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
return $app['firewall']->requireAdmin($app);
|
||||
});
|
||||
$response = $app['firewall']->requireAdmin();
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Sphinx configuration
|
||||
|
@@ -288,7 +288,6 @@ class Users implements ControllerProviderInterface
|
||||
->on_sbas_ids($on_sbas);
|
||||
|
||||
$offset = 0;
|
||||
$geoname = new \geonames();
|
||||
$buffer = array();
|
||||
|
||||
$buffer[] = array(
|
||||
@@ -322,12 +321,12 @@ class Users implements ControllerProviderInterface
|
||||
, $user->get_lastname()
|
||||
, $user->get_firstname()
|
||||
, $user->get_email()
|
||||
, \phraseadate::format_mysql($user->get_creation_date())
|
||||
, \phraseadate::format_mysql($user->get_modification_date())
|
||||
, $app['date-formatter']->format_mysql($user->get_creation_date())
|
||||
, $app['date-formatter']->format_mysql($user->get_modification_date())
|
||||
, $user->get_address()
|
||||
, $user->get_city()
|
||||
, $user->get_zipcode()
|
||||
, $geoname->get_country($user->get_geonameid(), $app)
|
||||
, $app['geonames']->get_country($user->get_geonameid())
|
||||
, $user->get_tel()
|
||||
, $user->get_fax()
|
||||
, $user->get_job()
|
||||
|
@@ -33,7 +33,7 @@ class Datafiles extends AbstractDelivery
|
||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||
$record = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$app['phraseanet.session']->is_authenticated()) {
|
||||
if (!$app->isAuthenticated()) {
|
||||
throw new \Exception_Session_NotAuthenticated();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class Datafiles extends AbstractDelivery
|
||||
}
|
||||
}
|
||||
|
||||
return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app);
|
||||
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
|
@@ -61,7 +61,7 @@ class Permalink extends AbstractDelivery
|
||||
|
||||
$watermark = $stamp = false;
|
||||
|
||||
if ($app['phraseanet.session']->is_authenticated()) {
|
||||
if ($app->isAuthenticated()) {
|
||||
$user = \User_Adapter::getInstance($app['phraseanet.user']->get_id(), $app);
|
||||
|
||||
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
|
||||
@@ -77,7 +77,7 @@ class Permalink extends AbstractDelivery
|
||||
}
|
||||
}
|
||||
|
||||
return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app);
|
||||
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
|
||||
} else {
|
||||
$collection = \collection::get_from_base_id($app, $record->get_base_id());
|
||||
switch ($collection->get_pub_wm()) {
|
||||
@@ -94,7 +94,7 @@ class Permalink extends AbstractDelivery
|
||||
}
|
||||
}
|
||||
|
||||
return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app);
|
||||
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
|
||||
}
|
||||
)
|
||||
->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
@@ -31,6 +31,14 @@ class Basket implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a basket
|
||||
*/
|
||||
|
@@ -11,13 +11,11 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Controller\Prod;
|
||||
|
||||
use Alchemy\Phrasea\Helper\Record as RecordHelper;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Alchemy\Phrasea\Helper\Record as RecordHelper;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -31,14 +29,25 @@ class Bridge implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
|
||||
$response = $app['firewall']
|
||||
->requireNotGuest()
|
||||
->requireRight('bas_chupub');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$app['require_connection'] = $app->protect(function(\Bridge_Account $account) use ($app) {
|
||||
$app['current_account'] = function() use ($account) {
|
||||
return $account;
|
||||
};
|
||||
|
||||
if ( ! $account->get_api()->get_connector()->is_configured())
|
||||
if (!$account->get_api()->get_connector()->is_configured())
|
||||
throw new \Bridge_Exception_ApiConnectorNotConfigured("Bridge API Connector is not configured");
|
||||
if ( ! $account->get_api()->get_connector()->is_connected())
|
||||
if (!$account->get_api()->get_connector()->is_connected())
|
||||
throw new \Bridge_Exception_ApiConnectorNotConnected("Bridge API Connector is not connected");
|
||||
|
||||
return;
|
||||
@@ -420,57 +429,6 @@ class Bridge implements ControllerProviderInterface
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements())));
|
||||
});
|
||||
//
|
||||
// $app->error(function(\Exception $e, $code) use ($app) {
|
||||
//
|
||||
// $request = $app['request'];
|
||||
//
|
||||
// if ($e instanceof \Bridge_Exception) {
|
||||
//
|
||||
// $params = array(
|
||||
// 'message' => $e->getMessage()
|
||||
// , 'file' => $e->getFile()
|
||||
// , 'line' => $e->getLine()
|
||||
// , 'r_method' => $request->getMethod()
|
||||
// , 'r_action' => $request->getRequestUri()
|
||||
// , 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
|
||||
// );
|
||||
//
|
||||
// if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
|
||||
// $params = array_merge($params, array('account' => $app['current_account']));
|
||||
//
|
||||
// $response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200);
|
||||
// } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
|
||||
// $params = array_merge($params, array('account' => $app['current_account']));
|
||||
//
|
||||
// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
|
||||
// } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
|
||||
// $params = array_merge($params, array('account' => $app['current_account']));
|
||||
//
|
||||
// $response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200);
|
||||
// } elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
|
||||
// $params = array_merge($params, array('api' => $e->get_api()));
|
||||
//
|
||||
// $response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200);
|
||||
// } else {
|
||||
// $response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200);
|
||||
// }
|
||||
//
|
||||
// $response->headers->set('Phrasea-StatusCode', 200);
|
||||
//
|
||||
// return $response;
|
||||
// }
|
||||
// });
|
||||
|
||||
// /**
|
||||
// * Temporary fix for https://github.com/fabpot/Silex/issues/438
|
||||
// */
|
||||
// $app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){
|
||||
// if ($event->getResponse()->headers->has('Phrasea-StatusCode')) {
|
||||
// $event->getResponse()->setStatusCode($event->getResponse()->headers->get('Phrasea-StatusCode'));
|
||||
// $event->getResponse()->headers->remove('Phrasea-StatusCode');
|
||||
// }
|
||||
// });
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
@@ -30,6 +30,17 @@ class Edit implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
|
||||
$response = $app['firewall']
|
||||
->requireNotGuest()
|
||||
->requireRight('modifyrecord');
|
||||
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->post('/', function(Application $app, Request $request) {
|
||||
|
||||
$records = RecordsRequest::fromRequest($app, $request, true, array('canmodifrecord'));
|
||||
@@ -386,13 +397,11 @@ class Edit implements ControllerProviderInterface
|
||||
->write_metas();
|
||||
|
||||
if ($statbits != '') {
|
||||
$app['phraseanet.session']
|
||||
->get_logger($record->get_databox())
|
||||
$app['phraseanet.logger']($record->get_databox())
|
||||
->log($record, \Session_Logger::EVENT_STATUS, '', '');
|
||||
}
|
||||
if ($editDirty) {
|
||||
$app['phraseanet.session']
|
||||
->get_logger($record->get_databox())
|
||||
$app['phraseanet.logger']($record->get_databox())
|
||||
->log($record, \Session_Logger::EVENT_EDIT, '', '');
|
||||
}
|
||||
}
|
||||
|
@@ -41,12 +41,10 @@ class Printer implements ControllerProviderInterface
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$session = $app['phraseanet.session'];
|
||||
|
||||
$layout = $request->request->get('lay');
|
||||
|
||||
foreach ($printer->get_elements() as $record) {
|
||||
$session->get_logger($record->get_databox())
|
||||
$app['phraseanet.logger']($record->get_databox())
|
||||
->log($record, \Session_Logger::EVENT_PRINT, $layout, '');
|
||||
}
|
||||
$PDF = new PDFExport($app, $printer->get_elements(), $layout);
|
||||
|
@@ -237,8 +237,7 @@ class Push implements ControllerProviderInterface
|
||||
$events_manager->trigger('__PUSH_DATAS__', $params);
|
||||
}
|
||||
|
||||
$app['phraseanet.session']
|
||||
->get_logger($BasketElement->getRecord($app)->get_databox())
|
||||
$app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())
|
||||
->log($BasketElement->getRecord($app), \Session_Logger::EVENT_VALIDATE, $user_receiver->get_id(), '');
|
||||
|
||||
$app['EM']->flush();
|
||||
@@ -413,8 +412,7 @@ class Push implements ControllerProviderInterface
|
||||
$app['EM']->merge($BasketElement);
|
||||
$app['EM']->persist($ValidationData);
|
||||
|
||||
$app['phraseanet.session']
|
||||
->get_logger($BasketElement->getRecord($app)->get_databox())
|
||||
$app['phraseanet.logger']($BasketElement->getRecord($app)->get_databox())
|
||||
->log($BasketElement->getRecord($app), \Session_Logger::EVENT_PUSH, $participant_user->get_id(), '');
|
||||
|
||||
$Participant->addValidationData($ValidationData);
|
||||
|
@@ -27,6 +27,14 @@ class Query implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->post('/', function(Application $app, Request $request) {
|
||||
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
@@ -165,7 +173,7 @@ class Query implements ControllerProviderInterface
|
||||
$prop = null;
|
||||
|
||||
if ($search_engine->is_first_page()) {
|
||||
$propals = $result->get_suggestions($app['phraseanet.session']->get_I18n());
|
||||
$propals = $result->get_suggestions($app['locale.I18n']);
|
||||
if (count($propals) > 0) {
|
||||
foreach ($propals as $prop_array) {
|
||||
if ($prop_array['value'] !== $query && $prop_array['hits'] > $result->get_count_total_results()) {
|
||||
|
@@ -30,6 +30,14 @@ class Root implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->get('/', function(Application $app) {
|
||||
|
||||
\User_Adapter::updateClientInfos($app, 1);
|
||||
@@ -59,7 +67,7 @@ class Root implements ControllerProviderInterface
|
||||
|
||||
$cssfile = $user->getPrefs('css');
|
||||
|
||||
if ( ! $cssfile && isset($css['000000'])) {
|
||||
if (!$cssfile && isset($css['000000'])) {
|
||||
$cssfile = '000000';
|
||||
}
|
||||
|
||||
@@ -71,9 +79,9 @@ class Root implements ControllerProviderInterface
|
||||
$queries_topics = '';
|
||||
|
||||
if ($registry->get('GV_client_render_topics') == 'popups') {
|
||||
$queries_topics = \queries::dropdown_topics($app['phraseanet.session']->get_I18n());
|
||||
$queries_topics = \queries::dropdown_topics($app['locale.I18n']);
|
||||
} elseif ($registry->get('GV_client_render_topics') == 'tree') {
|
||||
$queries_topics = \queries::tree_topics($app['phraseanet.session']->get_I18n());
|
||||
$queries_topics = \queries::tree_topics($app['locale.I18n']);
|
||||
}
|
||||
|
||||
$sbas = $bas2sbas = array();
|
||||
@@ -125,12 +133,12 @@ class Root implements ControllerProviderInterface
|
||||
$download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story'));
|
||||
|
||||
return $app['twig']->render('common/dialog_export.html.twig', array(
|
||||
'download' => $download,
|
||||
'ssttid' => (int) $request->request->get('ssel'),
|
||||
'lst' => $download->serialize_list(),
|
||||
'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'),
|
||||
'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title')
|
||||
));
|
||||
'download' => $download,
|
||||
'ssttid' => (int) $request->request->get('ssel'),
|
||||
'lst' => $download->serialize_list(),
|
||||
'default_export_title' => $app['phraseanet.registry']->get('GV_default_export_title'),
|
||||
'choose_export_title' => $app['phraseanet.registry']->get('GV_choose_export_title')
|
||||
));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
|
@@ -32,7 +32,6 @@ class TOU implements ControllerProviderInterface
|
||||
|
||||
try {
|
||||
$user = $app['phraseanet.user'];
|
||||
$session = $app['phraseanet.session'];
|
||||
|
||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||
|
||||
@@ -41,7 +40,7 @@ class TOU implements ControllerProviderInterface
|
||||
);
|
||||
$user->ACL()->revoke_unused_sbas_rights();
|
||||
|
||||
$session->logout();
|
||||
$app->closeAccount();
|
||||
|
||||
$ret = array('success' => true, 'message' => '');
|
||||
} catch (\Exception $e) {
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Controller\Prod;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
|
||||
@@ -26,6 +27,14 @@ class Tooltip implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->post('/basket/{basket_id}/', $this->call('displayBasket'))
|
||||
->assert('basket_id', '\d+');
|
||||
|
||||
|
@@ -27,6 +27,14 @@ class UserPreferences implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->post('/save/', $this->call('savePreference'));
|
||||
|
||||
return $controllers;
|
||||
|
@@ -29,6 +29,14 @@ class WorkZone implements ControllerProviderInterface
|
||||
{
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
$controllers->get('/', $this->call('displayWorkzone'));
|
||||
|
||||
$controllers->get('/Browse/', $this->call('browse'));
|
||||
|
@@ -31,8 +31,12 @@ class Account implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function() use ($app) {
|
||||
return $app['firewall']->requireAuthentication($app);
|
||||
});
|
||||
$response = $app['firewall']->requireAuthentication();
|
||||
|
||||
if($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a new account
|
||||
@@ -449,7 +453,7 @@ class Account implements ControllerProviderInterface
|
||||
public function accountAuthorizedApps(Application $app, Request $request)
|
||||
{
|
||||
return $app['twig']->render('account/authorized_apps.html.twig', array(
|
||||
"apps" => \API_OAuth2_Application::load_app_by_user($app, $app['phraseanet.user']),
|
||||
"applications" => \API_OAuth2_Application::load_app_by_user($app, $app['phraseanet.user']),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -462,7 +466,46 @@ class Account implements ControllerProviderInterface
|
||||
*/
|
||||
public function accountSessionsAccess(Application $app, Request $request)
|
||||
{
|
||||
return new Response($app['twig']->render('account/sessions.html.twig'));
|
||||
|
||||
$dql = 'SELECT s FROM Entities\Session s
|
||||
WHERE s.usr_id = :usr_id
|
||||
ORDER BY s.created DESC';
|
||||
|
||||
$query = $app['EM']->createQuery($dql);
|
||||
$query->setParameters(array('usr_id'=>$app['session']->get('usr_id')));
|
||||
$sessions = $query->getResult();
|
||||
|
||||
// $sql = 'SELECT session_id, lastaccess, ip, platform, browser, screen
|
||||
// , created_on, browser_version, token
|
||||
// FROM cache WHERE usr_id = :usr_id';
|
||||
//
|
||||
//
|
||||
// $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
// $stmt->execute(array(':usr_id' => $this->get_usr_id()));
|
||||
// $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
// $stmt->closeCursor();
|
||||
//
|
||||
// $geonames = new geonames();
|
||||
//
|
||||
// foreach ($rs as $k => $row) {
|
||||
// $datas = $geonames->find_geoname_from_ip($row['ip'], $this->app);
|
||||
//
|
||||
// if ($datas['city']) {
|
||||
// $infos = $datas['city'] . ' (' . $datas['country'] . ')';
|
||||
// } elseif ($datas['fips']) {
|
||||
// $infos = $datas['fips'] . ' (' . $datas['country'] . ')';
|
||||
// } elseif ($datas['country']) {
|
||||
// $infos = $datas['country'];
|
||||
// } else {
|
||||
// $infos = '';
|
||||
// }
|
||||
// $rs[$k]['session_id'] = (int) $rs[$k]['session_id'];
|
||||
// $rs[$k]['ip_infos'] = $infos;
|
||||
// $rs[$k]['created_on'] = new \DateTime($row['created_on']);;
|
||||
// $rs[$k]['lastaccess'] = new \DateTime($row['lastaccess']);
|
||||
// }
|
||||
|
||||
return new Response($app['twig']->render('account/sessions.html.twig', array('sessions'=>$sessions)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,7 +540,6 @@ class Account implements ControllerProviderInterface
|
||||
}
|
||||
|
||||
return new Response($app['twig']->render('account/account.html.twig', array(
|
||||
'geonames' => new \geonames(),
|
||||
'user' => $user,
|
||||
'notice' => $notice,
|
||||
'evt_mngr' => $evtMngr,
|
||||
|
@@ -341,7 +341,7 @@ class Developers implements ControllerProviderInterface
|
||||
public function listApps(Application $app, Request $request)
|
||||
{
|
||||
return $app['twig']->render('developers/applications.html.twig', array(
|
||||
"apps" => \API_OAuth2_Application::load_dev_app_by_user(
|
||||
"applications" => \API_OAuth2_Application::load_dev_app_by_user(
|
||||
$app, $app['phraseanet.user']
|
||||
)));
|
||||
}
|
||||
@@ -383,7 +383,7 @@ class Developers implements ControllerProviderInterface
|
||||
$token = $client->get_user_account($user)->get_token()->get_value();
|
||||
|
||||
return $app['twig']->render('developers/application.html.twig', array(
|
||||
"app" => $client,
|
||||
"application" => $client,
|
||||
"user" => $user,
|
||||
"token" => $token
|
||||
));
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Controller\Root;
|
||||
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -30,10 +31,12 @@ class Login implements ControllerProviderInterface
|
||||
$controllers = $app['controllers_factory'];
|
||||
|
||||
$controllers->before(function(Request $request) use ($app) {
|
||||
if ($app['phraseanet.registry']->get('GV_maintenance')) {
|
||||
return $app->redirect("/login/?redirect=" . $request->request->get('redirect') . "&error=maintenance");
|
||||
}
|
||||
});
|
||||
if ($app['phraseanet.registry']->get('GV_maintenance')) {
|
||||
return $app->redirect("/login/?redirect=" . $request->request->get('redirect') . "&error=maintenance");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Login
|
||||
@@ -50,21 +53,20 @@ class Login implements ControllerProviderInterface
|
||||
*/
|
||||
$controllers->get('/', $this->call('login'))
|
||||
->before(function(Request $request) use ($app) {
|
||||
if ($app->isAuthenticated()) {
|
||||
return $app->redirect('/' . $request->query->get('redirect', 'prod') . '/');
|
||||
}
|
||||
|
||||
if (null !== $request->query->get('postlog')) {
|
||||
|
||||
// if isset postlog parameter, set cookie and log out current user
|
||||
// then post login operation like getting baskets from an invit session
|
||||
// could be done by Session_handler authentication process
|
||||
|
||||
$app['phraseanet.session']->set_postlog();
|
||||
$response = new RedirectResponse("/login/logout/?redirect=" . $request->query->get('redirect', 'prod'));
|
||||
$response->headers->setCookie(new \Symfony\Component\HttpFoundation\Cookie('postlog', 1));
|
||||
|
||||
return $app->redirect("/login/logout/?redirect=" . $request->query->get('redirect', 'prod'));
|
||||
}
|
||||
|
||||
|
||||
if ($app->isAuthenticated()) {
|
||||
|
||||
return $app->redirect('/' . $request->query->get('redirect', 'prod') . '/');
|
||||
return $response;
|
||||
}
|
||||
})
|
||||
->bind('homepage');
|
||||
@@ -83,11 +85,6 @@ class Login implements ControllerProviderInterface
|
||||
* return : HTML Response
|
||||
*/
|
||||
$controllers->post('/authenticate/', $this->call('authenticate'))
|
||||
->before(function() use ($app) {
|
||||
if ($app->isAuthenticated()) {
|
||||
return $app->redirect('/prod/');
|
||||
}
|
||||
})
|
||||
->bind('login_authenticate');
|
||||
|
||||
/**
|
||||
@@ -483,9 +480,8 @@ class Login implements ControllerProviderInterface
|
||||
'parms' => $request->query->all(),
|
||||
'needed' => $needed,
|
||||
'arrayVerif' => $arrayVerif,
|
||||
'geonames' => new \geonames(),
|
||||
'demandes' => $request->query->get('demand', array()),
|
||||
'lng' => \Session_Handler::get_locale()
|
||||
'lng' => $app['locale']
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -655,20 +651,25 @@ class Login implements ControllerProviderInterface
|
||||
* @param Request $request The current request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function logout(Application $app, Request $request)
|
||||
public function logout(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
$appRedirect = $request->query->get("app");
|
||||
|
||||
try {
|
||||
$session = $app['phraseanet.session'];
|
||||
/**
|
||||
* Move to middleware
|
||||
if ( ! $this->is_authenticated()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
$app->closeAccount();
|
||||
|
||||
$session->logout();
|
||||
$session->remove_cookies();
|
||||
} catch (\Exception $e) {
|
||||
return $app->redirect("/" . ($appRedirect ? $appRedirect : 'prod'));
|
||||
}
|
||||
$response = new RedirectResponse("/login/?logged_out=user" . ($appRedirect ? sprintf("&redirect=/%s", $appRedirect) : ""));
|
||||
|
||||
return $app->redirect("/login/?logged_out=user" . ($appRedirect ? sprintf("&redirect=/%s", $appRedirect) : ""));
|
||||
$response->headers->removeCookie('persistent');
|
||||
$response->headers->removeCookie('last_act');
|
||||
$response->headers->removeCookie('postlog');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -795,7 +796,7 @@ class Login implements ControllerProviderInterface
|
||||
public function authenticate(Application $app, Request $request)
|
||||
{
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
$session = $app['phraseanet.session'];
|
||||
$conn = $appbox->get_connection();
|
||||
$registry = $app['phraseanet.registry'];
|
||||
|
||||
$is_guest = false;
|
||||
@@ -810,8 +811,6 @@ class Login implements ControllerProviderInterface
|
||||
* @todo dispatch an event that can be used to tweak the authentication
|
||||
* (LDAP....)
|
||||
*/
|
||||
// $app['dispatcher']->dispatch();
|
||||
|
||||
try {
|
||||
if ($is_guest) {
|
||||
$auth = new \Session_Authentication_Guest($app);
|
||||
@@ -837,7 +836,132 @@ class Login implements ControllerProviderInterface
|
||||
$auth->set_captcha_challenge($captcha);
|
||||
}
|
||||
|
||||
$session->authenticate($auth);
|
||||
|
||||
$sql = "SELECT session_id FROM cache
|
||||
WHERE (lastaccess < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND token IS NOT NULL)
|
||||
OR (lastaccess < DATE_SUB(NOW(), INTERVAL 30 MINUTE) AND token IS NULL)";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
phrasea_close_session($row['session_id']);
|
||||
}
|
||||
|
||||
$date = new \DateTime('+' . (int) $app['phraseanet.registry']->get('GV_validation_reminder') . ' days');
|
||||
|
||||
foreach ($app['EM']
|
||||
->getRepository('\Entities\ValidationParticipant')
|
||||
->findNotConfirmedAndNotRemindedParticipantsByExpireDate($date) as $participant) {
|
||||
|
||||
/* @var $participant \Entities\ValidationParticipant */
|
||||
|
||||
$validationSession = $participant->getSession();
|
||||
$participantId = $participant->getUsrId();
|
||||
$basketId = $validationSession->getBasket()->getId();
|
||||
|
||||
try {
|
||||
$token = \random::getValidationToken($this->app, $participantId, $basketId);
|
||||
} catch (\Exception_NotFound $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$app['events-manager']->trigger('__VALIDATION_REMINDER__', array(
|
||||
'to' => $participantId,
|
||||
'ssel_id' => $basketId,
|
||||
'from' => $validationSession->getInitiatorId(),
|
||||
'validate_id' => $validationSession->getId(),
|
||||
'url' => $app['phraseanet.registry']->get('GV_ServerName') . 'lightbox/validate/' . $basketId . '/?LOG=' . $token
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* IMPORTANT
|
||||
*/
|
||||
$auth->prelog();
|
||||
|
||||
if ($app->isAuthenticated() && $app['session']->get('usr_id') == $auth->get_user()->get_id()) {
|
||||
return $app->redirect('/' . $request->request->get('redirect', 'prod'));
|
||||
}
|
||||
|
||||
$user = $auth->signOn();
|
||||
|
||||
|
||||
/**
|
||||
* TODO NEUTRON save user locale
|
||||
*/
|
||||
/**
|
||||
* TODO NEUTRON move this to phrasea
|
||||
*/
|
||||
$user->ACL()->inject_rights();
|
||||
|
||||
if ($request->cookies->has('postlog') && $request->cookies->get('postlog') == '1') {
|
||||
if (!$user->is_guest() && $request->cookies->has('invite-usr_id')) {
|
||||
if ($user->get_id() != $inviteUsrId = $request->cookies->get('invite-usr_id')) {
|
||||
|
||||
$repo = $app['EM']->getRepository('Entities\Basket');
|
||||
$baskets = $repo->findBy(array('usr_id' => $inviteUsrId));
|
||||
|
||||
foreach ($baskets as $basket) {
|
||||
$basket->setUsrId($user->get_id());
|
||||
$app['EM']->persist($basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$app->openAccount($auth);
|
||||
|
||||
/**
|
||||
* IMPORTANT
|
||||
*/
|
||||
$auth->postlog();
|
||||
|
||||
if ($app['browser']->isMobile()) {
|
||||
$response = new RedirectResponse("/lightbox/");
|
||||
} elseif ($request->request->get('redirect')) {
|
||||
$response = new RedirectResponse('/' . $request->request->get('redirect'));
|
||||
} elseif (true !== $app['browser']->isNewGeneration()) {
|
||||
$response = new RedirectResponse('/client/');
|
||||
} else {
|
||||
$response = new RedirectResponse('/prod/');
|
||||
}
|
||||
|
||||
$response->headers->removeCookie('postlog');
|
||||
|
||||
$session = $app['EM']->find('Entities\Session', $app['session']->get('session_id'));
|
||||
|
||||
if ($request->request->get('remember-me') == '1') {
|
||||
$nonce = \random::generatePassword(16);
|
||||
$string = $app['browser']->getBrowser() . '_' . $app['browser']->getPlatform();
|
||||
|
||||
$token = \User_Adapter::salt_password($app, $string, $nonce);
|
||||
|
||||
$session->setToken($token)
|
||||
->setNonce($nonce);
|
||||
$cookie = new Cookie('persistent', $token);
|
||||
$response->headers->setCookie($cookie);
|
||||
}
|
||||
|
||||
$width = $height = null;
|
||||
if ($app['request']->cookies->has('screen')) {
|
||||
$data = explode('x', $this['request']->cookies->get('screen'));
|
||||
$width = $data[0];
|
||||
$height = $data[1];
|
||||
}
|
||||
$session->setIpAddress($request->getClientIp())
|
||||
->setScreenHeight($height)
|
||||
->setScreenWidth($width);
|
||||
|
||||
$app['EM']->persist($session);
|
||||
$app['EM']->flush();
|
||||
|
||||
$response->headers->removeCookie('last_act');
|
||||
|
||||
return $response;
|
||||
} catch (\Exception_Session_StorageClosed $e) {
|
||||
return $app->redirect("/login/?redirect=" . $request->request->get('redirect') . "&error=session");
|
||||
} catch (\Exception_Session_RequireCaptcha $e) {
|
||||
@@ -861,16 +985,6 @@ class Login implements ControllerProviderInterface
|
||||
} catch (\Exception $e) {
|
||||
return $app->redirect("/login/?redirect=" . $request->request->get('redirect') . "&error=" . _('An error occured'));
|
||||
}
|
||||
|
||||
if ($app['browser']->isMobile()) {
|
||||
return $app->redirect("/lightbox/");
|
||||
} elseif ($request->request->get('redirect')) {
|
||||
return $app->redirect($request->request->get('redirect'));
|
||||
} elseif (true !== $app['browser']->isNewGeneration()) {
|
||||
return $app->redirect('/client/');
|
||||
} else {
|
||||
return $app->redirect('/prod/');
|
||||
}
|
||||
} else {
|
||||
return $app->redirect("/login/");
|
||||
}
|
||||
|
@@ -81,7 +81,7 @@ class RSSFeeds implements ControllerProviderInterface
|
||||
$controllers->get('/feed/{id}/{format}/', function(Application $app, $id, $format) use ($display_feed) {
|
||||
$feed = new \Feed_Adapter($app, $id);
|
||||
|
||||
if ( ! $feed->is_public()) {
|
||||
if (!$feed->is_public()) {
|
||||
return new Response('Forbidden', 403);
|
||||
}
|
||||
|
||||
@@ -94,12 +94,9 @@ class RSSFeeds implements ControllerProviderInterface
|
||||
})->assert('id', '\d+')->assert('format', '(rss|atom)');
|
||||
|
||||
$controllers->get('/userfeed/{token}/{id}/{format}/', function(Application $app, $token, $id, $format) use ($display_feed) {
|
||||
try {
|
||||
$token = new \Feed_Token($app, $token, $id);
|
||||
$feed = $token->get_feed();
|
||||
} catch (\Exception_FeedNotFound $e) {
|
||||
return new Response('Not Found', 404);
|
||||
}
|
||||
$token = new \Feed_Token($app, $token, $id);
|
||||
$feed = $token->get_feed();
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$page = (int) $request->query->get('page');
|
||||
@@ -109,12 +106,8 @@ class RSSFeeds implements ControllerProviderInterface
|
||||
})->assert('id', '\d+')->assert('format', '(rss|atom)');
|
||||
|
||||
$controllers->get('/userfeed/aggregated/{token}/{format}/', function(Application $app, $token, $format) use ($display_feed) {
|
||||
try {
|
||||
$token = new \Feed_TokenAggregate($app, $token);
|
||||
$feed = $token->get_feed();
|
||||
} catch (\Exception_FeedNotFound $e) {
|
||||
return new Response('', 404);
|
||||
}
|
||||
$token = new \Feed_TokenAggregate($app, $token);
|
||||
$feed = $token->get_feed();
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
|
@@ -46,7 +46,7 @@ class Installer implements ControllerProviderInterface
|
||||
$extension_constraints = \setup::check_php_extension();
|
||||
$opcode_constraints = \setup::check_cache_opcode();
|
||||
$php_conf_constraints = \setup::check_php_configuration();
|
||||
$locales_constraints = \setup::check_system_locales();
|
||||
$locales_constraints = \setup::check_system_locales($app);
|
||||
|
||||
$constraints_coll = array(
|
||||
'php_constraint' => $php_constraint
|
||||
@@ -80,7 +80,7 @@ class Installer implements ControllerProviderInterface
|
||||
return $app['twig']->render(
|
||||
'/setup/index.html.twig'
|
||||
, array_merge($constraints_coll, array(
|
||||
'locale' => \Session_Handler::get_locale()
|
||||
'locale' => $app['locale']
|
||||
, 'available_locales' => $app->getAvailableLanguages()
|
||||
, 'version_number' => $app['phraseanet.version']->getNumber()
|
||||
, 'version_name' => $app['phraseanet.version']->getName()
|
||||
@@ -91,7 +91,7 @@ class Installer implements ControllerProviderInterface
|
||||
|
||||
public function getInstallForm(Application $app, Request $request)
|
||||
{
|
||||
\phrasea::use_i18n(\Session_Handler::get_locale());
|
||||
\phrasea::use_i18n($app['locale']);
|
||||
|
||||
$ld_path = array(__DIR__ . '/../../../../../templates/web');
|
||||
$loader = new \Twig_Loader_Filesystem($ld_path);
|
||||
@@ -106,7 +106,7 @@ class Installer implements ControllerProviderInterface
|
||||
$extension_constraints = \setup::check_php_extension();
|
||||
$opcode_constraints = \setup::check_cache_opcode();
|
||||
$php_conf_constraints = \setup::check_php_configuration();
|
||||
$locales_constraints = \setup::check_system_locales();
|
||||
$locales_constraints = \setup::check_system_locales($app);
|
||||
|
||||
$constraints_coll = array(
|
||||
'php_constraint' => $php_constraint
|
||||
@@ -133,7 +133,7 @@ class Installer implements ControllerProviderInterface
|
||||
return $twig->render(
|
||||
'/setup/step2.html.twig'
|
||||
, array(
|
||||
'locale' => \Session_Handler::get_locale()
|
||||
'locale' => $app['locale']
|
||||
, 'available_locales' => $app->getAvailableLanguages()
|
||||
, 'available_templates' => \appbox::list_databox_templates()
|
||||
, 'version_number' => $app['phraseanet.version']->getNumber()
|
||||
@@ -150,7 +150,7 @@ class Installer implements ControllerProviderInterface
|
||||
public function doInstall(Application $app, Request $request)
|
||||
{
|
||||
set_time_limit(360);
|
||||
\phrasea::use_i18n(\Session_Handler::get_locale());
|
||||
\phrasea::use_i18n($app['locale']);
|
||||
|
||||
$servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
|
||||
|
||||
@@ -234,7 +234,7 @@ class Installer implements ControllerProviderInterface
|
||||
|
||||
$auth = new \Session_Authentication_None($user);
|
||||
|
||||
$app['phraseanet.session']->authenticate($auth);
|
||||
$app->openAccount($auth);
|
||||
|
||||
if ($databox_name && !\p4string::hasAccent($databox_name)) {
|
||||
$template = new \SplFileInfo(__DIR__ . '/../../../../conf.d/data_templates/' . $request->request->get('db_template') . '.xml');
|
||||
|
@@ -33,7 +33,7 @@ class Upgrader implements ControllerProviderInterface
|
||||
return $app['twig']->render(
|
||||
'/setup/upgrader.html.twig'
|
||||
, array(
|
||||
'locale' => \Session_Handler::get_locale()
|
||||
'locale' => $app['locale']
|
||||
, 'upgrade_status' => $upgrade_status
|
||||
, 'available_locales' => $app->getAvailableLanguages()
|
||||
, 'bad_users' => \User_Adapter::get_wrong_email_users($app)
|
||||
|
@@ -90,7 +90,7 @@
|
||||
<div class="control-group">
|
||||
<label class="form_label control-label" for="form_city">{% trans 'admin::compte-utilisateur ville' %}</label>
|
||||
<div class="controls">
|
||||
<input class="input_element geoname_field" type="text" name="form_geonameid" id="form_geonameid" geonameid="{{ user.get_geonameid() }}" value="{{ geonames.name_from_id(user.get_geonameid(), app) }}" />
|
||||
<input class="input_element geoname_field" type="text" name="form_geonameid" id="form_geonameid" geonameid="{{ user.get_geonameid() }}" value="{{ app['geonames'].name_from_id(user.get_geonameid()) }}" />
|
||||
<p class="form_alert help-block"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -53,23 +53,23 @@ $(document).ready(function(){
|
||||
<td style='width:600px;'>
|
||||
<div id="content-apps">
|
||||
<h3>{% trans 'Vous avez autorise ces applications a acceder a votre compte' %}</h3>
|
||||
{% if apps|length > 0 %}
|
||||
{% if applications|length > 0 %}
|
||||
<ul class='app-list'>
|
||||
{% for app in apps %}
|
||||
<li id='app_{{app.get_id}}'>
|
||||
{% for application in applications %}
|
||||
<li id='app_{{application.get_id}}'>
|
||||
<div>
|
||||
{% set account = app.get_user_account(user) %}
|
||||
{% set account = application.get_user_account(user) %}
|
||||
{% if account.is_revoked() is empty %}
|
||||
<button type='button' class='revoke app-btn' value='{{app.get_id()}}'>{% trans 'Revoquer l\'access' %}</button>
|
||||
<button type='button' class='revoke app-btn' value='{{application.get_id()}}'>{% trans 'Revoquer l\'access' %}</button>
|
||||
{% else %}
|
||||
<button type='button' class='authorize app-btn' value='{{app.get_id()}}'>{% trans 'Authoriser l\'access' %}</button>
|
||||
<button type='button' class='authorize app-btn' value='{{application.get_id()}}'>{% trans 'Authoriser l\'access' %}</button>
|
||||
{% endif %}
|
||||
<span class='app-row'>
|
||||
<a href="{{app.get_website()}}" target="_blank">
|
||||
<strong>{{app.get_name()}}</strong>
|
||||
<a href="{{application.get_website()}}" target="_blank">
|
||||
<strong>{{application.get_name()}}</strong>
|
||||
</a>
|
||||
{% if app.get_creator() is not none %}
|
||||
{% set user_name = app.get_creator().get_display_name() %}
|
||||
{% if application.get_creator() is not none %}
|
||||
{% set user_name = application.get_creator().get_display_name() %}
|
||||
{% trans %}
|
||||
par {{user_name}}
|
||||
{% endtrans %}
|
||||
@@ -78,7 +78,7 @@ $(document).ready(function(){
|
||||
<span class='app-row'>
|
||||
<font size="1"><i>{{ app['date-formatter'].getPrettyString(app.get_created_on()) }}</i></font>
|
||||
</span>
|
||||
<span class='app-row'>{{ app.get_description() }}</span>
|
||||
<span class='app-row'>{{ application.get_description() }}</span>
|
||||
</div>
|
||||
</li>
|
||||
{%endfor%}
|
||||
|
@@ -33,28 +33,40 @@
|
||||
{% for row in sessions %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if app['session'].get('phrasea_session_id') != row['session_id'] %}
|
||||
{% if app['session'].get('phrasea_session_id') != row.Id() %}
|
||||
<img src="/skins/icons/delete.png"/>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ app['date-formatter'].getDate(row['created_on']) }}
|
||||
{{ app['date-formatter'].getDate(row.getCreated()) }}
|
||||
</td>
|
||||
<td>
|
||||
{{ app['date-formatter'].getDate(row['lastaccess']) }}
|
||||
{{ app['date-formatter'].getDate(row.getUpdated()) }}
|
||||
</td>
|
||||
<td>
|
||||
{{ row['ip'] }}
|
||||
{{ row['ip_infos'] }}
|
||||
{% set geoname = app['geonames'].find_geoname_from_ip(row.getIpAddress()) %}
|
||||
|
||||
{% if geoname['city'] %}
|
||||
{% set ip_infos = geoname['city'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
||||
{% elseif geoname['fips'] %}
|
||||
{% set ip_infos = geoname['fips'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
||||
{% elseif geoname['country'] %}
|
||||
{% set ip_infos = geoname['country'] %}
|
||||
{% else %}
|
||||
{% set ip_infos = '' %}
|
||||
{% endif %}
|
||||
|
||||
{{ row.getIpAddress() }}
|
||||
{{ ip_infos }}
|
||||
</td>
|
||||
<td>
|
||||
{{ row['browser'] }} {{ row['browser_version'] }}
|
||||
{{ row.getBrowserName() }} {{ row.getBrowserVersion() }}
|
||||
</td>
|
||||
<td>
|
||||
{{ row['screen'] }}
|
||||
{{ row.getScreenWidth() }} x {{ row.getScreenHeight() }}
|
||||
</td>
|
||||
<td>
|
||||
{% if row['token'] %}oui{% endif %}
|
||||
{% if row.getToken %}{{ yes }}{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
{% extends request.isXmlHttpRequest ? "admin/common/ajax_wrap.html.twig" : "admin/common/iframe_wrap.html.twig" %}
|
||||
{% extends app['request'].isXmlHttpRequest ? "admin/common/ajax_wrap.html.twig" : "admin/common/iframe_wrap.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
@@ -9,13 +9,13 @@
|
||||
{% block content %}
|
||||
|
||||
<h1 style='text-align:left'>{% trans 'Application' %}</h1>
|
||||
<input type="hidden" value="{{app.get_id}}" name="app_id"/>
|
||||
<input type="hidden" value="{{application.get_id}}" name="app_id"/>
|
||||
<div>
|
||||
<ul class='app-list'>
|
||||
<li>
|
||||
<div>
|
||||
<span class='app-row'><strong><a class="link" href="/developers/application/{{app.get_id}}/">{{app.get_name}}</a></strong></span>
|
||||
<span class='app-row'>{{app.get_description }}</span>
|
||||
<span class='app-row'><strong><a class="link" href="/developers/application/{{application.get_id}}/">{{application.get_name}}</a></strong></span>
|
||||
<span class='app-row'>{{application.get_description }}</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -26,20 +26,20 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Client ID</td>
|
||||
<td>{{app.get_client_id}}</td>
|
||||
<td>{{application.get_client_id}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Client Secret</td>
|
||||
<td>{{app.get_client_secret}}</td>
|
||||
<td>{{application.get_client_secret}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans 'URL de callback' %}</td>
|
||||
{% if app.get_type == constant('API_OAuth2_Application::DESKTOP_TYPE') %}
|
||||
{% if application.get_type == constant('API_OAuth2_Application::DESKTOP_TYPE') %}
|
||||
<td>
|
||||
<span>{{app.get_redirect_uri}}</span>
|
||||
<span>{{application.get_redirect_uri}}</span>
|
||||
</td>
|
||||
{% else %}
|
||||
<td class="url_callback"><span class="url_callback_input">{{app.get_redirect_uri}}</span>
|
||||
<td class="url_callback"><span class="url_callback_input">{{application.get_redirect_uri}}</span>
|
||||
<button type="button" class="save_callback" style="display:none;">save</button>
|
||||
<button type="button" class="modifier_callback" style="display:none;">modifier</button>
|
||||
</td>
|
||||
@@ -55,7 +55,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans 'Activer le grant_type de type password pour votre application' %}</td>
|
||||
<td><input class="grant-type" type='checkbox' {{ app.is_password_granted() ? "checked='checked'" : ""}} name="grant" value='{{app.get_id()}}'></td>
|
||||
<td><input class="grant-type" type='checkbox' {{ application.is_password_granted() ? "checked='checked'" : ""}} name="grant" value='{{application.get_id()}}'></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -80,7 +80,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td style='width:25%'></td>
|
||||
<td><button id="generate_access" type="button" value="{{app.get_id}}">{% trans 'boutton::generer' %}</button></td>
|
||||
<td><button id="generate_access" type="button" value="{{application.get_id}}">{% trans 'boutton::generer' %}</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@@ -14,21 +14,21 @@
|
||||
<div id="content-apps">
|
||||
<h1>Phraseanet Developer Center</h1>
|
||||
<h3>{% trans 'Mes applications' %}</h3>
|
||||
{% if apps|length > 0 %}
|
||||
{% if applications|length > 0 %}
|
||||
<ul class='app-list'>
|
||||
{% for app in apps %}
|
||||
<li id='app_{{app.get_id()}}'>
|
||||
{% for application in applications %}
|
||||
<li id='app_{{application.get_id()}}'>
|
||||
<div>
|
||||
<button class='delete_app' type='button'>{% trans 'button::supprimer'%}</button>
|
||||
<span class='app-row'>
|
||||
<strong>
|
||||
<a class="link" href="/developers/application/{{app.get_id()}}/">
|
||||
{{app.get_name()}}
|
||||
<a class="link" href="/developers/application/{{application.get_id()}}/">
|
||||
{{application.get_name()}}
|
||||
</a>
|
||||
</strong>
|
||||
</span>
|
||||
<span class='app-row'>{{app.get_description() }}</span>
|
||||
<span class='app-row'>{{app.get_website()}}</span>
|
||||
<span class='app-row'>{{application.get_description() }}</span>
|
||||
<span class='app-row'>{{application.get_website()}}</span>
|
||||
</div>
|
||||
</li>
|
||||
{%endfor%}
|
||||
|
@@ -11,7 +11,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
protected $client;
|
||||
protected static $createdCollections = array();
|
||||
protected static $createdDataboxes = array();
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
@@ -76,65 +75,12 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function createDatabox()
|
||||
{
|
||||
$registry = self::$application['phraseanet.registry'];
|
||||
|
||||
$this->createDatabase();
|
||||
|
||||
$configuration = self::$application['phraseanet.configuration'];
|
||||
|
||||
$choosenConnexion = $configuration->getPhraseanet()->get('database');
|
||||
$connexion = $configuration->getConnexion($choosenConnexion);
|
||||
|
||||
try {
|
||||
$conn = new \connection_pdo('databox_creation', $connexion->get('host'), $connexion->get('port'), $connexion->get('user'), $connexion->get('password'), 'unit_test_db', array(), $registry);
|
||||
} catch (\PDOException $e) {
|
||||
|
||||
$this->markTestSkipped('Could not reach DB');
|
||||
}
|
||||
|
||||
$databox = \databox::create(
|
||||
self::$application, $conn, new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/fr-simple.xml'), $registry
|
||||
);
|
||||
|
||||
self::$createdDataboxes[] = $databox;
|
||||
|
||||
$databox->registerAdmin(self::$application['phraseanet.user']);
|
||||
|
||||
return $databox;
|
||||
}
|
||||
|
||||
public function checkRedirection($response, $location)
|
||||
{
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals($location, $response->headers->get('location'));
|
||||
}
|
||||
|
||||
public static function dropDatabase()
|
||||
{
|
||||
$stmt = self::$application['phraseanet.appbox']
|
||||
->get_connection()
|
||||
->prepare('DROP DATABASE IF EXISTS `unit_test_db`');
|
||||
$stmt->execute();
|
||||
$stmt = self::$application['phraseanet.appbox']
|
||||
->get_connection()
|
||||
->prepare('DELETE FROM sbas WHERE dbname = "unit_test_db"');
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
protected function createDatabase()
|
||||
{
|
||||
self::dropDatabase();
|
||||
|
||||
$stmt = self::$application['phraseanet.appbox']
|
||||
->get_connection()
|
||||
->prepare('CREATE DATABASE `unit_test_db`
|
||||
CHARACTER SET utf8 COLLATE utf8_unicode_ci');
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::connect
|
||||
@@ -519,65 +465,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$this->assertEquals('new_databox_name', $databox->get_viewname());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabaseEmpty()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->client->request('POST', '/admin/databox/', array(
|
||||
'new_dbname' => ''
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals('/admin/databoxes/?error=no-empty', $response->headers->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabaseSpecialChar()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->client->request('POST', '/admin/databox/', array(
|
||||
'new_dbname' => 'ééààèè'
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals('/admin/databoxes/?error=special-chars', $response->headers->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabase()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->createDatabase();
|
||||
|
||||
$this->client->request('POST', '/admin/databox/', array(
|
||||
'new_dbname' => 'unit_test_db',
|
||||
'new_data_template' => 'fr-simple',
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$uriRedirect = $response->headers->get('location');
|
||||
$this->assertTrue(!!strrpos($uriRedirect, 'success=1'));
|
||||
$explode = explode('/', $uriRedirect);
|
||||
$databoxId = $explode[3];
|
||||
$databox = self::$application['phraseanet.appbox']->get_databox($databoxId);
|
||||
$databox->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
$databox->delete();
|
||||
|
||||
unset($stmt, $databox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::deleteBase
|
||||
*/
|
||||
@@ -601,41 +488,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::databaseMount
|
||||
*/
|
||||
public function testMountBase()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$base = $this->createDatabox();
|
||||
$base->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
|
||||
$this->client->request('POST', '/admin/databox/mount/', array(
|
||||
'new_dbname' => 'unit_test_db'
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$uriRedirect = $response->headers->get('location');
|
||||
|
||||
|
||||
$this->assertTrue(!!strrpos($uriRedirect, 'success=1'));
|
||||
$explode = explode('/', $uriRedirect);
|
||||
$databoxId = $explode[3];
|
||||
|
||||
try {
|
||||
$databox = self::$application['phraseanet.appbox']->get_databox($databoxId);
|
||||
$databox->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
$databox->delete();
|
||||
} catch (\Exception_DataboxNotFound $e) {
|
||||
$this->fail('databox not mounted');
|
||||
}
|
||||
|
||||
unset($databox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::mountCollection
|
||||
*/
|
||||
|
@@ -59,4 +59,99 @@ class DataboxesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::databaseMount
|
||||
*/
|
||||
public function testMountBase()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$base = $this->createDatabox();
|
||||
$base->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
|
||||
$this->client->request('POST', '/admin/databoxes/mount/', array(
|
||||
'new_dbname' => 'unit_test_db'
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$uriRedirect = $response->headers->get('location');
|
||||
|
||||
|
||||
$this->assertTrue(!!strrpos($uriRedirect, 'success=1'));
|
||||
$explode = explode('/', $uriRedirect);
|
||||
$databoxId = $explode[3];
|
||||
|
||||
try {
|
||||
$databox = self::$application['phraseanet.appbox']->get_databox($databoxId);
|
||||
$databox->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
$databox->delete();
|
||||
} catch (\Exception_DataboxNotFound $e) {
|
||||
$this->fail('databox not mounted');
|
||||
}
|
||||
|
||||
unset($databox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabaseEmpty()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->client->request('POST', '/admin/databoxes/', array(
|
||||
'new_dbname' => ''
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals('/admin/databoxes/?error=no-empty', $response->headers->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabaseSpecialChar()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->client->request('POST', '/admin/databoxes/', array(
|
||||
'new_dbname' => 'ééààèè'
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertEquals('/admin/databoxes/?error=special-chars', $response->headers->get('location'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Admin\Database::createDatabase
|
||||
*/
|
||||
public function testCreateDatabase()
|
||||
{
|
||||
$this->setAdmin(true);
|
||||
|
||||
$this->createDatabase();
|
||||
|
||||
$this->client->request('POST', '/admin/databoxes/', array(
|
||||
'new_dbname' => 'unit_test_db',
|
||||
'new_data_template' => 'fr-simple',
|
||||
));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$uriRedirect = $response->headers->get('location');
|
||||
$this->assertTrue(!!strrpos($uriRedirect, 'success=1'));
|
||||
$explode = explode('/', $uriRedirect);
|
||||
$databoxId = $explode[3];
|
||||
$databox = self::$application['phraseanet.appbox']->get_databox($databoxId);
|
||||
$databox->unmount_databox(self::$application['phraseanet.appbox']);
|
||||
$databox->delete();
|
||||
|
||||
unset($stmt, $databox);
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
|
||||
public static $account = null;
|
||||
public static $api = null;
|
||||
protected $client;
|
||||
protected static $useExceptionHandler = true;
|
||||
|
||||
public function testList()
|
||||
{
|
||||
@@ -67,13 +68,7 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
|
||||
|
||||
public function testUpdateFeedNotOwner()
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
//is not owner
|
||||
$stub = $this->getMock("user_adapter", array(), array(), "", false);
|
||||
//return a different userid
|
||||
$stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999));
|
||||
|
||||
$feed = Feed_Adapter::create(self::$application, $stub, "salut", 'coucou');
|
||||
$feed = Feed_Adapter::create(self::$application, self::$user_alt1, "salut", 'coucou');
|
||||
$this->client->request("POST", "/admin/publications/feed/" . $feed->get_id() . "/update/");
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(), 'update fails, i\'m redirected');
|
||||
$this->assertTrue(
|
||||
@@ -152,17 +147,9 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
|
||||
|
||||
public function testIconUploadErrorOwner()
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$feed = Feed_Adapter::create(self::$application, self::$user_alt1, "salut", 'coucou');
|
||||
|
||||
//is not owner
|
||||
$stub = $this->getMock("user_adapter", array(), array(), "", false);
|
||||
//return a different userid
|
||||
$stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999));
|
||||
|
||||
|
||||
$feed = Feed_Adapter::create(self::$application, $stub, "salut", 'coucou');
|
||||
|
||||
$this->client->request("POST", "/admin/publications/feed/" . $feed->get_id() . "/iconupload/", array(), array(), array('HTTP_ACCEPT'=>'application/json'));
|
||||
$this->client->request("POST", "/admin/publications/feed/" . $feed->get_id() . "/iconupload/", array(), array(), array('HTTP_ACCEPT' => 'application/json'));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
@@ -225,7 +212,7 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
|
||||
|
||||
$feed = Feed_Adapter::create(self::$application, self::$user, "salut", 'coucou');
|
||||
|
||||
$files = array(
|
||||
$files = array(
|
||||
'files' => array(
|
||||
new \Symfony\Component\HttpFoundation\File\UploadedFile(
|
||||
__DIR__ . '/../../../../testfiles/logocoll.gif', 'logocoll.gif'
|
||||
|
@@ -24,7 +24,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testLoginRedirectPostLog()
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
|
||||
$this->client->request('GET', '/login/', array('postlog' => '1', 'redirect' => 'prod'));
|
||||
$response = $this->client->getResponse();
|
||||
@@ -38,7 +38,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testLoginError($warning, $notice)
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
|
||||
$this->client->request('GET', '/login/', array(
|
||||
'error' => $warning,
|
||||
@@ -632,17 +632,19 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testAuthenticate()
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
$password = \random::generatePassword();
|
||||
$login = self::$application['phraseanet.user']->get_login();
|
||||
self::$application['phraseanet.user']->set_password($password);
|
||||
self::$application->closeAccount();
|
||||
$this->client = new Client(self::$application, array());
|
||||
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$application);
|
||||
$this->client->request('POST', '/login/authenticate/', array(
|
||||
'login' => self::$user->get_login(),
|
||||
'login' => $login,
|
||||
'pwd' => $password
|
||||
));
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect());
|
||||
$this->assertTrue(self::$application->isAuthenticated());
|
||||
$this->assertRegExp('/^\/prod\/$/', $this->client->getResponse()->headers->get('Location'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -650,7 +652,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testBadAuthenticate()
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
$this->client->request('POST', '/login/authenticate/', array(
|
||||
'login' => self::$user->get_login(),
|
||||
'pwd' => 'test'
|
||||
@@ -666,7 +668,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testMailLockedAuthenticate()
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
$password = \random::generatePassword();
|
||||
self::$user->set_mail_locked(true);
|
||||
$this->client->request('POST', '/login/authenticate/', array(
|
||||
@@ -685,7 +687,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
*/
|
||||
public function testAuthenticateUnavailable()
|
||||
{
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
$password = \random::generatePassword();
|
||||
self::$application['phraseanet.registry']->set('GV_maintenance', true , \registry::TYPE_BOOLEAN);
|
||||
|
||||
|
@@ -72,6 +72,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
protected static $feed_4_public_title = 'Feed 4 title';
|
||||
protected static $feed_4_public_subtitle = 'Feed 4 subtitle';
|
||||
protected $client;
|
||||
protected static $useExceptionHandler = true;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -104,7 +105,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
self::$application['phraseanet.session']->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
|
||||
self::$feed_1_private = Feed_Adapter::create(self::$application, self::$user, self::$feed_1_private_title, self::$feed_1_private_subtitle);
|
||||
self::$feed_1_private->set_public(false);
|
||||
@@ -157,7 +158,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
self::$public_feeds = Feed_Collection::load_public_feeds(self::$application);
|
||||
self::$private_feeds = Feed_Collection::load_all(self::$application, self::$user);
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
@@ -217,12 +218,12 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
self::$application['phraseanet.session']->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
|
||||
$link = self::$feed_3_public->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
|
||||
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
|
||||
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
|
||||
$this->client->request('GET', "/feeds" . $link);
|
||||
$response = $this->client->getResponse();
|
||||
@@ -237,12 +238,12 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
self::$application['phraseanet.session']->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
|
||||
$link = self::$private_feeds->get_aggregate()->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
|
||||
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
|
||||
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
|
||||
$this->client->request('GET', "/feeds" . $link);
|
||||
$response = $this->client->getResponse();
|
||||
@@ -257,12 +258,12 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
self::$application['phraseanet.session']->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
|
||||
$link = self::$feed_1_private->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
|
||||
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
|
||||
|
||||
self::$application['phraseanet.session']->logout();
|
||||
self::$application->closeAccount();
|
||||
|
||||
$this->client->request('GET', "/feeds" . $link);
|
||||
$response = $this->client->getResponse();
|
||||
@@ -329,12 +330,10 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
|
||||
$this->verifyXML($xml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception_FeedNotFound
|
||||
*/
|
||||
public function testUnknowFeedId()
|
||||
{
|
||||
$this->client->request("GET", "/feeds/feed/0/rss/");
|
||||
$this->assertEquals(404, $this->client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user