Implement permission configuration.

This commit is contained in:
David Molineus
2018-12-05 09:52:59 +01:00
parent 91d3786187
commit d7fbc361d7
11 changed files with 396 additions and 3 deletions

View File

@@ -42,7 +42,8 @@
"netzmacht/contao-page-context": "~1.0",
"contao-community-alliance/meta-palettes": "^2.0 || ^1.5",
"menatwork/contao-multicolumnwizard": "^3.2",
"doctrine/cache": "^1.0"
"doctrine/cache": "^1.0",
"codefog/contao-widget_tree_picker": "^2.4"
},
"require-dev": {
"phpcq/all-tasks": "^1.2",

View File

@@ -83,6 +83,24 @@ services:
public: true
arguments:
- '%netzmacht.contao_leaflet.styles%'
-
netzmacht.contao_leaflet.listeners.dca.user:
class: Netzmacht\Contao\Leaflet\Listener\Dca\UserDcaListener
public: true
arguments:
- '@netzmacht.contao_toolkit.dca.manager'
- '@netzmacht.contao_leaflet.layer_label_renderer'
- '@translator'
- '%netzmacht.contao_leaflet.layers%'
-
netzmacht.contao_leaflet.listeners.dca.user_group:
class: Netzmacht\Contao\Leaflet\Listener\Dca\UserGroupDcaListener
public: true
arguments:
- '@netzmacht.contao_toolkit.dca.manager'
- '@netzmacht.contao_leaflet.layer_label_renderer'
- '@translator'
- '%netzmacht.contao_leaflet.layers%'
netzmacht.contao_leaflet.listeners.geo_json_listener:
class: Netzmacht\Contao\Leaflet\Listener\GeoJsonListener

View File

@@ -11,7 +11,7 @@
*/
/*
* Backend module.
* Backend modules
*/
array_insert(
@@ -48,8 +48,9 @@ if (TL_MODE === 'BE') {
$GLOBALS['TL_CSS'][] = 'bundles/netzmachtcontaoleaflet/css/backend_global.css';
}
/*
* Models.
* Models
*/
$GLOBALS['TL_MODELS']['tl_leaflet_control'] = \Netzmacht\Contao\Leaflet\Model\ControlModel::class;
@@ -60,3 +61,12 @@ $GLOBALS['TL_MODELS']['tl_leaflet_marker'] = \Netzmacht\Contao\Leaflet\Model\Ma
$GLOBALS['TL_MODELS']['tl_leaflet_popup'] = \Netzmacht\Contao\Leaflet\Model\PopupModel::class;
$GLOBALS['TL_MODELS']['tl_leaflet_style'] = \Netzmacht\Contao\Leaflet\Model\StyleModel::class;
$GLOBALS['TL_MODELS']['tl_leaflet_vector'] = \Netzmacht\Contao\Leaflet\Model\VectorModel::class;
/*
* Permissions
*/
$GLOBALS['TL_PERMISSIONS'][] = 'leaflet_layers';
$GLOBALS['TL_PERMISSIONS'][] = 'leaflet_layer_permissions';
$GLOBALS['TL_PERMISSIONS'][] = 'leaflet_tables';

View File

@@ -0,0 +1,68 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
use Contao\CoreBundle\DataContainer\PaletteManipulator;
PaletteManipulator::create()
->addLegend('leaflet_legend', 'amg_legend', PaletteManipulator::POSITION_BEFORE)
->addField(
['leaflet_layers', 'leaflet_layer_permissions', 'leaflet_tables'],
'leaflet_legend',
PaletteManipulator::POSITION_APPEND
)
->applyToPalette('extend', 'tl_user')
->applyToPalette('custom', 'tl_user');
$GLOBALS['TL_DCA']['tl_user']['fields']['leaflet_layers'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user']['leaflet_layers'],
'exclude' => true,
'inputType' => 'treePicker',
'eval' => [
'foreignTable' => 'tl_leaflet_layer',
'titleField' => 'title',
'searchField' => 'title',
'managerHref' => 'do=leaflet_layer',
'fieldType' => 'checkbox',
'selectParents' => true,
'multiple' => true,
'pickerCallback' => ['netzmacht.contao_leaflet.listeners.dca.user', 'generateLayersRowLabel']
],
'sql' => 'blob NULL',
];
$GLOBALS['TL_DCA']['tl_user']['fields']['leaflet_tables'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user']['leaflet_tables'],
'exclude' => true,
'inputType' => 'checkbox',
'options' => ['tl_leaflet_style', 'tl_leaflet_icon', 'tl_leaflet_popup'],
'reference' => &$GLOBALS['TL_LANG']['MOD'],
'eval' => [
'multiple' => true,
],
'sql' => 'mediumblob NULL',
];
$GLOBALS['TL_DCA']['tl_user']['fields']['leaflet_layer_permissions'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions'],
'exclude' => true,
'inputType' => 'checkbox',
'options' => ['create', 'edit', 'delete', 'data'],
'reference' => &$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options'],
'eval' => [
'helpwizard' => true,
'multiple' => true,
],
'sql' => 'mediumblob NULL',
];

View File

@@ -0,0 +1,67 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
use Contao\CoreBundle\DataContainer\PaletteManipulator;
PaletteManipulator::create()
->addLegend('leaflet_legend', 'amg_legend', PaletteManipulator::POSITION_BEFORE)
->addField(
['leaflet_layers', 'leaflet_layer_permissions', 'leaflet_tables'],
'leaflet_legend',
PaletteManipulator::POSITION_APPEND
)
->applyToPalette('default', 'tl_user_group');
$GLOBALS['TL_DCA']['tl_user_group']['fields']['leaflet_layers'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layers'],
'exclude' => true,
'inputType' => 'treePicker',
'eval' => [
'foreignTable' => 'tl_leaflet_layer',
'titleField' => 'title',
'searchField' => 'title',
'managerHref' => 'do=leaflet_layer',
'fieldType' => 'checkbox',
'selectParents' => true,
'multiple' => true,
'pickerCallback' => ['netzmacht.contao_leaflet.listeners.dca.user_group', 'generateLayersRowLabel']
],
'sql' => 'blob NULL',
];
$GLOBALS['TL_DCA']['tl_user_group']['fields']['leaflet_tables'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user_group']['leaflet_tables'],
'exclude' => true,
'inputType' => 'checkbox',
'options' => ['tl_leaflet_style', 'tl_leaflet_icon', 'tl_leaflet_popup'],
'reference' => &$GLOBALS['TL_LANG']['MOD'],
'eval' => [
'multiple' => true,
],
'sql' => 'mediumblob NULL',
];
$GLOBALS['TL_DCA']['tl_user_group']['fields']['leaflet_layer_permissions'] = [
'label' => &$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions'],
'exclude' => true,
'inputType' => 'checkbox',
'options' => ['create', 'edit', 'delete', 'data'],
'reference' => &$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options'],
'eval' => [
'helpwizard' => true,
'multiple' => true,
],
'sql' => 'mediumblob NULL',
];

View File

@@ -22,6 +22,8 @@ $GLOBALS['TL_LANG']['MOD']['leaflet_about'][1] = 'About the Leaflet integration
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_map'] = 'Maps';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_layer'] = 'Layers';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_icon'] = 'Icons';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_style'] = 'Styles';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_popup'] = 'Popup';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_marker'] = 'Markers';
$GLOBALS['TL_LANG']['MOD']['tl_leaflet_control'] = 'Controls';

