mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 18:33:13 +00:00
Use voters in workzone, actionbar and basket_actionbar
This commit is contained in:
@@ -16,16 +16,21 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
|||||||
abstract class BaseVoter implements VoterInterface
|
abstract class BaseVoter implements VoterInterface
|
||||||
{
|
{
|
||||||
private $supportedAttributes;
|
private $supportedAttributes;
|
||||||
private $supportedClass;
|
private $supportedClasses;
|
||||||
|
|
||||||
/** @var Application */
|
/** @var Application */
|
||||||
private $app;
|
private $app;
|
||||||
|
|
||||||
public function __construct(Application $app, array $attributes, $supportedClass)
|
/**
|
||||||
|
* @param Application $app
|
||||||
|
* @param array $attributes
|
||||||
|
* @param string|array $supportedClasses
|
||||||
|
*/
|
||||||
|
public function __construct(Application $app, array $attributes, $supportedClasses)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->supportedAttributes = $attributes;
|
$this->supportedAttributes = $attributes;
|
||||||
$this->supportedClass = $supportedClass;
|
$this->supportedClasses = is_array($supportedClasses) ? $supportedClasses : [$supportedClasses];
|
||||||
|
|
||||||
if (!is_callable([$this, 'isGranted'])) {
|
if (!is_callable([$this, 'isGranted'])) {
|
||||||
throw new \LogicException('Subclasses should implement a "isGranted" method');
|
throw new \LogicException('Subclasses should implement a "isGranted" method');
|
||||||
@@ -39,10 +44,11 @@ abstract class BaseVoter implements VoterInterface
|
|||||||
|
|
||||||
public function supportsClass($class)
|
public function supportsClass($class)
|
||||||
{
|
{
|
||||||
$supportedClass = $this->supportedClass;
|
foreach ($this->supportedClasses as $supportedClass) {
|
||||||
if ($class == $supportedClass || is_subclass_of($class, $supportedClass)) {
|
if ($class == $supportedClass || is_subclass_of($class, $supportedClass)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,15 @@ class BasketController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var \Closure $filter */
|
||||||
|
$filter = $this->app['plugin.filter_by_authorization'];
|
||||||
|
|
||||||
return $this->render('prod/WorkZone/Basket.html.twig', [
|
return $this->render('prod/WorkZone/Basket.html.twig', [
|
||||||
'basket' => $basket,
|
'basket' => $basket,
|
||||||
'ordre' => $request->query->get('order'),
|
'ordre' => $request->query->get('order'),
|
||||||
|
'plugins' => [
|
||||||
|
'actionbar' => $filter('workzone.basket.actionbar'),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,14 @@ class RootController extends Controller
|
|||||||
|
|
||||||
$helper = new Helper\Prod($this->app, $request);
|
$helper = new Helper\Prod($this->app, $request);
|
||||||
|
|
||||||
|
/** @var \Closure $filter */
|
||||||
|
$filter = $this->app['plugin.filter_by_authorization'];
|
||||||
|
|
||||||
|
$plugins = [
|
||||||
|
'workzone' => $filter('workzone'),
|
||||||
|
'actionbar' => $filter('actionbar'),
|
||||||
|
];
|
||||||
|
|
||||||
return $this->render('prod/index.html.twig', [
|
return $this->render('prod/index.html.twig', [
|
||||||
'module_name' => 'Production',
|
'module_name' => 'Production',
|
||||||
'WorkZone' => new Helper\WorkZone($this->app, $request),
|
'WorkZone' => new Helper\WorkZone($this->app, $request),
|
||||||
@@ -129,6 +137,7 @@ class RootController extends Controller
|
|||||||
'thesau_json_sbas' => json_encode($sbas),
|
'thesau_json_sbas' => json_encode($sbas),
|
||||||
'thesau_json_bas2sbas' => json_encode($bas2sbas),
|
'thesau_json_bas2sbas' => json_encode($bas2sbas),
|
||||||
'thesau_languages' => $this->app['locales.available'],
|
'thesau_languages' => $this->app['locales.available'],
|
||||||
|
'plugins' => $plugins,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Provider;
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Authorization\AuthorizationChecker;
|
||||||
use Alchemy\Phrasea\Plugin\PluginManager;
|
use Alchemy\Phrasea\Plugin\PluginManager;
|
||||||
use Alchemy\Phrasea\Plugin\Schema\ManifestValidator;
|
use Alchemy\Phrasea\Plugin\Schema\ManifestValidator;
|
||||||
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
||||||
@@ -57,6 +58,23 @@ class PluginServiceProvider implements ServiceProviderInterface
|
|||||||
$app['plugin.workzone'] = $app->share(function () {
|
$app['plugin.workzone'] = $app->share(function () {
|
||||||
return new Pimple();
|
return new Pimple();
|
||||||
});
|
});
|
||||||
|
$app['plugin.filter_by_authorization'] = $app->protect(function ($pluginZone, $attributes = 'VIEW') use ($app) {
|
||||||
|
/** @var \Pimple $container */
|
||||||
|
$container = $app['plugin.' . $pluginZone];
|
||||||
|
/** @var AuthorizationChecker $authorizationChecker */
|
||||||
|
$authorizationChecker = $app['phraseanet.authorization_checker'];
|
||||||
|
|
||||||
|
$plugins = [];
|
||||||
|
foreach ($container->keys() as $pluginKey) {
|
||||||
|
$plugin = $container[$pluginKey];
|
||||||
|
|
||||||
|
if ($authorizationChecker->isGranted($attributes, $plugin)) {
|
||||||
|
$plugins[$pluginKey] = $plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plugins;
|
||||||
|
});
|
||||||
|
|
||||||
$app['plugin.locale.textdomains'] = new ArrayObject();
|
$app['plugin.locale.textdomains'] = new ArrayObject();
|
||||||
|
|
||||||
|
|||||||
@@ -58,15 +58,13 @@
|
|||||||
<img src="/skins/icons/delete.png"/>
|
<img src="/skins/icons/delete.png"/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{% if app['plugin.workzone.basket.actionbar'].keys() is not empty %}
|
{% if plugins['actionbar'] is not empty %}
|
||||||
{% for pluginId in app['plugin.workzone.basket.actionbar'].keys() %}
|
{% for plugin in plugins['actionbar'] %}
|
||||||
{% for key,action in app['plugin.workzone.basket.actionbar'][pluginId].getBasketActionBar() %}
|
{% for key, action in plugin.getBasketActionBar() %}
|
||||||
{% set label = action.label %}
|
{% set label = action.label %}
|
||||||
|
<button class="ui-corner-all basket_window {{ action.classes|default('') }}" title="{% trans label plugin.PluginLocale %}">
|
||||||
<button class="ui-corner-all basket_window {{ action.classes|default('') }}" title="{% trans label app['plugin.workzone.basket.actionbar'][pluginId].PluginLocale %}">
|
<img src="{{ plugin_asset(plugin.PluginName, action.icon) }}"/>
|
||||||
<img src="{{ plugin_asset(app['plugin.workzone.basket.actionbar'][pluginId].PluginName,action.icon) }}"/>
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -160,14 +160,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% set workzone_plugins = [] %}
|
|
||||||
{% for plugin in app['plugin.workzone'].keys() %}
|
|
||||||
{% if app['phraseanet.authorization_checker'].isGranted('VIEW', app['plugin.workzone'][plugin]) %}
|
|
||||||
{% set workzone_plugins = workzone_plugins|merge({(plugin): app['plugin.workzone'][plugin]}) %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% set search_datas = module_prod.get_search_datas() %}
|
{% set search_datas = module_prod.get_search_datas() %}
|
||||||
<div style="position:absolute; top:0; left:0; right:0; bottom:0; background-color:#1a1a1a; z-index:32766;">
|
<div style="position:absolute; top:0; left:0; right:0; bottom:0; background-color:#1a1a1a; z-index:32766;">
|
||||||
<div id="loader" style="top:200px; margin:0 auto; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; background-color:#CCCCCC; position:relative; margin:0 auto; text-align:center; width:400px; height:100px; padding:20px; z-index:32767;">
|
<div id="loader" style="top:200px; margin:0 auto; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; background-color:#CCCCCC; position:relative; margin:0 auto; text-align:center; width:400px; height:100px; padding:20px; z-index:32767;">
|
||||||
@@ -203,8 +195,8 @@
|
|||||||
{% include 'prod/tab_thesaurus.html.twig' with {has_access_to_module: app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('thesaurus')} %}
|
{% include 'prod/tab_thesaurus.html.twig' with {has_access_to_module: app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('thesaurus')} %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<div id="plugins" class="PNB {{ workzone_plugins|length > 1 ? 'multiple-plugin' : 'single-plugin' }}" style="top:52px;">
|
<div id="plugins" class="PNB {{ plugins.workzone|length > 1 ? 'multiple-plugin' : 'single-plugin' }}" style="top:52px;">
|
||||||
{% for pluginId, plugin in workzone_plugins %}
|
{% for pluginId, plugin in plugins.workzone %}
|
||||||
{% include plugin.getWorkzoneTemplate() with {'app': app, 'plugin_id': pluginId} only %}
|
{% include plugin.getWorkzoneTemplate() with {'app': app, 'plugin_id': pluginId} only %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if workzone_plugins is not empty %}
|
{% if plugins.workzone is not empty %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#plugins" class="WZplugins">
|
<a href="#plugins" class="WZplugins">
|
||||||
<img src="/skins/icons/plugins.png" title="{{ 'phraseanet:: plugin.workzone' | trans }}"/>
|
<img src="/skins/icons/plugins.png" title="{{ 'phraseanet:: plugin.workzone' | trans }}"/>
|
||||||
|
|||||||
@@ -154,18 +154,18 @@
|
|||||||
{{ 'action : publier' | trans }}
|
{{ 'action : publier' | trans }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if app['plugin.actionbar'].keys() is not empty %}
|
{% if plugins.actionbar is not empty %}
|
||||||
{% for actionId in app['plugin.actionbar'].keys() %}
|
{% for plugin in plugins.actionbar %}
|
||||||
{% for key, action in app['plugin.actionbar'][actionId].getActionBar().push|default([]) %}
|
{% for key, action in plugin.getActionBar().push|default([]) %}
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<a class="results_window {{ action.classes|default('') }}">
|
<a class="results_window {{ action.classes|default('') }}">
|
||||||
{% if action.icon %}
|
{% if action.icon %}
|
||||||
<img src="{{ plugin_asset(app['plugin.actionbar'][actionId].PluginName, action.icon) }}" height="16" width="16"/>
|
<img src="{{ plugin.PluginName, action.icon) }}" height="16" width="16"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% set label = action.label %}
|
{% set label = action.label %}
|
||||||
{% trans label app['plugin.actionbar'][actionId].PluginLocale %}
|
{% trans label plugin.PluginLocale %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user