mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Merge pull request #2383 from mike-esokia/PHRAS-1736_PORT-165_and_1593
PHRAS-1736 port PHRAS-165 and PHRAS-1593
This commit is contained in:
@@ -23,44 +23,71 @@ class ShareController extends Controller
|
||||
*/
|
||||
public function shareRecord($base_id, $record_id)
|
||||
{
|
||||
$outputVars = [
|
||||
'isAvailable' => false,
|
||||
'preview' => [
|
||||
'permalinkUrl' => '',
|
||||
'permaviewUrl' => '',
|
||||
'embedUrl' => '',
|
||||
'width' => '',
|
||||
'height' => ''
|
||||
]
|
||||
];
|
||||
$record = new \record_adapter($this->app, \phrasea::sbasFromBas($this->app, $base_id), $record_id);
|
||||
|
||||
if (!$this->getAclForUser()->has_access_to_subdef($record, 'preview')) {
|
||||
$this->app->abort(403);
|
||||
}
|
||||
//get list of subdefs
|
||||
$subdefs = $record->get_subdefs();
|
||||
|
||||
$preview = $record->get_preview();
|
||||
$databoxSubdefs = $record->getDatabox()->get_subdef_structure()->getSubdefGroup($record->getType());
|
||||
$acl = $this->getAclForUser();
|
||||
$subdefList = [];
|
||||
$defaultKey = null;
|
||||
foreach ($subdefs as $subdef) {
|
||||
$subdefName = $subdef->get_name();
|
||||
if ($subdefName == 'document') {
|
||||
if (!$acl->has_right_on_base($record->getBaseId(), \ACL::CANDWNLDHD)) {
|
||||
continue;
|
||||
}
|
||||
$label = $this->app->trans('prod::tools: document');
|
||||
}
|
||||
elseif ($databoxSubdefs->hasSubdef($subdefName)) {
|
||||
if (!$acl->has_access_to_subdef($record, $subdefName)) {
|
||||
continue;
|
||||
}
|
||||
$label = $databoxSubdefs->getSubdef($subdefName)->get_label($this->app['locale']);
|
||||
}
|
||||
else {
|
||||
// this subdef does no exists anymore in databox structure ?
|
||||
continue; // don't publish it
|
||||
}
|
||||
$value = $subdef->get_name();
|
||||
$preview = $record->get_subdef($value);
|
||||
$defaultKey = $value; // will set a default option if neither preview,thumbnail or document is present
|
||||
|
||||
if (null !== $previewLink = $preview->get_permalink()) {
|
||||
$permalinkUrl = $previewLink->get_url();
|
||||
$permaviewUrl = $previewLink->get_page();
|
||||
$previewWidth = $preview->get_width();
|
||||
$previewHeight = $preview->get_height();
|
||||
|
||||
$embedUrl = $this->app->url('alchemy_embed_view', ['url' => (string)$permalinkUrl]);
|
||||
|
||||
$outputVars = [
|
||||
'isAvailable' => true,
|
||||
'preview' => [
|
||||
if ( ($previewLink = $preview->get_permalink()) !== null ) {
|
||||
$permalinkUrl = $previewLink->get_url()->__toString();
|
||||
$permaviewUrl = $previewLink->get_page();
|
||||
$previewWidth = $preview->get_width();
|
||||
$previewHeight = $preview->get_height();
|
||||
$embedUrl = $this->app->url('alchemy_embed_view', ['url' => (string)$permalinkUrl]);
|
||||
$previewData = [
|
||||
'label' => $label,
|
||||
'permalinkUrl' => $permalinkUrl,
|
||||
'permaviewUrl' => $permaviewUrl,
|
||||
'embedUrl' => $embedUrl,
|
||||
'width' => $previewWidth,
|
||||
'height' => $previewHeight
|
||||
]
|
||||
];
|
||||
'embedUrl' => $embedUrl,
|
||||
'width' => $previewWidth,
|
||||
'height' => $previewHeight
|
||||
];
|
||||
$subdefList[$value] = $previewData;
|
||||
}
|
||||
}
|
||||
|
||||
// candidates as best default selected option
|
||||
foreach(["preview", "thumbnail", "document"] as $k) {
|
||||
if (array_key_exists($k, $subdefList)) {
|
||||
$defaultKey = $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if no subdef was sharable, subdefList is empty and defaultKey is null
|
||||
// the twig MUST handle that
|
||||
$outputVars = [
|
||||
'isAvailable' => !empty($subdefList),
|
||||
'subdefList' => $subdefList,
|
||||
'defaultKey' => $defaultKey
|
||||
];
|
||||
|
||||
return $this->renderResponse('prod/Share/record.html.twig', $outputVars);
|
||||
}
|
||||
}
|
||||
|
@@ -47,10 +47,22 @@ class Share implements ControllerProviderInterface, ServiceProviderInterface
|
||||
|
||||
$controllers->get('/record/{base_id}/{record_id}/', 'controller.prod.share:shareRecord')
|
||||
->before(function (Request $request) use ($app, $firewall) {
|
||||
$firewall->requireRightOnSbas(
|
||||
\phrasea::sbasFromBas($app, $request->attributes->get('base_id')),
|
||||
\ACL::BAS_CHUPUB
|
||||
);
|
||||
$socialTools = $app['conf']->get(['registry', 'actions', 'social-tools']);
|
||||
if($socialTools === "all") {
|
||||
return;
|
||||
}
|
||||
elseif($socialTools === "none") {
|
||||
$app->abort(403, 'social tools disabled');
|
||||
}
|
||||
elseif($socialTools === "publishers") {
|
||||
$firewall->requireRightOnSbas(
|
||||
\phrasea::sbasFromBas($app, $request->attributes->get('base_id')),
|
||||
\ACL::BAS_CHUPUB
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new \Exception("bad value \"" . $socialTools . "\" for social tools");
|
||||
}
|
||||
})
|
||||
->bind('share_record');
|
||||
|
||||
|
Reference in New Issue
Block a user