Browse Source

Merge pull request #3297 from core23/permissions-extension

Handle permissions in admin extension
Oskar Stark 9 years ago
parent
commit
f210d88cec
3 changed files with 25 additions and 0 deletions
  1. 7 0
      Admin/Admin.php
  2. 8 0
      Admin/AdminExtension.php
  3. 10 0
      Admin/AdminExtensionInterface.php

+ 7 - 0
Admin/Admin.php

@@ -2927,6 +2927,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             'list'                    => 'LIST',
         ), $this->getAccessMapping());
 
+        foreach ($this->extensions as $extension) {
+            // TODO: remove method check in next major release
+            if (method_exists($extension, 'getAccessMapping')) {
+                $access = array_merge($access, $extension->getAccessMapping($this));
+            }
+        }
+
         if (!array_key_exists($action, $access)) {
             throw new \InvalidArgumentException(sprintf('Action "%s" could not be found in access mapping. Please make sure your action is defined into your admin class accessMapping property.', $action));
         }

+ 8 - 0
Admin/AdminExtension.php

@@ -115,6 +115,14 @@ abstract class AdminExtension implements AdminExtensionInterface
         return array();
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getAccessMapping(AdminInterface $admin)
+    {
+        return array();
+    }
+
     /**
      * {@inheritdoc}
      */

+ 10 - 0
Admin/AdminExtensionInterface.php

@@ -114,6 +114,16 @@ interface AdminExtensionInterface
      */
     public function getPersistentParameters(AdminInterface $admin);
 
+    /**
+     * Return the controller access mapping.
+     *
+     * @param AdminInterface $admin
+     *
+     * @return array
+     */
+    // TODO: Uncomment in next major release
+    // public function getAccessMapping(AdminInterface $admin);
+
     /**
      * @param AdminInterface $admin
      * @param mixed          $object