-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate a webspace specific setting administration interface
- Loading branch information
1 parent
5b7d35b
commit a569388
Showing
17 changed files
with
9,292 additions
and
247 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
File renamed without changes.
34 changes: 17 additions & 17 deletions
34
.../build/admin/main.7825759723a3c825efc7.js → .../build/admin/main.3363ee9cf8305bd45fc8.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ld/admin/main.7825759723a3c825efc7.js.map → ...ld/admin/main.3363ee9cf8305bd45fc8.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.