mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
PermalinkController knows about how to retrieve records, not Media service
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Controller;
|
||||
|
||||
use Alchemy\Embed\Media\Media;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
|
||||
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||
use Alchemy\Phrasea\Model\Repositories\BasketElementRepository;
|
||||
@@ -22,6 +23,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class PermalinkController extends AbstractDelivery
|
||||
{
|
||||
use ApplicationBoxAware;
|
||||
|
||||
/** @var ACLProvider */
|
||||
private $acl;
|
||||
/** @var Authenticator */
|
||||
@@ -40,9 +43,9 @@ class PermalinkController extends AbstractDelivery
|
||||
|
||||
public function getOptionsResponse(Request $request, $sbas_id, $record_id)
|
||||
{
|
||||
$databox = $this->mediaService->getDatabox($sbas_id);
|
||||
$databox = $this->findDataboxById($sbas_id);
|
||||
$token = $request->query->get('token');
|
||||
$record = $this->mediaService->retrieveRecord($databox, $token, $record_id, $request->get('subdef', 'thumbnail'));
|
||||
$record = $this->retrieveRecord($databox, $token, $record_id, $request->get('subdef', 'thumbnail'));
|
||||
|
||||
if (null === $record) {
|
||||
throw new NotFoundHttpException("Record not found");
|
||||
@@ -53,9 +56,9 @@ class PermalinkController extends AbstractDelivery
|
||||
|
||||
public function deliverCaption(Request $request, $sbas_id, $record_id)
|
||||
{
|
||||
$databox = $this->mediaService->getDatabox($sbas_id);
|
||||
$databox = $this->findDataboxById($sbas_id);
|
||||
$token = $request->query->get('token');
|
||||
$record = $this->mediaService->retrieveRecord($databox, $token, $record_id, \databox_subdef::CLASS_THUMBNAIL);
|
||||
$record = $this->retrieveRecord($databox, $token, $record_id, \databox_subdef::CLASS_THUMBNAIL);
|
||||
|
||||
if (null === $record) {
|
||||
throw new NotFoundHttpException("Caption not found");
|
||||
@@ -73,8 +76,8 @@ class PermalinkController extends AbstractDelivery
|
||||
private function doDeliverPermaview(Request $request, $sbas_id, $record_id, $token, $subdefName)
|
||||
{
|
||||
|
||||
$databox = $this->mediaService->getDatabox($sbas_id);
|
||||
$record = $this->mediaService->retrieveRecord($databox, $token, $record_id, $subdefName);
|
||||
$databox = $this->findDataboxById($sbas_id);
|
||||
$record = $this->retrieveRecord($databox, $token, $record_id, $subdefName);
|
||||
$metaData = $this->mediaService->getMetaData($request, $record, $subdefName);
|
||||
$subdef = $record->get_subdef($subdefName);
|
||||
|
||||
@@ -108,8 +111,8 @@ class PermalinkController extends AbstractDelivery
|
||||
|
||||
private function doDeliverPermalink(Request $request, $sbas_id, $record_id, $token, $subdef)
|
||||
{
|
||||
$databox = $this->mediaService->getDatabox($sbas_id);
|
||||
$record = $this->mediaService->retrieveRecord($databox, $token, $record_id, $subdef);
|
||||
$databox = $this->findDataboxById($sbas_id);
|
||||
$record = $this->retrieveRecord($databox, $token, $record_id, $subdef);
|
||||
$watermark = $stamp = false;
|
||||
|
||||
if ($this->authentication->isAuthenticated()) {
|
||||
@@ -172,4 +175,37 @@ class PermalinkController extends AbstractDelivery
|
||||
{
|
||||
return $this->doDeliverPermalink($request, $sbas_id, $record_id, $token, $subdef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \databox $databox
|
||||
* @param string $token
|
||||
* @param int $record_id
|
||||
* @param string $subdef
|
||||
* @return \record_adapter
|
||||
*/
|
||||
private function retrieveRecord(\databox $databox, $token, $record_id, $subdef)
|
||||
{
|
||||
try {
|
||||
$record = $databox->get_record($record_id);
|
||||
$subDefinition = $record->get_subdef($subdef);
|
||||
$permalink = $subDefinition->get_permalink();
|
||||
} catch (\Exception $exception) {
|
||||
throw new NotFoundHttpException('Wrong token.', $exception);
|
||||
}
|
||||
|
||||
if (null === $permalink || !$permalink->get_is_activated()) {
|
||||
throw new NotFoundHttpException('This token has been disabled.');
|
||||
}
|
||||
|
||||
$feedItemsRepository = $this->app['repo.feed-items'];
|
||||
if (in_array($subdef, [\databox_subdef::CLASS_PREVIEW, \databox_subdef::CLASS_THUMBNAIL])
|
||||
&& $feedItemsRepository->isRecordInPublicFeed($databox->get_sbas_id(), $record_id)
|
||||
) {
|
||||
return $record;
|
||||
} elseif ($permalink->get_token() == (string)$token) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('Wrong token.');
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface
|
||||
))
|
||||
->setDataboxLoggerLocator($app['phraseanet.logger'])
|
||||
->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
|
||||
->setApplicationBox($app['phraseanet.appbox'])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user