View File

@@ -0,0 +1,31 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
$GLOBALS['TL_LANG']['tl_user']['leaflet_legend'] = 'Leaflet Maps Permissions';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layers'][0] = 'Allowed map layers';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layers'][1] = 'Please choose the allowed map layers.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions'][0] = 'Layer permissions';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions'][1] = 'Please choose which permissions are allowed for the map layer.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_tables'][0] = 'Allows map tables';
$GLOBALS['TL_LANG']['tl_user']['leaflet_tables'][1] = 'Please choose which tables are allowed.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['create'][0] = 'Create layers';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['create'][1] = 'Grant permission to create new layers.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['edit'][0] = 'Edit layers';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['edit'][1] = 'Grant permission to edit layers.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['delete'][0] = 'Delete layers';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['delete'][1] = 'Grant permission to delete layers.';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['data'][0] = 'Edit data';
$GLOBALS['TL_LANG']['tl_user']['leaflet_layer_permissions_options']['data'][1] = 'Grant permission to edit data of a layer.';

View File

@@ -0,0 +1,31 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_legend'] = 'Leaflet Maps Permissions';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layers'][0] = 'Allowed map layers';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layers'][1] = 'Please choose the allowed map layers.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions'][0] = 'Layer permissions';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions'][1] = 'Please choose which permissions are allowed for the map layer.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_tables'][0] = 'Allows map tables';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_tables'][1] = 'Please choose which tables are allowed.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['create'][0] = 'Create layers';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['create'][1] = 'Grant permission to create new layers.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['edit'][0] = 'Edit layers';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['edit'][1] = 'Grant permission to edit layers.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['delete'][0] = 'Delete layers';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['delete'][1] = 'Grant permission to delete layers.';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['data'][0] = 'Edit data';
$GLOBALS['TL_LANG']['tl_user_group']['leaflet_layer_permissions_options']['data'][1] = 'Grant permission to edit data of a layer.';

