Skip to content

Commit

Permalink
Merge pull request sonata-project#3687 from greg0ire/2.x
Browse files Browse the repository at this point in the history
Backport 2.3 changes
  • Loading branch information
OskarStark committed Mar 29, 2016
2 parents 4f36f43 + 4e869aa commit 1bcdfcd
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sudo: false

cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache/files
- $HOME/.cache/pip

env:
Expand Down
2 changes: 1 addition & 1 deletion Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
const CONTEXT_MENU = 'menu';
const CONTEXT_DASHBOARD = 'dashboard';

const CLASS_REGEX = '@(?:([A-Za-z0-9]*)\\\)?(Bundle\\\)?([A-Za-z0-9]+)Bundle\\\(Entity|Document|Model|PHPCR|CouchDocument|Phpcr|Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB)\\\(.*)@';
const CLASS_REGEX = '@(?:([A-Za-z0-9]*)\\\)?(Bundle\\\)?([A-Za-z0-9]+?)(?:Bundle)?\\\(Entity|Document|Model|PHPCR|CouchDocument|Phpcr|Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB)\\\(.*)@';

/**
* The class name managed by the admin class.
Expand Down
16 changes: 8 additions & 8 deletions Resources/doc/reference/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The install process is available on the dedicated
Security handlers
-----------------

The security part is managed by a ``SecurityHandler``, the bundle comes with 3 handlers
The security part is managed by a ``SecurityHandler``, the bundle comes with 3 handlers:

- ``sonata.admin.security.handler.role``: ROLES to handle permissions
- ``sonata.admin.security.handler.acl``: ACL and ROLES to handle permissions
Expand Down Expand Up @@ -104,7 +104,7 @@ Configuration

First, activate the role security handler as described above.

Each time an user tries to do an action in the admin, Sonata checks if he is
Each time a user tries to do an action in the admin, Sonata checks if he is
either a super admin (``ROLE_SUPER_ADMIN``) **or** has the permission.

The permissions are:
Expand All @@ -129,7 +129,7 @@ The role name will be based on the name of your admin service. For instance, ``a

If your admin service is named like ``my.blog.admin.foo_bar`` (note the underscore ``_``) it will become: ``ROLE_MY_BLOG_ADMIN_FOO_BAR_{ACTION}``

So our ``security.yml`` file may look to something like this:
So our ``security.yml`` file may look something like this:

.. configuration-block::

Expand Down Expand Up @@ -310,7 +310,7 @@ The following configuration for the SonataUserBundle defines:
- the login form for authentication
- the access control: resources with related required roles, the important
part is the admin configuration
- the ``acl`` option to enable the ACL.
- the ``acl`` option to enable the ACL
- the ``AdminPermissionMap`` defines the permissions of the Admin class

.. configuration-block::
Expand Down Expand Up @@ -459,10 +459,10 @@ Owner:
Vocabulary used for Access Control Lists:

- **Role:** a user role;
- **ACL:** a list of access rules, the Admin uses 2 types:
- **ACL:** a list of access rules, the Admin uses 2 types;
- **Admin ACL:** created from the Security information of the Admin class
for each admin and shares the Access Control Entries that specify what
the user can do (permissions) with the admin
the user can do (permissions) with the admin;
- **Object ACL:** also created from the security information of the ``Admin``
class however created for each object, it uses 2 scopes:

Expand Down Expand Up @@ -497,9 +497,9 @@ In the application the security context is asked if access is granted for a role
or a permission (``admin.isGranted``):

- **Token:** a token identifies a user between requests;
- **Voter:** sort of judge that returns if access is granted of denied, if the
- **Voter:** sort of judge that returns whether access is granted or denied, if the
voter should not vote for a case, it returns abstain;
- **AccessDecisionManager:** decides if access is granted or denied according
- **AccessDecisionManager:** decides whether access is granted or denied according
a specific strategy. It grants access if at least one (affirmative strategy),
all (unanimous strategy) or more then half (consensus strategy) of the
counted votes granted access;
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/empty_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file that was distributed with this source code.
#}

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% extends admin_pool.getTemplate('layout') %}

{% block sonata_header %}{% endblock %}
{% block sonata_left_side %}{% endblock %}
Expand Down
30 changes: 22 additions & 8 deletions Tests/Admin/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ public function provideGetBaseRoutePattern()
'AppBundle\Entity\User',
'/app/user',
),
array(
'App\Entity\User',
'/app/user',
),
);
}

Expand All @@ -454,13 +458,16 @@ public function testGetBaseRoutePattern($objFqn, $expected)
$this->assertSame($expected, $admin->getBaseRoutePattern());
}

public function testGetBaseRoutePatternWithChildAdmin()
/**
* @dataProvider provideGetBaseRoutePattern
*/
public function testGetBaseRoutePatternWithChildAdmin($objFqn, $expected)
{
$postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
$postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
$commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
$commentAdmin->setParent($postAdmin);

$this->assertSame('/sonata/news/post/{id}/comment', $commentAdmin->getBaseRoutePattern());
$this->assertSame($expected.'/{id}/comment', $commentAdmin->getBaseRoutePattern());
}

