Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Security Context #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# PHPUnit
/phpunit.xml
.phpunit.result.cache

# composer
/composer.phar
/composer.lock
/auth.json
/vendor

# IDEs
.idea/*
*.iml
*~

# System files
.DS_Store

# tests
Tests/Application/var
Tests/Application/.env.dev.local
Tests/Application/.env.test.local

# php-cs-fixer
.php_cs.cache

#LocalDocker
docker-compose.yml
.docker
/var

.php-cs-fixer.cache
74 changes: 53 additions & 21 deletions Admin/SecuritytxtAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,72 @@
use Sulu\Bundle\AdminBundle\Exception\NavigationItemNotFoundException;
use Sulu\Bundle\PageBundle\Admin\PageAdmin;
use Sulu\Bundle\WebsiteBundle\Entity\AnalyticsInterface;
use Sulu\Component\Security\Authorization\PermissionTypes;
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;

class SecuritytxtAdmin extends Admin
{
final public const SECURITY_CONTEXT = 'bitexpert.securitytxt';

final public const SECURITYTXT_LIST_KEY = 'securitytxt';
final public const SECURITYTXT_LIST_VIEW = 'app.securitytxt_list';

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

public function configureViews(ViewCollection $viewCollection): void
{
$toolbarActions = [
new ToolbarAction('sulu_admin.add'),
new ToolbarAction('sulu_admin.delete'),
$toolbarActions = [];

if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::ADD)) {
$toolbarActions[] = new ToolbarAction('sulu_admin.add');
}

if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::DELETE)) {
$toolbarActions[] = new ToolbarAction('sulu_admin.delete');
}

if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::VIEW)) {
$viewCollection->add(
$this->viewBuilderFactory
->createFormOverlayListViewBuilder(static::SECURITYTXT_LIST_VIEW, '/securitytxt')
->setResourceKey(Securitytxt::RESOURCE_KEY)
->setListKey(self::SECURITYTXT_LIST_KEY)
->addListAdapters(['table'])
->addAdapterOptions(['table' => ['skin' => 'light']])
->addRouterAttributesToListRequest(['webspace'])
->addRouterAttributesToFormRequest(['webspace'])
->disableSearching()
->setFormKey('securitytxt_details')
->setTabTitle('securitytxt.title')
->setTabOrder(2048)
->addToolbarActions($toolbarActions)
->setParent(PageAdmin::WEBSPACE_TABS_VIEW)
->addRerenderAttribute('webspace')
);
}
}

public function getSecurityContexts()
{
return [
'BitExpert' => [
'Securitytxt' => [
static::SECURITY_CONTEXT => [
PermissionTypes::VIEW,
PermissionTypes::ADD,
PermissionTypes::DELETE,
],
],
],
];
}

$viewCollection->add(
$this->viewBuilderFactory
->createFormOverlayListViewBuilder(static::SECURITYTXT_LIST_VIEW, '/securitytxt')
->setResourceKey(Securitytxt::RESOURCE_KEY)
->setListKey(self::SECURITYTXT_LIST_KEY)
->addListAdapters(['table'])
->addAdapterOptions(['table' => ['skin' => 'light']])
->addRouterAttributesToListRequest(['webspace'])
->addRouterAttributesToFormRequest(['webspace'])
->disableSearching()
->setFormKey('securitytxt_details')
->setTabTitle('securitytxt.title')
->setTabOrder(2048)
->addToolbarActions($toolbarActions)
->setParent(PageAdmin::WEBSPACE_TABS_VIEW)
->addRerenderAttribute('webspace')
);
public function getConfigKey(): ?string
{
return 'bitexpert.securitytxt';
}
}