diff --git a/src/Resources/views/includes/_include_embedded_list.html.twig b/src/Resources/views/includes/_include_embedded_list.html.twig
index fc2353ec..04a22812 100644
--- a/src/Resources/views/includes/_include_embedded_list.html.twig
+++ b/src/Resources/views/includes/_include_embedded_list.html.twig
@@ -1,6 +1,7 @@
-{% set action_params = { entity: entity, action: 'embeddedList', filters: filters } %}
+{% set action_params = { (object_type): object, action: 'embeddedList', filters: filters } %}
+
{% if sort is not null %}
{% set action_params = action_params|merge({ sortField: sort.field, sortDirection: sort.direction}) %}
{% endif %}
-{{ render(path('easyadmin', action_params)) }}
+{{ render(easyadmin_path(action_params)) }}
diff --git a/src/Security/AdminAuthorizationChecker.php b/src/Security/AdminAuthorizationChecker.php
index c73a0661..a3cb26b9 100644
--- a/src/Security/AdminAuthorizationChecker.php
+++ b/src/Security/AdminAuthorizationChecker.php
@@ -17,13 +17,13 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker,
}
/**
- * Throws an error if user has no access to the entity action.
+ * Throws an error if user has no access to the object action.
*
- * @param array $entityConfig
+ * @param array $objectConfig
* @param string $actionName
* @param mixed $subject
*/
- public function checksUserAccess(array $entityConfig, string $actionName, $subject = null)
+ public function checksUserAccess(array $objectConfig, string $actionName, $subject = null)
{
if ($this->adminMinimumRole && !$this->authorizationChecker->isGranted($this->adminMinimumRole)) {
throw new AccessDeniedException(
@@ -31,11 +31,11 @@ public function checksUserAccess(array $entityConfig, string $actionName, $subje
);
}
- $requiredRole = $this->getRequiredRole($entityConfig, $actionName);
+ $requiredRole = $this->getRequiredRole($objectConfig, $actionName);
if ($requiredRole && !$this->authorizationChecker->isGranted($requiredRole, $subject)) {
throw new AccessDeniedException(
- \sprintf('You must be granted %s role to perform this entity action !', $requiredRole)
+ \sprintf('You must be granted %s role to perform this object action !', $requiredRole)
);
}
}
@@ -43,16 +43,16 @@ public function checksUserAccess(array $entityConfig, string $actionName, $subje
/**
* Returns user access as boolean, no exception thrown.
*
- * @param array $entityConfig
+ * @param array $objectConfig
* @param string $actionName
* @param mixed $subject
*
* @return bool
*/
- public function isEasyAdminGranted(array $entityConfig, string $actionName, $subject = null)
+ public function isEasyAdminGranted(array $objectConfig, string $actionName, $subject = null)
{
try {
- $this->checksUserAccess($entityConfig, $actionName, $subject);
+ $this->checksUserAccess($objectConfig, $actionName, $subject);
} catch (AccessDeniedException $e) {
return false;
}
@@ -60,17 +60,17 @@ public function isEasyAdminGranted(array $entityConfig, string $actionName, $sub
return true;
}
- protected function getRequiredRole(array $entityConfig, string $actionName)
+ protected function getRequiredRole(array $objectConfig, string $actionName)
{
// Prevent from security breach: role for 'list' action was not required for 'List' nor 'LIST'...
$actionName = \strtolower($actionName);
- if (isset($entityConfig[$actionName]) && isset($entityConfig[$actionName]['role'])) {
- return $entityConfig[$actionName]['role'];
- } elseif (isset($entityConfig['role_prefix'])) {
- return $entityConfig['role_prefix'].'_'.\strtoupper($actionName);
+ if (isset($objectConfig[$actionName]) && isset($objectConfig[$actionName]['role'])) {
+ return $objectConfig[$actionName]['role'];
+ } elseif (isset($objectConfig['role_prefix'])) {
+ return $objectConfig['role_prefix'].'_'.\strtoupper($actionName);
}
- return $entityConfig['role'] ?? null;
+ return $objectConfig['role'] ?? null;
}
}
diff --git a/src/Twig/AdminAuthorizationExtension.php b/src/Twig/AdminAuthorizationExtension.php
index 12776dc7..18f4ef62 100644
--- a/src/Twig/AdminAuthorizationExtension.php
+++ b/src/Twig/AdminAuthorizationExtension.php
@@ -39,22 +39,23 @@ public function getFunctions()
];
}
- public function isEasyAdminGranted(array $entityConfig, string $actionName = 'list', $subject = null)
+ public function isEasyAdminGranted(array $objectConfig, string $actionName = 'list', $subject = null)
{
- return $this->adminAuthorizationChecker->isEasyAdminGranted($entityConfig, $actionName, $subject);
+ return $this->adminAuthorizationChecker->isEasyAdminGranted($objectConfig, $actionName, $subject);
}
public function pruneItemsActions(
- array $itemActions, array $entityConfig, array $forbiddenActions = [], $subject = null
+ array $itemActions, array $objectConfig, array $forbiddenActions = [], $subject = null
) {
- return \array_filter($itemActions, function ($action) use ($entityConfig, $forbiddenActions, $subject) {
+ return \array_filter($itemActions, function ($action) use ($objectConfig, $forbiddenActions, $subject) {
return !\in_array($action, $forbiddenActions)
- && $this->isEasyAdminGranted($entityConfig, $action, $subject);
+ && $this->isEasyAdminGranted($objectConfig, $action, $subject)
+ ;
}, ARRAY_FILTER_USE_KEY);
}
- public function pruneMenuItems(array $menuConfig, array $entitiesConfig)
+ public function pruneMenuItems(array $menuConfig, array $objectsConfig)
{
- return $this->menuHelper->pruneMenuItems($menuConfig, $entitiesConfig);
+ return $this->menuHelper->pruneMenuItems($menuConfig, $objectsConfig);
}
}
diff --git a/src/Twig/EasyAdminExtensionTwigExtension.php b/src/Twig/EasyAdminExtensionTwigExtension.php
new file mode 100644
index 00000000..a6cacceb
--- /dev/null
+++ b/src/Twig/EasyAdminExtensionTwigExtension.php
@@ -0,0 +1,176 @@
+entityConfigManager = $entityConfigManager;
+ $this->mongoOdmConfigManager = $mongoOdmConfigManager;
+ $this->router = $router;
+ }
+
+ public function getFunctions()
+ {
+ return [
+ new TwigFunction('easyadmin_object', [$this, 'getObjectConfiguration']),
+ new TwigFunction('easyadmin_object_type', [$this, 'getObjectType']),
+ new TwigFunction('easyadmin_path', [$this, 'getEasyAdminPath']),
+ new TwigFunction('easyadmin_object_twig_path', [$this, 'getTwigPath']),
+ new TwigFunction('easyadmin_object_base_twig_path', [$this, 'getBaseTwigPath']),
+ new TwigFunction('easyadmin_object_get_actions_for_*_item', [$this, 'getActionsForItem'], ['needs_environment' => true]),
+ new TwigFunction('easyadmin_object_render_field_for_*_view', [$this, 'renderObjectField'], ['is_safe' => ['html'], 'needs_environment' => true]),
+ ];
+ }
+
+ public function getActionsForItem(
+ \Twig_Environment $twig, string $view, string $objectType, string $objectName
+ ) {
+ if ('document' === $objectType && $twig->getFunction('easyadmin_mongo_odm_get_actions_for_*_item')) {
+ $function = $twig->getFunction('easyadmin_mongo_odm_get_actions_for_*_item');
+ } else {
+ $function = $twig->getFunction('easyadmin_get_actions_for_*_item');
+ }
+
+ return \call_user_func($function->getCallable(), $view, $objectName);
+ }
+
+ public function renderObjectField(
+ \Twig_Environment $twig, string $view, string $objectType, string $objectName, $item, array $fieldMetadata
+ ) {
+ if ('document' === $objectType && $twig->getFunction('easyadmin_mongo_odm_render_field_for_*_view')) {
+ $function = $twig->getFunction('easyadmin_mongo_odm_render_field_for_*_view');
+ } else {
+ $function = $twig->getFunction('easyadmin_render_field_for_*_view');
+ }
+
+ return \call_user_func($function->getCallable(), $twig, $view, $objectName, $item, $fieldMetadata);
+ }
+
+ /**
+ * Returns the namespaced Twig path.
+ *
+ * @param Request $request
+ * @param string $path
+ *
+ * @return string
+ */
+ public function getTwigPath(Request $request, string $path)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return \sprintf('@EasyAdmin/%s', $path);
+ } elseif ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return \sprintf('@EasyAdminMongoOdm/%s', $path);
+ }
+
+ // Fallback not entity/document admin pages based on EasyAdmin layout ?
+ return \sprintf('@EasyAdmin/%s', $path);
+ }
+
+ /**
+ * Returns the namespaced base Twig path.
+ *
+ * @param Request $request
+ * @param string $path
+ *
+ * @return string
+ */
+ public function getBaseTwigPath(Request $request, string $path)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return \sprintf('@BaseEasyAdmin/%s', $path);
+ } elseif ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return \sprintf('@BaseEasyAdminMongoOdm/%s', $path);
+ }
+
+ // Fallback not entity/document admin pages based on EasyAdmin layout ?
+ return \sprintf('@BaseEasyAdmin/%s', $path);
+ }
+
+ /**
+ * Returns the entire configuration of the given object.
+ *
+ * @param Request $request
+ *
+ * @return array|null
+ */
+ public function getObjectConfiguration(Request $request)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return $this->entityConfigManager->getEntityConfig($request->query->get('entity'));
+ }
+
+ if (null === $this->mongoOdmConfigManager) {
+ return null;
+ }
+
+ if ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return $this->mongoOdmConfigManager->getDocumentConfig($request->query->get('document'));
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the given object type.
+ *
+ * @param Request $request
+ *
+ * @return string|null
+ */
+ public function getObjectType(Request $request)
+ {
+ $requestRoute = $request->attributes->get('_route');
+
+ if ('easyadmin' === $requestRoute && $request->query->has('entity')) {
+ return 'entity';
+ }
+
+ if (null === $this->mongoOdmConfigManager) {
+ return null;
+ }
+
+ if ('easyadmin_mongo_odm' === $requestRoute && $request->query->has('document')) {
+ return 'document';
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns easyadmin path for given parameters.
+ *
+ * @param array $parameters
+ *
+ * @return string
+ */
+ public function getEasyAdminPath(array $parameters)
+ {
+ if (\array_key_exists('entity', $parameters)) {
+ return $this->router->generate('easyadmin', $parameters);
+ } elseif (\array_key_exists('document', $parameters)) {
+ return $this->router->generate('easyadmin_mongo_odm', $parameters);
+ }
+
+ throw new \RuntimeException('Parameters must contain either "entity" or "document" key !');
+ }
+}
diff --git a/src/Twig/EmbeddedListExtension.php b/src/Twig/EmbeddedListExtension.php
index 453d5de1..f7d7be6e 100644
--- a/src/Twig/EmbeddedListExtension.php
+++ b/src/Twig/EmbeddedListExtension.php
@@ -42,8 +42,8 @@ public function getEmbeddedListIdentifier(string $requestUri)
return \md5($requestUri);
}
- public function guessDefaultFilters(string $entityFqcn, string $parentEntityProperty, $parentEntity)
+ public function guessDefaultFilters(string $objectFqcn, string $parentObjectProperty, $parentObject)
{
- return $this->embeddedListHelper->guessDefaultFilter($entityFqcn, $parentEntityProperty, $parentEntity);
+ return $this->embeddedListHelper->guessDefaultFilter($objectFqcn, $parentObjectProperty, $parentObject);
}
}
diff --git a/tests/Configuration/CustomFormTypeConfigPassTest.php b/tests/Configuration/CustomFormTypeConfigPassTest.php
index 1edaa3e8..976a6c62 100644
--- a/tests/Configuration/CustomFormTypeConfigPassTest.php
+++ b/tests/Configuration/CustomFormTypeConfigPassTest.php
@@ -27,6 +27,16 @@ public function testCustomFormTypesAreReplaced()
]],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'form' => ['fields' => ['testField1' => ['type' => 'foo']]],
+ 'edit' => ['fields' => ['testField2' => ['type' => 'bar']]],
+ 'new' => ['fields' => [
+ 'testField1' => ['type' => 'foo'],
+ 'testField2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
];
$backendConfig = $shortFormTypeConfigPass->process($backendConfig);
@@ -52,6 +62,26 @@ public function testCustomFormTypesAreReplaced()
],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'form' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\FooType'],
+ ],
+ ],
+ 'edit' => [
+ 'fields' => [
+ 'testField2' => ['type' => 'AppBundle\Form\Type\BarType'],
+ ],
+ ],
+ 'new' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\FooType'],
+ 'testField2' => ['type' => 'AppBundle\Form\Type\BarType'],
+ ],
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
@@ -75,6 +105,14 @@ public function testLegacyShortFormTypesAreReplaced()
]],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'new' => ['fields' => [
+ 'testField1' => ['type' => 'text'],
+ 'testField2' => ['type' => 'choice'],
+ ]],
+ ],
+ ],
];
$backendConfig = $shortFormTypeConfigPass->process($backendConfig);
@@ -90,6 +128,16 @@ public function testLegacyShortFormTypesAreReplaced()
],
],
],
+ 'documents' => [
+ 'TestDocument' => [
+ 'new' => [
+ 'fields' => [
+ 'testField1' => ['type' => 'AppBundle\Form\Type\TextType'],
+ 'testField2' => ['type' => ChoiceType::class],
+ ],
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
diff --git a/tests/Configuration/EmbeddedListViewConfigPassTest.php b/tests/Configuration/EmbeddedListViewConfigPassTest.php
index 90c929c3..bbd02741 100644
--- a/tests/Configuration/EmbeddedListViewConfigPassTest.php
+++ b/tests/Configuration/EmbeddedListViewConfigPassTest.php
@@ -21,6 +21,16 @@ public function testOpenNewTabOption()
'embeddedList' => ['open_new_tab' => false],
],
],
+ 'documents' => [
+ 'NotSetDocument' => [
+ ],
+ 'SetTrueDocument' => [
+ 'embeddedList' => ['open_new_tab' => true],
+ ],
+ 'SetFalseDocument' => [
+ 'embeddedList' => ['open_new_tab' => false],
+ ],
+ ],
];
$backendConfig = $embeddedListViewConfigPass->process($backendConfig);
@@ -43,6 +53,23 @@ public function testOpenNewTabOption()
],
],
],
+ 'documents' => [
+ 'NotSetDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => true,
+ ],
+ ],
+ 'SetTrueDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => true,
+ ],
+ ],
+ 'SetFalseDocument' => [
+ 'embeddedList' => [
+ 'open_new_tab' => false,
+ ],
+ ],
+ ],
];
$this->assertSame($backendConfig, $expectedBackendConfig);
diff --git a/tests/Configuration/ListFormFiltersConfigPassTest.php b/tests/Configuration/ListFormFiltersConfigPassTest.php
new file mode 100644
index 00000000..3c5ebc94
--- /dev/null
+++ b/tests/Configuration/ListFormFiltersConfigPassTest.php
@@ -0,0 +1,62 @@
+createMock(ManagerRegistry::class);
+
+ $listFormFiltersConfigPass = new ListFormFiltersConfigPass($doctrineOrm);
+
+ $backendConfig = [
+ 'entities' => [
+ 'TestEntity' => [
+ 'class' => 'App\\Entity\\TestEntity',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo'],
+ 'filter2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
+ 'documents' => [
+ 'TestDocument' => [
+ 'class' => 'App\\Document\\TestDocument',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo'],
+ 'filter2' => ['type' => 'bar'],
+ ]],
+ ],
+ ],
+ ];
+
+ $backendConfig = $listFormFiltersConfigPass->process($backendConfig);
+
+ $expectedBackendConfig = [
+ 'entities' => [
+ 'TestEntity' => [
+ 'class' => 'App\\Entity\\TestEntity',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo', 'property' => 'filter1'],
+ 'filter2' => ['type' => 'bar', 'property' => 'filter2'],
+ ]],
+ ],
+ ],
+ 'documents' => [
+ 'TestDocument' => [
+ 'class' => 'App\\Document\\TestDocument',
+ 'list' => ['form_filters' => [
+ 'filter1' => ['type' => 'foo', 'property' => 'filter1'],
+ 'filter2' => ['type' => 'bar', 'property' => 'filter2'],
+ ]],
+ ],
+ ],
+ ];
+
+ $this->assertSame($backendConfig, $expectedBackendConfig);
+ }
+}
diff --git a/tests/Configuration/ShowViewConfigPassTest.php b/tests/Configuration/ShowViewConfigPassTest.php
index 4933a5e1..230415f0 100644
--- a/tests/Configuration/ShowViewConfigPassTest.php
+++ b/tests/Configuration/ShowViewConfigPassTest.php
@@ -57,9 +57,10 @@ public function testDefaultEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => '@EasyAdminExtension/default/field_embedded_list.html.twig',
'template_options' => [
- 'entity_fqcn' => 'App\Entity\MyRelation',
- 'parent_entity_property' => 'relations',
+ 'object_type' => 'entity',
'entity' => 'MyRelation',
+ 'object_fqcn' => 'App\Entity\MyRelation',
+ 'parent_object_property' => 'relations',
'filters' => [],
'sort' => null,
],
@@ -101,10 +102,10 @@ public function testDefinedEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => 'path/to/template.html.twig',
'template_options' => [
- 'parent_entity_fqcn' => 'Foo\Entity\MyEntity',
- 'parent_entity_property' => 'children',
- 'entity_fqcn' => 'Foo\Entity\Child',
'entity' => 'Child',
+ 'object_fqcn' => 'Foo\Entity\Child',
+ 'parent_object_fqcn' => 'Foo\Entity\MyEntity',
+ 'parent_object_property' => 'children',
'filters' => ['bar' => 'baz'],
'sort' => ['qux', 'ASC'],
],
@@ -128,12 +129,13 @@ public function testDefinedEmbeddedListShow()
'sourceEntity' => 'App\Entity\MyEntity',
'template' => 'path/to/template.html.twig',
'template_options' => [
- 'parent_entity_fqcn' => 'Foo\Entity\MyEntity',
- 'parent_entity_property' => 'children',
- 'entity_fqcn' => 'Foo\Entity\Child',
'entity' => 'Child',
+ 'object_fqcn' => 'Foo\Entity\Child',
+ 'parent_object_fqcn' => 'Foo\Entity\MyEntity',
+ 'parent_object_property' => 'children',
'filters' => ['bar' => 'baz'],
'sort' => ['field' => 'qux', 'direction' => 'ASC'],
+ 'object_type' => 'entity',
],
],
],
diff --git a/tests/Controller/MongoOdmCompatTest.php b/tests/Controller/MongoOdmCompatTest.php
new file mode 100644
index 00000000..53d872ab
--- /dev/null
+++ b/tests/Controller/MongoOdmCompatTest.php
@@ -0,0 +1,45 @@
+initClient(['environment' => 'mongo_odm_compat', 'withMongoOdm' => true]);
+ }
+
+ public function testEasyAdminWorks()
+ {
+ $crawler = $this->requestListView('Product');
+
+ $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+ }
+
+ public function testEasyAdminMongoOdmWorks()
+ {
+ $this->markTestSkipped('The MongoDB test database is not yet available.');
+
+ $crawler = $this->requestMongoOdmListView('RequestLog');
+
+ $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+ }
+
+ /**
+ * @return Crawler
+ */
+ protected function requestMongoOdmListView($documentName = 'RequestLog', array $requestFilters = [], array $formFilters = [])
+ {
+ return $this->getMongoOdmBackendPage([
+ 'action' => 'list',
+ 'document' => $documentName,
+ 'view' => 'list',
+ 'filters' => $requestFilters,
+ 'form_filters' => $formFilters,
+ ]);
+ }
+}
diff --git a/tests/Controller/UserRolesTest.php b/tests/Controller/UserRolesTest.php
index c490e16b..23a0e3da 100644
--- a/tests/Controller/UserRolesTest.php
+++ b/tests/Controller/UserRolesTest.php
@@ -151,7 +151,7 @@ public function testEntityActionsAreFilteredOnPrefixedRoles()
$crawler = $this->getBackendPage(['entity' => 'Category', 'action' => 'edit', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_CATEGORY_EDIT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_CATEGORY_EDIT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
@@ -174,7 +174,7 @@ public function testEntityActionsAreFilteredOnSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'show', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
}
@@ -204,19 +204,19 @@ public function testEntityActionsAreForbiddenOnCaseInsensitiveSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'edit', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'Edit', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'EDIT', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_EDIT_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
@@ -224,19 +224,19 @@ public function testEntityActionsAreForbiddenOnCaseInsensitiveSpecificRoles()
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'show', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'Show', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
$crawler = $this->getBackendPage(['entity' => 'Product', 'action' => 'SHOW', 'id' => 1]);
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
$this->assertSame(
- 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this entity action ! (403 Forbidden)',
+ 'You must be granted ROLE_TEST_SHOW_PRODUCT role to perform this object action ! (403 Forbidden)',
\trim($crawler->filterXPath('//head/title')->text())
);
}
diff --git a/tests/Fixtures/AbstractTestCase.php b/tests/Fixtures/AbstractTestCase.php
index 523f8727..8cd4d6f4 100644
--- a/tests/Fixtures/AbstractTestCase.php
+++ b/tests/Fixtures/AbstractTestCase.php
@@ -36,6 +36,20 @@ protected function initClient(array $options = [])
$this->client = static::createClient($options);
}
+ /**
+ * {@inheritdoc}
+ */
+ protected static function createKernel(array $options = [])
+ {
+ $kernel = parent::createKernel($options);
+
+ $withMongoOdm = isset($options['withMongoOdm']) ? (bool) $options['withMongoOdm'] : false;
+
+ $kernel->withMongoOdm($withMongoOdm);
+
+ return $kernel;
+ }
+
/**
* It ensures that the database contains the original fixtures of the
* application. This way tests can modify its contents safely without
@@ -64,6 +78,16 @@ protected function getBackendPage(array $queryParameters = [])
return $this->client->request('GET', '/admin/?'.\http_build_query($queryParameters, '', '&'));
}
+ /**
+ * @param array $queryParameters
+ *
+ * @return Crawler
+ */
+ protected function getMongoOdmBackendPage(array $queryParameters = [])
+ {
+ return $this->client->request('GET', '/admin-mongo-odm/?'.\http_build_query($queryParameters, '', '&'));
+ }
+
/**
* @return Crawler
*/
diff --git a/tests/Fixtures/App/AppKernel.php b/tests/Fixtures/App/AppKernel.php
index 8f6b4c4b..9efee280 100644
--- a/tests/Fixtures/App/AppKernel.php
+++ b/tests/Fixtures/App/AppKernel.php
@@ -18,18 +18,35 @@
*/
class AppKernel extends Kernel
{
+ private $withMongoOdm = false;
+
+ public function withMongoOdm(bool $withMongoOdm)
+ {
+ $this->withMongoOdm = $withMongoOdm;
+
+ return $this;
+ }
+
public function registerBundles()
{
- return [
+ $bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle(),
- new AlterPHP\EasyAdminExtensionBundle\EasyAdminExtensionBundle(),
- new AlterPHP\EasyAdminExtensionBundle\Tests\Fixtures\AppTestBundle\AppTestBundle(),
];
+
+ if ($this->withMongoOdm) {
+ $bundles[] = new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle();
+ $bundles[] = new AlterPHP\EasyAdminMongoOdmBundle\EasyAdminMongoOdmBundle();
+ }
+
+ $bundles[] = new AlterPHP\EasyAdminExtensionBundle\EasyAdminExtensionBundle();
+ $bundles[] = new AlterPHP\EasyAdminExtensionBundle\Tests\Fixtures\AppTestBundle\AppTestBundle();
+
+ return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
diff --git a/tests/Fixtures/App/config/config.yaml b/tests/Fixtures/App/config/config.yaml
index ada16e14..b52774a1 100644
--- a/tests/Fixtures/App/config/config.yaml
+++ b/tests/Fixtures/App/config/config.yaml
@@ -13,7 +13,7 @@ framework:
default_locale: '%locale%'
test: ~
router: { resource: '%kernel.root_dir%/config/routing_base.yaml' }
- form: true
+ form: true
validation: { enable_annotations: true }
templating: { engines: ['twig'] }
profiler:
diff --git a/tests/Fixtures/App/config/config_mongo_odm_compat.yaml b/tests/Fixtures/App/config/config_mongo_odm_compat.yaml
new file mode 100644
index 00000000..824f4c40
--- /dev/null
+++ b/tests/Fixtures/App/config/config_mongo_odm_compat.yaml
@@ -0,0 +1,47 @@
+imports:
+ - { resource: config.yaml }
+
+framework:
+ router:
+ resource: '%kernel.root_dir%/config/routing_mongo_odm.yaml'
+
+doctrine_mongodb:
+ auto_generate_proxy_classes: '%kernel.debug%'
+ auto_generate_hydrator_classes: '%kernel.debug%'
+ connections:
+ default:
+ server: 'localhost'
+ options:
+ authSource: "admin"
+ db: 'mongo_db'
+ document_managers:
+ default:
+ connection: default
+ database: 'mongo_db'
+ mappings:
+ App:
+ is_bundle: false
+ type: annotation
+ dir: '%kernel.root_dir%/../AppTestBundle/Document/FunctionalTests/'
+ prefix: AppTestBundle\Document\FunctionalTests\
+ alias: FunctionalTests
+ default_document_manager: default
+ default_connection: default
+
+easy_admin:
+ entities:
+ Category:
+ class: AppTestBundle\Entity\FunctionalTests\Category
+ Product:
+ class: AppTestBundle\Entity\FunctionalTests\Product
+ Purchase:
+ class: AppTestBundle\Entity\FunctionalTests\Purchase
+ AdminGroup:
+ class: AppTestBundle\Entity\FunctionalTests\AdminGroup
+ AdminUser:
+ class: AppTestBundle\Entity\FunctionalTests\AdminUser
+
+easy_admin_mongo_odm:
+ documents:
+ RequestLog:
+ class: AppTestBundle\Document\FunctionalTests\RequestLog
diff --git a/tests/Fixtures/App/config/routing_mongo_odm.yaml b/tests/Fixtures/App/config/routing_mongo_odm.yaml
new file mode 100644
index 00000000..839066b0
--- /dev/null
+++ b/tests/Fixtures/App/config/routing_mongo_odm.yaml
@@ -0,0 +1,9 @@
+easy_admin_bundle:
+ resource: "AlterPHP\\EasyAdminExtensionBundle\\Controller\\EasyAdminController"
+ type: annotation
+ prefix: /admin/
+
+easy_admin_mongo_odm_bundle:
+ resource: "AlterPHP\\EasyAdminExtensionBundle\\Controller\\MongoOdmEasyAdminController"
+ type: annotation
+ prefix: /admin-mongo-odm/
diff --git a/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php b/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php
new file mode 100644
index 00000000..b769bcbe
--- /dev/null
+++ b/tests/Fixtures/AppTestBundle/Document/FunctionalTests/RequestLog.php
@@ -0,0 +1,61 @@
+clientIp = $clientIp;
+ $requestLog->localDatetime = $localDatetime ? $localDatetime->format('c') : null;
+
+ return $requestLog;
+ }
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function getClientIp()
+ {
+ return $this->clientIp;
+ }
+
+ public function getLocalDatetime()
+ {
+ return $this->localDatetime;
+ }
+}
diff --git a/tests/Helper/MenuHelperTest.php b/tests/Helper/MenuHelperTest.php
index 82d257f0..cc4fb4ea 100644
--- a/tests/Helper/MenuHelperTest.php
+++ b/tests/Helper/MenuHelperTest.php
@@ -96,6 +96,93 @@ public function testAcessDeniedEntityEntriesArePruned()
$this->assertSame($expectedPrunedMenu, $prunedMenu);
}
+ public function testAcessDeniedDocumentEntriesArePruned()
+ {
+ $menuConfig = [
+ 0 => ['label' => 'Dashboard', 'type' => 'route', 'children' => []],
+ 1 => ['label' => 'Organizations', 'type' => 'document', 'document' => 'Organization'],
+ 2 => ['label' => 'Members', 'type' => 'document', 'document' => 'Member'],
+ 3 => ['label' => 'Events', 'type' => 'empty', 'children' => [
+ 0 => ['label' => 'Seminaries', 'type' => 'document', 'document' => 'Seminary'],
+ 1 => ['label' => 'Meetings', 'type' => 'document', 'document' => 'Meeting'],
+ 2 => ['label' => 'Plenary meetings', 'type' => 'document', 'document' => 'PlenaryMeeting'],
+ ]],
+ 4 => ['label' => 'System', 'type' => 'empty', 'children' => [
+ 0 => ['label' => 'Admin users', 'type' => 'document', 'document' => 'AdminUser'],
+ 1 => ['label' => 'Admin groups', 'type' => 'document', 'document' => 'AdminGroup'],
+ ]],
+ ];
+
+ $documentsConfig = [
+ 'Organization' => ['role_prefix' => 'ROLE_ORGANIZATION'],
+ 'Member' => ['role_prefix' => 'ROLE_MEMBER'],
+ 'Seminary' => ['role_prefix' => 'ROLE_SEMINARY'],
+ 'Meeting' => ['role_prefix' => 'ROLE_MEETING'],
+ 'PlenaryMeeting' => ['role_prefix' => 'ROLE_PLENARYMEETING'],
+ 'AdminUser' => ['role_prefix' => 'ROLE_ADMINUSER'],
+ 'AdminGroup' => ['role_prefix' => 'ROLE_ADMINGROUP'],
+ ];
+
+ $adminAuthorizationChecker = $this->createMock(AdminAuthorizationChecker::class);
+ $symfonyAuthorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
+
+ $grantedRoleMap = [
+ [$documentsConfig['Organization'], 'list', null, true],
+ [$documentsConfig['Member'], 'list', null, false],
+ [$documentsConfig['Seminary'], 'list', null, true],
+ [$documentsConfig['Meeting'], 'list', null, false],
+ [$documentsConfig['PlenaryMeeting'], 'list', null, true],
+ [$documentsConfig['AdminUser'], 'list', null, false],
+ [$documentsConfig['AdminGroup'], 'list', null, false],
+ ];
+ $adminAuthorizationChecker->method('isEasyAdminGranted')->will($this->returnValueMap($grantedRoleMap));
+
+ $helper = new MenuHelper($adminAuthorizationChecker, $symfonyAuthorizationChecker);
+
+ $prunedMenu = $helper->pruneMenuItems($menuConfig, $documentsConfig);
+
+ $expectedPrunedMenu = [
+ 0 => [
+ 'label' => 'Dashboard',
+ 'type' => 'route',
+ 'children' => [],
+ 'menu_index' => 0,
+ 'submenu_index' => -1,
+ ],
+ 1 => [
+ 'label' => 'Organizations',
+ 'type' => 'document',
+ 'document' => 'Organization',
+ 'menu_index' => 1,
+ 'submenu_index' => -1,
+ ],
+ 2 => [
+ 'label' => 'Events',
+ 'type' => 'empty',
+ 'children' => [
+ 0 => [
+ 'label' => 'Seminaries',
+ 'type' => 'document',
+ 'document' => 'Seminary',
+ 'menu_index' => 2,
+ 'submenu_index' => 0,
+ ],
+ 1 => [
+ 'label' => 'Plenary meetings',
+ 'type' => 'document',
+ 'document' => 'PlenaryMeeting',
+ 'menu_index' => 2,
+ 'submenu_index' => 1,
+ ],
+ ],
+ 'menu_index' => 2,
+ 'submenu_index' => -1,
+ ],
+ ];
+
+ $this->assertSame($expectedPrunedMenu, $prunedMenu);
+ }
+
public function testAcessDeniedStaticEntriesArePruned()
{
$menuConfig = [