public function testGetBaseRoutePatternWithSpecifedPattern()
Expand All @@ -484,7 +491,7 @@ public function testGetBaseRoutePatternWithChildAdminAndWithSpecifedPattern()
*/
public function testGetBaseRoutePatternWithUnreconizedClassname()
{
$admin = new PostAdmin('sonata.post.admin.post', 'News\Entity\Post', 'SonataNewsBundle:PostAdmin');
$admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'SonataNewsBundle:PostAdmin');
$admin->getBaseRoutePattern();
}

Expand Down Expand Up @@ -547,6 +554,10 @@ public function provideGetBaseRouteName()
'AppBundle\Entity\User',
'admin_app_user',
),
array(
'App\Entity\User',
'admin_app_user',
),
);
}

Expand All @@ -560,15 +571,18 @@ public function testGetBaseRouteName($objFqn, $expected)
$this->assertSame($expected, $admin->getBaseRouteName());
}

public function testGetBaseRouteNameWithChildAdmin()
/**
* @dataProvider provideGetBaseRouteName
*/
public function testGetBaseRouteNameWithChildAdmin($objFqn, $expected)
{
$routeGenerator = new DefaultRouteGenerator(
$this->getMock('Symfony\Component\Routing\RouterInterface'),
new RoutesCache($this->cacheTempFolder, true)
);

$pathInfo = new \Sonata\AdminBundle\Route\PathInfoBuilder($this->getMock('Sonata\AdminBundle\Model\AuditManagerInterface'));
$postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
$postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
$postAdmin->setRouteBuilder($pathInfo);
$postAdmin->setRouteGenerator($routeGenerator);
$postAdmin->initialize();
Expand All @@ -580,7 +594,7 @@ public function testGetBaseRouteNameWithChildAdmin()

$postAdmin->addChild($commentAdmin);

$this->assertSame('admin_sonata_news_post_comment', $commentAdmin->getBaseRouteName());
$this->assertSame($expected.'_comment', $commentAdmin->getBaseRouteName());

$this->assertTrue($postAdmin->hasRoute('show'));
$this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show'));
Expand All @@ -595,7 +609,7 @@ public function testGetBaseRouteNameWithChildAdmin()
*/
public function testGetBaseRouteNameWithUnreconizedClassname()
{
$admin = new PostAdmin('sonata.post.admin.post', 'News\Entity\Post', 'SonataNewsBundle:PostAdmin');
$admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'SonataNewsBundle:PostAdmin');
$admin->getBaseRouteName();
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/Controller/CoreControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public function testdashboardActionStandardRequest()
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
return $values[$id];
}));

$container->expects($this->any())
->method('has')
->will($this->returnCallback(function ($id) {
if ($id == 'templating') {
return true;
}

return false;
}));

