mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 20:13:28 +00:00
Add API get collection route
Signed-off-by: Benoît Burnichon <bburnichon@alchemy.fr> Forward port from 3.8
This commit is contained in:

committed by
Benoît Burnichon

parent
dc7a50548a
commit
a903594fbc
@@ -472,8 +472,14 @@ class V1Controller extends Controller
|
||||
|
||||
public function getDataboxCollectionAction(Request $request, $base_id)
|
||||
{
|
||||
try {
|
||||
$collection = $this->getApplicationBox()->get_collection($base_id);
|
||||
} catch (\RuntimeException $exception) {
|
||||
throw new \HttpException('Collection not found', 404, $exception);
|
||||
}
|
||||
|
||||
return Result::create($request, [
|
||||
$this->listCollection($this->app->getApplicationBox()->get_collection($base_id))
|
||||
'collection' => $this->listCollection($collection),
|
||||
])->createResponse();
|
||||
}
|
||||
|
||||
@@ -2513,6 +2519,18 @@ class V1Controller extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
public function ensureAccessToBase(Request $request)
|
||||
{
|
||||
$user = $this->getApiAuthenticatedUser();
|
||||
$base_id = $request->attributes->get('base_id');
|
||||
|
||||
if (!$this->getAclForUser($user)->has_access_to_base($base_id)) {
|
||||
return Result::createError($request, 401, 'You are not authorized')->createResponse();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function ensureCanAccessToRecord(Request $request)
|
||||
{
|
||||
$user = $this->getApiAuthenticatedUser();
|
||||
|
@@ -72,7 +72,9 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface
|
||||
$controllers->get('/monitor/phraseanet/', 'controller.api.v1:showPhraseanetConfigurationAction')
|
||||
->before('controller.api.v1:ensureAdmin');
|
||||
|
||||
$controllers->get('/collections/{base_id}/', 'controller.api.v1:getDataboxCollectionAction');
|
||||
$controllers->get('/collections/{base_id}/', 'controller.api.v1:getDataboxCollectionAction')
|
||||
->before('controller.api.v1:ensureAccessToBase')
|
||||
->assert('base_id', '\d+');
|
||||
|
||||
$controllers->get('/databoxes/list/', 'controller.api.v1:listDataboxesAction');
|
||||
|
||||
|
@@ -257,6 +257,10 @@ class appbox extends base
|
||||
return $this->databoxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sbas_id
|
||||
* @return databox
|
||||
*/
|
||||
public function get_databox($sbas_id)
|
||||
{
|
||||
$databoxes = $this->get_databoxes();
|
||||
@@ -268,6 +272,10 @@ class appbox extends base
|
||||
return $databoxes[$sbas_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $base_id
|
||||
* @return collection
|
||||
*/
|
||||
public function get_collection($base_id)
|
||||
{
|
||||
$sbas_id = phrasea::sbasFromBas($this->app, $base_id);
|
||||
|
Reference in New Issue
Block a user