View File

@@ -0,0 +1,109 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
use Contao\Image;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\LayerLabelRenderer;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Toolkit\Dca\Listener\AbstractListener;
use Netzmacht\Contao\Toolkit\Dca\Manager;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class AbstractUserDcaListener
*/
abstract class AbstractUserDcaListener extends AbstractListener
{
/**
* Layer label renderer.
*
* @var LayerLabelRenderer
*/
private $labelRenderer;
/**
* Translator.
*
* @var Translator
*/
private $translator;
/**
* Layers definitions.
*
* @var array
*/
private $layers;
/**
* Constructor.
*
* @param Manager $dcaManager Dca manager.
* @param LayerLabelRenderer $labelRenderer Layer label renderer.
* @param Translator $translator Translator.
* @param array $layers Layers definition.
*/
public function __construct(
Manager $dcaManager,
LayerLabelRenderer $labelRenderer,
Translator $translator,
array $layers
) {
parent::__construct($dcaManager);
$this->labelRenderer = $labelRenderer;
$this->translator = $translator;
$this->layers = $layers;
}
/**
* Generate the layers row label.
*
* @param array $row Layer data row.
*
* @return string
*/
public function generateLayersRowLabel(array $row): string
{
if (!empty($this->layers[$row['type']]['icon'])) {
$src = $this->layers[$row['type']]['icon'];
} else {
$src = 'iconPLAIN.gif';
}
$activeIcon = $src;
$disabledIcon = preg_replace('/(\.[^\.]+)$/', '_1$1', $src);
if (!$row['active']) {
$src = $disabledIcon;
}
$alt = $this->getFormatter(LayerModel::getTable())->formatValue('type', $row['type']);
$attributes = sprintf(
'class="list-icon" title="%s" data-icon="%s" data-icon-disabled="%s"',
StringUtil::specialchars(strip_tags($alt)),
$activeIcon,
$disabledIcon
);
$label = $this->getFormatter(LayerModel::getTable())->formatValue('title', $row['title']);
$label .= sprintf(' <span class="tl_gray">[ID %s]</span>', $row['id']);
$icon = Image::getHtml($src, $alt, $attributes);
$label = $this->labelRenderer->render($row, $label, $this->translator);
return $icon . ' ' . $label;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
/**
* Class UserDcaListener
*/
final class UserDcaListener extends AbstractUserDcaListener
{
/**
* Data container name.
*
* @var string
*/
protected static $name = 'tl_user';
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
/**
* Class UserGroupDcaListener
*/
final class UserGroupDcaListener extends AbstractUserDcaListener
{
/**
* Data container name.
*
* @var string
*/
protected static $name = 'tl_user_group';
}