$container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
if ($name == 'sonata.admin.configuration.dashboard_blocks') {
return array();
Expand Down Expand Up @@ -96,6 +107,17 @@ public function testdashboardActionAjaxLayout()
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
return $values[$id];
}));

$container->expects($this->any())
->method('has')
->will($this->returnCallback(function ($id) {
if ($id == 'templating') {
return true;
}

return false;
}));

$container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
if ($name == 'sonata.admin.configuration.dashboard_blocks') {
return array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function testEmbeddedAdmin()
$meta->tags['sonata.admin'][0],
array(
'manager_type' => 'orm',
'group' => 'Admin',
'label' => 'Tests\Fixtures\Foo',
'show_in_dashboard' => false,
)
);
Expand Down
14 changes: 6 additions & 8 deletions Tests/Twig/Extension/SonataAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public function setUp()
$this->environment->addExtension(new RoutingExtension($urlGenerator));
$this->environment->addExtension(new \Twig_Extensions_Extension_Text());

$this->twigExtension->initRuntime($this->environment);

// initialize object
$this->object = new \stdClass();

Expand Down Expand Up @@ -247,7 +245,7 @@ public function testRenderListElement($expected, $type, $value, array $options)
}
}));

$this->assertSame($expected, trim(preg_replace('/\s+/', ' ', $this->twigExtension->renderListElement($this->object, $this->fieldDescription))));
$this->assertSame($expected, trim(preg_replace('/\s+/', ' ', $this->twigExtension->renderListElement($this->environment, $this->object, $this->fieldDescription))));
}

public function getRenderListElementTests()
Expand Down Expand Up @@ -407,7 +405,7 @@ public function testRenderListElementNonExistentTemplate()
->method('warning')
->with(($this->stringStartsWith('An error occured trying to load the template "SonataAdminBundle:CRUD:list_nonexistent_template.html.twig" for the field "Foo_name", the default template "SonataAdminBundle:CRUD:base_list_field.html.twig" was used instead: "Unable to find template "list_nonexistent_template.html.twig')));

$this->twigExtension->renderListElement($this->object, $this->fieldDescription);
$this->twigExtension->renderListElement($this->environment, $this->object, $this->fieldDescription);
}

/**
Expand All @@ -425,7 +423,7 @@ public function testRenderListElementErrorLoadingTemplate()
->method('getTemplate')
->will($this->returnValue('SonataAdminBundle:CRUD:list_nonexistent_template.html.twig'));

$this->twigExtension->renderListElement($this->object, $this->fieldDescription);
$this->twigExtension->renderListElement($this->environment, $this->object, $this->fieldDescription);
}

/**
Expand Down Expand Up @@ -486,7 +484,7 @@ public function testRenderViewElement($expected, $type, $value, array $options)
}
}));

$this->assertSame($expected, trim(preg_replace('/\s+/', ' ', $this->twigExtension->renderViewElement($this->fieldDescription, $this->object))));
$this->assertSame($expected, trim(preg_replace('/\s+/', ' ', $this->twigExtension->renderViewElement($this->environment, $this->fieldDescription, $this->object))));
}

public function getRenderViewElementTests()
Expand Down Expand Up @@ -702,11 +700,11 @@ public function testOutput()
$template = $this->environment->loadTemplate('SonataAdminBundle:CRUD:base_list_field.html.twig');

$this->assertSame('<td class="sonata-ba-list-field sonata-ba-list-field-" objectId="12345"> foo </td>',
trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters))));
trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters, $this->environment))));

$this->environment->enableDebug();
$this->assertSame('<!-- START fieldName: fd_name template: SonataAdminBundle:CRUD:base_list_field.html.twig compiled template: SonataAdminBundle:CRUD:base_list_field.html.twig --> <td class="sonata-ba-list-field sonata-ba-list-field-" objectId="12345"> foo </td> <!-- END - fieldName: fd_name -->',
trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters))));
trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters, $this->environment))));
}

public function testRenderRelationElementNoObject()
Expand Down
Loading

0 comments on commit 1bcdfcd

Please sign in to comment.