Skip to content

Commit

Permalink
Integrate a webspace specific setting administration interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jan 30, 2023
1 parent 5b7d35b commit a569388
Show file tree
Hide file tree
Showing 17 changed files with 9,292 additions and 247 deletions.
8,984 changes: 8,984 additions & 0 deletions assets/admin/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>application_settings</key>
<key>webspace_setting_details</key>

<properties>
<property name="demobarText" type="text_line">
Expand Down
5 changes: 0 additions & 5 deletions config/packages/app_application_settings_admin.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions config/packages/app_webspace_setting_admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sulu_admin:
resources:
webspace_settings:
routes:
detail: 'app.get_webspace_settings'

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/build/admin/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"main.css": "/build/admin/main.7825759723a3c825efc7.css",
"main.js": "/build/admin/main.7825759723a3c825efc7.js",
"main.js.map": "/build/admin/main.7825759723a3c825efc7.js.map",
"main.css": "/build/admin/main.3363ee9cf8305bd45fc8.css",
"main.js": "/build/admin/main.3363ee9cf8305bd45fc8.js",
"main.js.map": "/build/admin/main.3363ee9cf8305bd45fc8.js.map",
"build/admin/fonts/fa-brands-400.woff": "/build/admin/fonts/fa-brands-400.2285773e6b4b172f07d9b777c81b0775.woff",
"build/admin/fonts/fa-brands-400.eot": "/build/admin/fonts/fa-brands-400.23f19bb08961f37aaf692ff943823453.eot",
"build/admin/fonts/fa-brands-400.svg": "/build/admin/fonts/fa-brands-400.2f517e09eb2ca6650ff5bec5a95157ab.svg",
Expand Down
81 changes: 0 additions & 81 deletions src/Admin/ApplicationSettingsAdmin.php

This file was deleted.

125 changes: 125 additions & 0 deletions src/Admin/WebspaceSettingAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

declare(strict_types=1);

namespace App\Admin;

use App\Entity\WebspaceSetting;
use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction;
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
use Sulu\Bundle\PageBundle\Admin\PageAdmin;
use Sulu\Component\Security\Authorization\PermissionTypes;
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;
use Sulu\Component\Webspace\Webspace;

class WebspaceSettingAdmin extends Admin
{
public const TAB_VIEW = 'app.webspace_settings';
public const FORM_VIEW = 'app.webspace_settings.form';
public const FORM_KEY = 'webspace_setting_details';


public function __construct(
private WebspaceManagerInterface $webspaceManager,
private ViewBuilderFactoryInterface $viewBuilderFactory,
private SecurityCheckerInterface $securityChecker
) {
}

public function configureViews(ViewCollection $viewCollection): void
{
if ($this->hasSomeWebspaceSettingPermission()) {
$viewCollection->add(
// sulu will only load the existing entity if the path of the form includes an id attribute
$this->viewBuilderFactory->createResourceTabViewBuilder(static::TAB_VIEW, '/webspace-settings/:id')
->setResourceKey(WebspaceSetting::RESOURCE_KEY)
->setTabTitle('app.webspace_settings')
->setParent(PageAdmin::WEBSPACE_TABS_VIEW)
->setOption('routerAttributesToFormRequest', ['webspace'])
->setTabOrder(8096)
->setAttributeDefault('id', '-')
);

$viewCollection->add(
$this->viewBuilderFactory->createFormViewBuilder(static::FORM_VIEW, '/details')
->setResourceKey(WebspaceSetting::RESOURCE_KEY)
->setFormKey(self::FORM_KEY)
->setTabTitle('sulu_admin.details')
->addToolbarActions([new ToolbarAction('sulu_admin.save')])
->addRouterAttributesToFormRequest(['webspace'])
->setParent(static::TAB_VIEW)
);
}
}

public function getSecurityContexts(): array
{
$webspaceContexts = [];
/* @var Webspace $webspace */
foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
$securityContextKey = self::getWebspaceSettingSecurityContext($webspace->getKey());
$webspaceContexts[$securityContextKey] = $this->getSecurityContextPermissions();
}

return [
self::SULU_ADMIN_SECURITY_SYSTEM => [
'Webspaces' => $webspaceContexts,
],
];
}

public function getSecurityContextsWithPlaceholder(): array
{
return [
self::SULU_ADMIN_SECURITY_SYSTEM => [
'Webspaces' => [
self::getWebspaceSettingSecurityContext('#webspace#') => $this->getSecurityContextPermissions(),
],
],
];
}

/**
* Returns security context for settings in given webspace.
*
* @final
*
* @param string $webspaceKey
*
* @return string
*/
public static function getWebspaceSettingSecurityContext($webspaceKey): string
{
return \sprintf('%s%s.%s', PageAdmin::SECURITY_CONTEXT_PREFIX, $webspaceKey, 'settings');
}

/**
* @return string[]
*/
private function getSecurityContextPermissions(): array
{
return [
PermissionTypes::VIEW,
PermissionTypes::EDIT,
];
}

private function hasSomeWebspaceSettingPermission(): bool
{
foreach ($this->webspaceManager->getWebspaceCollection()->getWebspaces() as $webspace) {
$hasWebspaceAnalyticsPermission = $this->securityChecker->hasPermission(
self::getWebspaceSettingSecurityContext($webspace->getKey()),
PermissionTypes::EDIT
);

if ($hasWebspaceAnalyticsPermission) {
return true;
}
}

return false;
}
}
86 changes: 0 additions & 86 deletions src/Controller/Admin/ApplicationSettingsController.php

This file was deleted.

Loading

0 comments on commit a569388

Please sign in to comment.