Browse Source

Merge remote-tracking branch 'origin/2.2'

Conflicts:
	Resources/doc/reference/installation.rst
	Resources/public/Admin.js
Thomas Rabaix 10 years ago
parent
commit
39dfabdd1b

+ 8 - 8
Controller/CRUDController.php

@@ -664,10 +664,6 @@ class CRUDController extends Controller
      */
     public function historyAction($id = null)
     {
-        if (false === $this->admin->isGranted('EDIT')) {
-            throw new AccessDeniedException();
-        }
-
         $id = $this->get('request')->get($this->admin->getIdParameter());
 
         $object = $this->admin->getObject($id);
@@ -676,6 +672,10 @@ class CRUDController extends Controller
             throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
         }
 
+        if (false === $this->admin->isGranted('EDIT', $object)) {
+            throw new AccessDeniedException();
+        }
+
         $manager = $this->get('sonata.admin.audit.manager');
 
         if (!$manager->hasReader($this->admin->getClass())) {
@@ -706,10 +706,6 @@ class CRUDController extends Controller
      */
     public function historyViewRevisionAction($id = null, $revision = null)
     {
-        if (false === $this->admin->isGranted('EDIT')) {
-            throw new AccessDeniedException();
-        }
-
         $id = $this->get('request')->get($this->admin->getIdParameter());
 
         $object = $this->admin->getObject($id);
@@ -718,6 +714,10 @@ class CRUDController extends Controller
             throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
         }
 
+        if (false === $this->admin->isGranted('EDIT', $object)) {
+            throw new AccessDeniedException();
+        }
+
         $manager = $this->get('sonata.admin.audit.manager');
 
         if (!$manager->hasReader($this->admin->getClass())) {

+ 1 - 0
Resources/doc/reference/field_types.rst

@@ -11,6 +11,7 @@ There are many field types that can be used in the list action or show action :
 * **date**: display a formatted date. Accepts an optional ``format`` parameter
 * **datetime**: display a formatted date and time. Accepts an optional ``format`` parameter
 * **text**: display a text
+* **textarea**: display a textarea
 * **trans**: translate the value with a provided ``catalogue`` option
 * **string**: display a text
 * **number**: display a number

+ 1 - 1
Resources/doc/reference/installation.rst

@@ -45,7 +45,7 @@ Besides the storage layer mentioned on step 2, there are other bundles needed
 for SonataAdminBundle to work:
 
     - `SonataBlockBundle <http://sonata-project.org/bundles/block/master/doc/reference/installation.html>`_
-    - `KnpMenuBundle <https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md#installation>`_ (Version 1.1.*)
+    - `KnpMenuBundle <https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md#installation>`_ (Version 2.*)
 
 These bundles are automatically downloaded by composer as a dependency of SonataAdminBundle.
 However, you have to enable them in your ``AppKernel.php``, and configure them manually. Don't

+ 1 - 1
Resources/public/Admin.js

@@ -12,7 +12,7 @@
 jQuery(document).ready(function() {
     jQuery('html').removeClass('no-js');
     if (window.SONATA_CONFIG && window.SONATA_CONFIG.CONFIRM_EXIT) {
-        jQuery('.sonata-ba-form form').each( function () { $(this).confirmExit(); } );
+        jQuery('.sonata-ba-form form').each(function () { $(this).confirmExit(); });
     }
 
     Admin.setup_per_page_switcher(document);

+ 9 - 5
Resources/views/CRUD/base_list_field.html.twig

@@ -10,13 +10,17 @@ file that was distributed with this source code.
 #}
 
 <td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}">
+    {% set route = field_description.options.route.name|default(null) %}
+    {% set action = route == 'show' ? 'VIEW' : route|upper %}
+
     {% if
-            field_description.options.identifier is defined
-        and field_description.options.route is defined
-        and admin.isGranted(field_description.options.route.name == 'show' ? 'VIEW' : field_description.options.route.name|upper, object)
-        and admin.hasRoute(field_description.options.route.name)
+        field_description.options.identifier is defined
+        and route
+        and action
+        and admin.hasRoute(route)
+        and admin.isGranted(action, action in ['VIEW', 'EDIT'] ? object : null)
     %}
-        <a class="sonata-link-identifier" href="{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}">
+        <a class="sonata-link-identifier" href="{{ admin.generateObjectUrl(route, object, field_description.options.route.parameters) }}">
             {%- block field %}{{ value }}{% endblock -%}
         </a>
     {% else %}

+ 8 - 10
Tests/Controller/CRUDControllerTest.php

@@ -1744,6 +1744,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
     {
         $this->setExpectedException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
 
+        $this->admin->expects($this->any())
+            ->method('getObject')
+            ->will($this->returnValue(new \StdClass()));
+
         $this->admin->expects($this->once())
             ->method('isGranted')
             ->with($this->equalTo('EDIT'))
@@ -1756,11 +1760,6 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
     {
         $this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
 
-        $this->admin->expects($this->once())
-            ->method('isGranted')
-            ->with($this->equalTo('EDIT'))
-            ->will($this->returnValue(true));
-
         $this->admin->expects($this->once())
             ->method('getObject')
             ->will($this->returnValue(false));
@@ -2088,6 +2087,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
     {
         $this->setExpectedException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
 
+        $this->admin->expects($this->any())
+            ->method('getObject')
+            ->will($this->returnValue(new \StdClass()));
+
         $this->admin->expects($this->once())
             ->method('isGranted')
             ->with($this->equalTo('EDIT'))
@@ -2102,11 +2105,6 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
 
         $this->request->query->set('id', 123);
 
-        $this->admin->expects($this->once())
-            ->method('isGranted')
-            ->with($this->equalTo('EDIT'))
-            ->will($this->returnValue(true));
-
         $this->admin->expects($this->once())
             ->method('getObject')
             ->will($this->returnValue(false));

+ 2 - 2
Validator/InlineValidator.php

@@ -13,8 +13,8 @@ namespace Sonata\AdminBundle\Validator;
 use Symfony\Component\Validator\ConstraintValidator;
 use Symfony\Component\Validator\Constraint;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory;
 use Sonata\AdminBundle\Validator\ErrorElement;
+use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
 
 class InlineValidator extends ConstraintValidator
 {
@@ -24,7 +24,7 @@ class InlineValidator extends ConstraintValidator
      * @param \Symfony\Component\DependencyInjection\ContainerInterface            $container
      * @param \Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory $constraintValidatorFactory
      */
-    public function __construct(ContainerInterface $container, ConstraintValidatorFactory $constraintValidatorFactory)
+    public function __construct(ContainerInterface $container, ConstraintValidatorFactoryInterface $constraintValidatorFactory)
     {
         $this->container                  = $container;
         $this->constraintValidatorFactory = $constraintValidatorFactory;