Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to define security permissions for menu items
- Loading branch information
1 parent
9cb2b44
commit 56f4a82
Showing
10 changed files
with
228 additions
and
11 deletions.
There are no files selected for viewing
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 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 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 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 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 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
20 changes: 20 additions & 0 deletions
20
tests/Configuration/fixtures/configurations/input/admin_180.yml
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,20 @@ | ||
# TEST | ||
# the 'permission' option for menu items is properly parsed | ||
|
||
# CONFIGURATION | ||
easy_admin: | ||
design: | ||
menu: | ||
- label: 'Products' | ||
permission: 'ROLE_PERMISSION_1' | ||
children: | ||
- { entity: 'Product' } | ||
- { entity: 'Product', label: 'Add Product', params: { action: 'new' }, permission: 'ROLE_PERMISSION_2' } | ||
- { label: 'Additional Items' } | ||
- { label: 'Absolute URL', url: 'https://github.com/javiereguiluz/EasyAdminBundle', permission: 'ROLE_PERMISSION_3' } | ||
- { label: 'Categories', entity: 'Category' } | ||
- { label: 'About EasyAdmin', permission: ['ROLE_PERMISSION_4', 'ROLE_PERMISSION_5'] } | ||
|
||
entities: | ||
- AppTestBundle\Entity\UnitTests\Category | ||
- AppTestBundle\Entity\UnitTests\Product |
18 changes: 18 additions & 0 deletions
18
tests/Configuration/fixtures/configurations/output/config_180.yml
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,18 @@ | ||
easy_admin: | ||
design: | ||
menu: | ||
- label: 'Products' | ||
permission: 'ROLE_PERMISSION_1' | ||
children: | ||
- label: 'Product' | ||
permission: null | ||
- label: 'Add Product' | ||
permission: 'ROLE_PERMISSION_2' | ||
- label: 'Additional Items' | ||
permission: null | ||
- label: 'Absolute URL' | ||
permission: 'ROLE_PERMISSION_3' | ||
- label: 'Categories' | ||
permission: null | ||
- label: 'About EasyAdmin' | ||
permission: ['ROLE_PERMISSION_4', 'ROLE_PERMISSION_5'] |
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,36 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Tests\Fixtures\AbstractTestCase; | ||
|
||
class CustomMenuSecurityTest extends AbstractTestCase | ||
{ | ||
protected static $options = ['environment' => 'custom_menu_security']; | ||
|
||
public function testMenuSecurityAsAnonymousUser() | ||
{ | ||
$crawler = $this->requestListView(); | ||
|
||
$this->assertCount(1, $crawler->filter('.sidebar-menu li')); | ||
$this->assertSame('Categories', \trim($crawler->filter('.sidebar-menu li')->text())); | ||
} | ||
|
||
public function testMenuSecurityAsLoggedUser() | ||
{ | ||
static::$client->followRedirects(); | ||
$crawler = static::$client->request('GET', '/admin', [], [], [ | ||
'PHP_AUTH_USER' => 'admin', | ||
'PHP_AUTH_PW' => 'pa$$word', | ||
]); | ||
|
||
$this->assertCount(7, $crawler->filter('.sidebar-menu li')); | ||
$this->assertSame('Products', \trim($crawler->filter('.sidebar-menu li')->eq(0)->filter('span')->eq(0)->text())); | ||
$this->assertSame('Product', \trim($crawler->filter('.sidebar-menu li')->eq(1)->text())); | ||
$this->assertSame('Add Product', \trim($crawler->filter('.sidebar-menu li')->eq(2)->text())); | ||
$this->assertSame('Additional Items', \trim($crawler->filter('.sidebar-menu li')->eq(3)->text())); | ||
$this->assertSame('Absolute URL', \trim($crawler->filter('.sidebar-menu li')->eq(4)->text())); | ||
$this->assertSame('Categories', \trim($crawler->filter('.sidebar-menu li')->eq(5)->text())); | ||
$this->assertSame('About EasyAdmin', \trim($crawler->filter('.sidebar-menu li')->eq(6)->text())); | ||
} | ||
} |
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,84 @@ | ||
# This file cannot import the main ' config.yml' file because it defines its own | ||
# security configuration and 'config.yml' also contains some basic security configuration | ||
# This avoids the following error: | ||
# Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: | ||
# You are not allowed to define new elements for path "security.firewalls". | ||
# Please define all elements for this path in one config file. | ||
|
||
imports: | ||
- { resource: services.yml } | ||
|
||
parameters: | ||
locale: en | ||
database_path: '%kernel.root_dir%/../../../build/test.db' | ||
|
||
framework: | ||
secret: secret | ||
translator: ~ | ||
default_locale: '%locale%' | ||
test: ~ | ||
router: { resource: "%kernel.root_dir%/config/routing_override.yml" } | ||
form: true | ||
validation: { enable_annotations: true } | ||
profiler: | ||
collect: true | ||
session: | ||
storage_id: session.storage.mock_file | ||
|
||
twig: | ||
strict_variables: '%kernel.debug%' | ||
|
||
doctrine: | ||
dbal: | ||
driver: pdo_sqlite | ||
path: '%database_path%' | ||
orm: | ||
auto_generate_proxy_classes: true | ||
auto_mapping: true | ||
mappings: | ||
FunctionalTestEntities: | ||
mapping: true | ||
type: annotation | ||
dir: '%kernel.root_dir%/../AppTestBundle/Entity/FunctionalTests/' | ||
alias: 'FunctionalTests' | ||
prefix: 'AppTestBundle\Entity\FunctionalTests' | ||
is_bundle: false | ||
|
||
security: | ||
encoders: | ||
Symfony\Component\Security\Core\User\User: plaintext | ||
providers: | ||
in_memory: | ||
memory: | ||
users: | ||
admin: | ||
password: 'pa$$word' | ||
roles: [ROLE_USER, ROLE_ADMIN] | ||
role_hierarchy: | ||
ROLE_ADMIN: ['ROLE_BETA'] | ||
firewalls: | ||
main: | ||
pattern: ^/ | ||
anonymous: true | ||
logout: true | ||
http_basic: | ||
provider: in_memory | ||
access_control: | ||
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY } | ||
|
||
easy_admin: | ||
design: | ||
menu: | ||
- label: 'Products' | ||
permission: 'ROLE_BETA' | ||
children: | ||
- { entity: 'Product' } | ||
- { entity: 'Product', label: 'Add Product', params: { action: 'new' }, permission: 'ROLE_ADMIN' } | ||
- { label: 'Additional Items' } | ||
- { label: 'Absolute URL', url: 'https://github.com/javiereguiluz/EasyAdminBundle', permission: ['ROLE_GENERIC_PERMISSION', 'ROLE_USER'] } | ||
- { label: 'Categories', entity: 'Category' } | ||
- { label: 'About EasyAdmin', permission: ['ROLE_ADMIN', 'ROLE_BETA'] } | ||
|
||
entities: | ||
- AppTestBundle\Entity\FunctionalTests\Category | ||
- AppTestBundle\Entity\FunctionalTests\Product |