mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +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
|
||||
{
|
||||
private $supportedAttributes;
|
||||
private $supportedClass;
|
||||
private $supportedClasses;
|
||||
|
||||
/** @var Application */
|
||||
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->supportedAttributes = $attributes;
|
||||
$this->supportedClass = $supportedClass;
|
||||
$this->supportedClasses = is_array($supportedClasses) ? $supportedClasses : [$supportedClasses];
|
||||
|
||||
if (!is_callable([$this, 'isGranted'])) {
|
||||
throw new \LogicException('Subclasses should implement a "isGranted" method');
|
||||
@@ -39,9 +44,10 @@ abstract class BaseVoter implements VoterInterface
|
||||
|
||||
public function supportsClass($class)
|
||||
{
|
||||
$supportedClass = $this->supportedClass;
|
||||
if ($class == $supportedClass || is_subclass_of($class, $supportedClass)) {
|
||||
return true;
|
||||
foreach ($this->supportedClasses as $supportedClass) {
|
||||
if ($class == $supportedClass || is_subclass_of($class, $supportedClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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', [
|
||||
'basket' => $basket,
|
||||
'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);
|
||||
|
||||
/** @var \Closure $filter */
|
||||
$filter = $this->app['plugin.filter_by_authorization'];
|
||||
|
||||
$plugins = [
|
||||
'workzone' => $filter('workzone'),
|
||||
'actionbar' => $filter('actionbar'),
|
||||
];
|
||||
|
||||
return $this->render('prod/index.html.twig', [
|
||||
'module_name' => 'Production',
|
||||
'WorkZone' => new Helper\WorkZone($this->app, $request),
|
||||
@@ -129,6 +137,7 @@ class RootController extends Controller
|
||||
'thesau_json_sbas' => json_encode($sbas),
|
||||
'thesau_json_bas2sbas' => json_encode($bas2sbas),
|
||||
'thesau_languages' => $this->app['locales.available'],
|
||||
'plugins' => $plugins,
|
||||
]);
|
||||
}
|
||||
/**
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Authorization\AuthorizationChecker;
|
||||
use Alchemy\Phrasea\Plugin\PluginManager;
|
||||
use Alchemy\Phrasea\Plugin\Schema\ManifestValidator;
|
||||
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
||||
@@ -57,6 +58,23 @@ class PluginServiceProvider implements ServiceProviderInterface
|
||||
$app['plugin.workzone'] = $app->share(function () {
|
||||
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();
|
||||
|
||||
|
@@ -58,15 +58,13 @@
|
||||
<img src="/skins/icons/delete.png"/>
|
||||
</button>
|
||||
|
||||
{% if app['plugin.workzone.basket.actionbar'].keys() is not empty %}
|
||||
{% for pluginId in app['plugin.workzone.basket.actionbar'].keys() %}
|
||||
{% for key,action in app['plugin.workzone.basket.actionbar'][pluginId].getBasketActionBar() %}
|
||||
{% if plugins['actionbar'] is not empty %}
|
||||
{% for plugin in plugins['actionbar'] %}
|
||||
{% for key, action in plugin.getBasketActionBar() %}
|
||||
{% set label = action.label %}
|
||||
|
||||
<button class="ui-corner-all basket_window {{ action.classes|default('') }}" title="{% trans label app['plugin.workzone.basket.actionbar'][pluginId].PluginLocale %}">
|
||||
<img src="{{ plugin_asset(app['plugin.workzone.basket.actionbar'][pluginId].PluginName,action.icon) }}"/>
|
||||
<button class="ui-corner-all basket_window {{ action.classes|default('') }}" title="{% trans label plugin.PluginLocale %}">
|
||||
<img src="{{ plugin_asset(plugin.PluginName, action.icon) }}"/>
|
||||
</button>
|
||||
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
@@ -160,14 +160,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% 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() %}
|
||||
<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;">
|
||||
@@ -203,8 +195,8 @@
|
||||
{% include 'prod/tab_thesaurus.html.twig' with {has_access_to_module: app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('thesaurus')} %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
<div id="plugins" class="PNB {{ workzone_plugins|length > 1 ? 'multiple-plugin' : 'single-plugin' }}" style="top:52px;">
|
||||
{% for pluginId, plugin in workzone_plugins %}
|
||||
<div id="plugins" class="PNB {{ plugins.workzone|length > 1 ? 'multiple-plugin' : 'single-plugin' }}" style="top:52px;">
|
||||
{% for pluginId, plugin in plugins.workzone %}
|
||||
{% include plugin.getWorkzoneTemplate() with {'app': app, 'plugin_id': pluginId} only %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if workzone_plugins is not empty %}
|
||||
{% if plugins.workzone is not empty %}
|
||||
<li>
|
||||
<a href="#plugins" class="WZplugins">
|
||||
<img src="/skins/icons/plugins.png" title="{{ 'phraseanet:: plugin.workzone' | trans }}"/>
|
||||
|
@@ -154,18 +154,18 @@
|
||||
{{ 'action : publier' | trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% if app['plugin.actionbar'].keys() is not empty %}
|
||||
{% for actionId in app['plugin.actionbar'].keys() %}
|
||||
{% for key, action in app['plugin.actionbar'][actionId].getActionBar().push|default([]) %}
|
||||
{% if plugins.actionbar is not empty %}
|
||||
{% for plugin in plugins.actionbar %}
|
||||
{% for key, action in plugin.getActionBar().push|default([]) %}
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a class="results_window {{ action.classes|default('') }}">
|
||||
{% 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 %}
|
||||
|
||||
{% set label = action.label %}
|
||||
{% trans label app['plugin.actionbar'][actionId].PluginLocale %}
|
||||
{% trans label plugin.PluginLocale %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
Reference in New Issue
Block a user