From 4402bf00e218e5f2353693882d3bccf8d084918b Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Tue, 28 Apr 2020 16:14:25 +0200 Subject: [PATCH 01/17] feature/undelete-nodes --- .../AdminList/NodeAdminListConfigurator.php | 30 ++- .../Controller/NodeAdminController.php | 183 ++++++++++++++++-- 2 files changed, 193 insertions(+), 20 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index b5d3c35c07..1109681318 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -2,7 +2,9 @@ namespace Kunstmaan\NodeBundle\AdminList; +use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface; use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper; @@ -46,6 +48,11 @@ class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator */ protected $authorizationChecker; + /** + * @var bool + */ + private $deletedPagesOnly; + /** * @param EntityManager $em The entity * manager @@ -164,6 +171,10 @@ public function canAdd() public function canEdit($item) { + if ($this->deletedPagesOnly) { + return false; + } + return $this->authorizationChecker->isGranted(PermissionMap::PERMISSION_EDIT, $item->getNode()); } @@ -241,10 +252,11 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) $queryBuilder ->select('b,n') - ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id') + ->innerJoin('b.node', 'n', Join::WITH, 'b.node = n.id') ->andWhere('b.lang = :lang') - ->andWhere('n.deleted = 0') - ->addOrderBy('b.updated', 'DESC') + ->andWhere('n.deleted = :deletedPagesOnly') + ->setParameter('deletedPagesOnly', $this->deletedPagesOnly) + ->addOrderBy('b.updated', Criteria::DESC) ->setParameter('lang', $this->locale); if (!$this->domainConfiguration) { @@ -259,4 +271,16 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->setParameter('right', $rootNode->getRight()); } } + + /** + * @var bool $deletedPagesOnly + * + * @return NodeAdminListConfigurator + */ + public function setDeletedPagesOnly($deletedPagesOnly): NodeAdminListConfigurator + { + $this->deletedPagesOnly = $deletedPagesOnly; + + return $this; + } } diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index f729d775b0..ac5b990b0a 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -16,6 +16,7 @@ use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap; use Kunstmaan\AdminBundle\Service\AclManager; use Kunstmaan\AdminListBundle\AdminList\AdminList; +use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction; use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator; use Kunstmaan\NodeBundle\Entity\HasNodeInterface; use Kunstmaan\NodeBundle\Entity\Node; @@ -117,16 +118,9 @@ public function indexAction(Request $request) { $this->init($request); - $nodeAdminListConfigurator = new NodeAdminListConfigurator( - $this->em, - $this->aclHelper, - $this->locale, - PermissionMap::PERMISSION_VIEW, - $this->authorizationChecker - ); - $locale = $this->locale; $acl = $this->authorizationChecker; + $itemRoute = function (EntityInterface $item) use ($locale, $acl) { if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) { return array( @@ -134,18 +128,25 @@ public function indexAction(Request $request) 'params' => ['_locale' => $locale, 'url' => $item->getUrl()], ); } - }; - $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); - $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); - $nodeAdminListConfigurator->setShowAddHomepage($this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN')); - /** @var AdminList $adminlist */ - $adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); - $adminlist->bindRequest($request); + return null; + }; - return array( - 'adminlist' => $adminlist, + $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); + $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); + $nodeAdminListConfigurator->addListAction( + new SimpleListAction( + [ + 'path' => 'KunstmaanNodeBundle_deleted_nodes', + 'params' => [], + ], + 'view_deleted_pages.label', + null, + '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' + ) ); + + return $this->renderAdminList($request, $nodeAdminListConfigurator); } /** @@ -445,6 +446,46 @@ public function deleteAction(Request $request, $id) return $response; } + /** + * @Route( + * "/{id}/delete/undo", + * requirements={"id" = "\d+"}, + * name="KunstmaanNodeBundle_nodes_delete_undo", + * ) + * + * @param Request $request + * @param int $id + * + * @return RedirectResponse + */ + public function undoDeleteAction(Request $request, $id) + { + $this->init($request); + + /* @var Node $node */ + $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); + + try { + $this->undoDeleteNode($node); + + $this->em->flush(); + + $this->addFlash( + FlashTypes::SUCCESS, + $this->get('translator')->trans('kuma_node.admin.delete_undo.flash.success') + ); + } catch (AccessDeniedException $exception) { + $this->addFlash( + FlashTypes::SUCCESS, + $this->get('translator')->trans('kuma_node.admin.delete_undo.flash.error') + ); + } + + return $this->redirectToRoute( + 'KunstmaanNodeBundle_deleted_nodes' + ); + } + /** * @Route( * "/{id}/duplicate", @@ -1189,6 +1230,28 @@ private function deleteNodeChildren( } } + /** + * @param Node $node + * + * @return void + */ + private function undoDeleteNode( + Node $node + ) { + $this->denyAccessUnlessGranted( + PermissionMap::PERMISSION_DELETE, + $node + ); + + $node->setDeleted(false); + + $this->em->persist($node); + + foreach ($node->getChildren() as $child) { + $this->undoDeleteNode($node); + } + } + /** * @param Request $request * @param string $type @@ -1272,4 +1335,90 @@ private function renderNodeNotTranslatedPage(Node $node) ) ); } + + /** + * @return NodeAdminListConfigurator + */ + private function getNodeAdminListConfigurator() + { + $nodeAdminListConfigurator = new NodeAdminListConfigurator( + $this->em, + $this->aclHelper, + $this->locale, + PermissionMap::PERMISSION_VIEW, + $this->authorizationChecker + ); + + $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); + $nodeAdminListConfigurator->setShowAddHomepage( + $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') + ); + + return $nodeAdminListConfigurator; + } + + /** + * @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") + * @Template("@KunstmaanNode/Admin/list.html.twig") + * + * @param Request $request + * + * @return array + */ + public function removedNodesAction(Request $request) + { + $this->init($request); + + $locale = $this->locale; + $acl = $this->authorizationChecker; + + $itemRoute = function (EntityInterface $item) use ($locale, $acl) { + if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { + return [ + 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', + 'params' => [ + '_locale' => $locale, + 'id' => $item->getNode()->getId() + ], + ]; + } + + return null; + }; + + $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); + $nodeAdminListConfigurator->setDeletedPagesOnly(true); + $nodeAdminListConfigurator->addSimpleItemAction('action.undo', $itemRoute, 'undo'); + $nodeAdminListConfigurator->addListAction( + new SimpleListAction( + [ + 'path' => 'KunstmaanNodeBundle_nodes', + 'params' => [], + ], + 'view_pages.label', + null, + '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' + ) + ); + + return $this->renderAdminList($request, $nodeAdminListConfigurator); + } + + /** + * @var NodeAdminListConfigurator $nodeAdminListConfigurator + * + * @return array + */ + private function renderAdminList( + Request $request, + NodeAdminListConfigurator $nodeAdminListConfigurator + ) { + /** @var AdminList $adminList */ + $adminList = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); + $adminList->bindRequest($request); + + return [ + 'adminlist' => $adminList, + ]; + } } From 0f70f5c77de919b3beda98a5edb77b0e2519041c Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Wed, 6 May 2020 11:54:35 +0200 Subject: [PATCH 02/17] feature/undelete-nodes --- .../AdminList/NodeAdminListConfigurator.php | 2 +- .../Controller/NodeAdminController.php | 95 ++++++++++--------- .../Resources/translations/messages.en.yml | 6 ++ .../Resources/translations/messages.nl.yml | 5 + 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index 1109681318..60913356df 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -51,7 +51,7 @@ class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator /** * @var bool */ - private $deletedPagesOnly; + private $deletedPagesOnly = false; /** * @param EntityManager $em The entity diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index ac5b990b0a..8c58882320 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -446,6 +446,53 @@ public function deleteAction(Request $request, $id) return $response; } + /** + * @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") + * @Template("@KunstmaanNode/Admin/list.html.twig") + * + * @param Request $request + * + * @return array + */ + public function removedNodesAction(Request $request) + { + $this->init($request); + + $locale = $this->locale; + $acl = $this->authorizationChecker; + + $itemRoute = function (EntityInterface $item) use ($locale, $acl) { + if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { + return [ + 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', + 'params' => [ + '_locale' => $locale, + 'id' => $item->getNode()->getId() + ], + ]; + } + + return null; + }; + + $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); + $nodeAdminListConfigurator->setDeletedPagesOnly(true); + $nodeAdminListConfigurator->addSimpleItemAction('action.undo', $itemRoute, 'undo'); + $nodeAdminListConfigurator->addListAction( + new SimpleListAction( + [ + 'path' => 'KunstmaanNodeBundle_nodes', + 'params' => [], + ], + 'view_pages.label', + null, + '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' + ) + ); + + return $this->renderAdminList($request, $nodeAdminListConfigurator); + } + /** * @Route( * "/{id}/delete/undo", @@ -1248,7 +1295,7 @@ private function undoDeleteNode( $this->em->persist($node); foreach ($node->getChildren() as $child) { - $this->undoDeleteNode($node); + $this->undoDeleteNode($child); } } @@ -1358,53 +1405,7 @@ private function getNodeAdminListConfigurator() } /** - * @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") - * @Template("@KunstmaanNode/Admin/list.html.twig") - * * @param Request $request - * - * @return array - */ - public function removedNodesAction(Request $request) - { - $this->init($request); - - $locale = $this->locale; - $acl = $this->authorizationChecker; - - $itemRoute = function (EntityInterface $item) use ($locale, $acl) { - if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { - return [ - 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', - 'params' => [ - '_locale' => $locale, - 'id' => $item->getNode()->getId() - ], - ]; - } - - return null; - }; - - $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); - $nodeAdminListConfigurator->setDeletedPagesOnly(true); - $nodeAdminListConfigurator->addSimpleItemAction('action.undo', $itemRoute, 'undo'); - $nodeAdminListConfigurator->addListAction( - new SimpleListAction( - [ - 'path' => 'KunstmaanNodeBundle_nodes', - 'params' => [], - ], - 'view_pages.label', - null, - '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' - ) - ); - - return $this->renderAdminList($request, $nodeAdminListConfigurator); - } - - /** * @var NodeAdminListConfigurator $nodeAdminListConfigurator * * @return array diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml index 76e9c8ae47..0fbde68de3 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml @@ -17,6 +17,7 @@ modal: sourcelanguage: "Source language" pages: + view_action: 'View pages' copynotavailable: "Please translate the parent page first" kuma_node: @@ -187,3 +188,8 @@ toolbar: node: title: 'Page title' edit: 'Edit page' + +deleted_pages: + title: 'Deleted pages' + additional_title: 'This list contains all the deleted pages, chronologically ordered by updated date.' + view_action: 'View deleted pages' diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml index d12ad9816b..bfe6b6d3f8 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml @@ -15,6 +15,7 @@ action: modal: sourcelanguage: "Bron taal" pages: + view_action: "Bekijk pagina's" copynotavailable: "Gelieve de bovenliggende pagina eerst te vertalen" kuma_node: form: @@ -177,3 +178,7 @@ kuma_node: widget: choose: Kies url_chooser: URL-keuze +deleted_pages: + title: "Verwijderde pagina's" + additional_title: "Deze lijst bevat alle verwijderde pagina's chronologisch gesorteerd op laatste wijziging." + view_action: "Bekijk verwijderde pagina's" From 631ddf3d84477cfa9b960cc786ab259b27c10d5f Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Mon, 29 Jun 2020 11:52:25 +0200 Subject: [PATCH 03/17] feature/undelete-nodes --- .../DeletedNodeAdminListConfigurator.php | 43 +++++++ .../AdminList/NodeAdminListConfigurator.php | 28 +---- .../Controller/NodeAdminController.php | 117 ++++++++---------- 3 files changed, 97 insertions(+), 91 deletions(-) create mode 100644 src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php diff --git a/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php new file mode 100644 index 0000000000..cc4514b654 --- /dev/null +++ b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php @@ -0,0 +1,43 @@ +addFilter('title', new StringFilterType('title'), 'kuma_node.admin.list.filter.title') + ->addFilter('created', new DateFilterType('created'), 'kuma_node.admin.list.filter.created_at') + ->addFilter('updated', new DateFilterType('updated'), 'kuma_node.admin.list.filter.updated_at') + ; + } + + public function buildFields() + { + $this + ->addField('title', 'kuma_node.admin.list.header.title', true, '@KunstmaanNode/Admin/title.html.twig') + ->addField('created', 'kuma_node.admin.list.header.created_at', true) + ->addField('updated', 'kuma_node.admin.list.header.updated_at', true) + ; + } + + public function canEdit($item) + { + return false; + } + + public function adaptQueryBuilder(QueryBuilder $queryBuilder) + { + parent::adaptQueryBuilder($queryBuilder); + + $queryBuilder + ->where('b.lang = :lang') + ->andWhere('n.deleted = 1') + ; + } +} diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index 60913356df..0093929b6b 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -48,11 +48,6 @@ class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator */ protected $authorizationChecker; - /** - * @var bool - */ - private $deletedPagesOnly = false; - /** * @param EntityManager $em The entity * manager @@ -69,14 +64,14 @@ public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $p $this->setPermissionDefinition( new PermissionDefinition( array($permission), - 'Kunstmaan\NodeBundle\Entity\Node', + Node::class, 'n' ) ); } /** - * @param \Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface $domainConfiguration + * @param DomainConfigurationInterface $domainConfiguration */ public function setDomainConfiguration(DomainConfigurationInterface $domainConfiguration) { @@ -171,10 +166,6 @@ public function canAdd() public function canEdit($item) { - if ($this->deletedPagesOnly) { - return false; - } - return $this->authorizationChecker->isGranted(PermissionMap::PERMISSION_EDIT, $item->getNode()); } @@ -254,8 +245,7 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->select('b,n') ->innerJoin('b.node', 'n', Join::WITH, 'b.node = n.id') ->andWhere('b.lang = :lang') - ->andWhere('n.deleted = :deletedPagesOnly') - ->setParameter('deletedPagesOnly', $this->deletedPagesOnly) + ->andWhere('n.deleted = 0') ->addOrderBy('b.updated', Criteria::DESC) ->setParameter('lang', $this->locale); @@ -271,16 +261,4 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->setParameter('right', $rootNode->getRight()); } } - - /** - * @var bool $deletedPagesOnly - * - * @return NodeAdminListConfigurator - */ - public function setDeletedPagesOnly($deletedPagesOnly): NodeAdminListConfigurator - { - $this->deletedPagesOnly = $deletedPagesOnly; - - return $this; - } } diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 8c58882320..bb6601a0cd 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -17,6 +17,7 @@ use Kunstmaan\AdminBundle\Service\AclManager; use Kunstmaan\AdminListBundle\AdminList\AdminList; use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction; +use Kunstmaan\NodeBundle\AdminList\DeletedNodeAdminListConfigurator; use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator; use Kunstmaan\NodeBundle\Entity\HasNodeInterface; use Kunstmaan\NodeBundle\Entity\Node; @@ -118,9 +119,16 @@ public function indexAction(Request $request) { $this->init($request); + $nodeAdminListConfigurator = new NodeAdminListConfigurator( + $this->em, + $this->aclHelper, + $this->locale, + PermissionMap::PERMISSION_VIEW, + $this->authorizationChecker + ); + $locale = $this->locale; $acl = $this->authorizationChecker; - $itemRoute = function (EntityInterface $item) use ($locale, $acl) { if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) { return array( @@ -132,7 +140,6 @@ public function indexAction(Request $request) return null; }; - $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); $nodeAdminListConfigurator->addListAction( new SimpleListAction( @@ -140,13 +147,23 @@ public function indexAction(Request $request) 'path' => 'KunstmaanNodeBundle_deleted_nodes', 'params' => [], ], - 'view_deleted_pages.label', + 'deleted_pages.view_action', null, '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' ) ); + $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); + $nodeAdminListConfigurator->setShowAddHomepage( + $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') + ); - return $this->renderAdminList($request, $nodeAdminListConfigurator); + /** @var AdminList $adminlist */ + $adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); + $adminlist->bindRequest($request); + + return [ + 'adminlist' => $adminlist, + ]; } /** @@ -454,42 +471,50 @@ public function deleteAction(Request $request, $id) * * @return array */ - public function removedNodesAction(Request $request) + public function deletedNodesAction(Request $request) { $this->init($request); - $locale = $this->locale; - $acl = $this->authorizationChecker; - - $itemRoute = function (EntityInterface $item) use ($locale, $acl) { - if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { - return [ - 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', - 'params' => [ - '_locale' => $locale, - 'id' => $item->getNode()->getId() - ], - ]; - } - - return null; - }; - - $nodeAdminListConfigurator = $this->getNodeAdminListConfigurator(); - $nodeAdminListConfigurator->setDeletedPagesOnly(true); - $nodeAdminListConfigurator->addSimpleItemAction('action.undo', $itemRoute, 'undo'); + $nodeAdminListConfigurator = new DeletedNodeAdminListConfigurator( + $this->em, + $this->aclHelper, + $this->locale, + PermissionMap::PERMISSION_DELETE, + $this->authorizationChecker + ); $nodeAdminListConfigurator->addListAction( new SimpleListAction( [ 'path' => 'KunstmaanNodeBundle_nodes', 'params' => [], ], - 'view_pages.label', + 'pages.view_action', null, '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' ) ); + $locale = $this->locale; + $acl = $this->authorizationChecker; + + $nodeAdminListConfigurator->addSimpleItemAction( + 'action.undo', + function (EntityInterface $item) use ($locale, $acl) { + if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { + return [ + 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', + 'params' => [ + '_locale' => $locale, + 'id' => $item->getNode()->getId() + ], + ]; + } + + return null; + }, + 'undo' + ); + return $this->renderAdminList($request, $nodeAdminListConfigurator); } @@ -1382,44 +1407,4 @@ private function renderNodeNotTranslatedPage(Node $node) ) ); } - - /** - * @return NodeAdminListConfigurator - */ - private function getNodeAdminListConfigurator() - { - $nodeAdminListConfigurator = new NodeAdminListConfigurator( - $this->em, - $this->aclHelper, - $this->locale, - PermissionMap::PERMISSION_VIEW, - $this->authorizationChecker - ); - - $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); - $nodeAdminListConfigurator->setShowAddHomepage( - $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') - ); - - return $nodeAdminListConfigurator; - } - - /** - * @param Request $request - * @var NodeAdminListConfigurator $nodeAdminListConfigurator - * - * @return array - */ - private function renderAdminList( - Request $request, - NodeAdminListConfigurator $nodeAdminListConfigurator - ) { - /** @var AdminList $adminList */ - $adminList = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); - $adminList->bindRequest($request); - - return [ - 'adminlist' => $adminList, - ]; - } } From dab4e8f1be0e64fa01f308e510cf593425a049f1 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Mon, 29 Jun 2020 12:21:32 +0200 Subject: [PATCH 04/17] feature/undelete-nodes --- .../Controller/NodeAdminController.php | 35 +++++++++++++------ .../Resources/translations/messages.en.yml | 5 +++ .../Resources/translations/messages.nl.yml | 5 +++ .../views/Admin/deleted_list.html.twig | 17 +++++++++ 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 src/Kunstmaan/NodeBundle/Resources/views/Admin/deleted_list.html.twig diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index bb6601a0cd..325a89ff87 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -157,13 +157,7 @@ public function indexAction(Request $request) $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') ); - /** @var AdminList $adminlist */ - $adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); - $adminlist->bindRequest($request); - - return [ - 'adminlist' => $adminlist, - ]; + return $this->renderAdminList($request, $nodeAdminListConfigurator); } /** @@ -465,7 +459,7 @@ public function deleteAction(Request $request, $id) /** * @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") - * @Template("@KunstmaanNode/Admin/list.html.twig") + * @Template("@KunstmaanNode/Admin/deleted_list.html.twig") * * @param Request $request * @@ -498,7 +492,7 @@ public function deletedNodesAction(Request $request) $acl = $this->authorizationChecker; $nodeAdminListConfigurator->addSimpleItemAction( - 'action.undo', + 'action.undo_delete', function (EntityInterface $item) use ($locale, $acl) { if ($acl->isGranted(PermissionMap::PERMISSION_DELETE, $item->getNode())) { return [ @@ -544,12 +538,12 @@ public function undoDeleteAction(Request $request, $id) $this->addFlash( FlashTypes::SUCCESS, - $this->get('translator')->trans('kuma_node.admin.delete_undo.flash.success') + $this->get('translator')->trans('kuma_node.admin.undo_delete.flash.success') ); } catch (AccessDeniedException $exception) { $this->addFlash( FlashTypes::SUCCESS, - $this->get('translator')->trans('kuma_node.admin.delete_undo.flash.error') + $this->get('translator')->trans('kuma_node.admin.undo_delete.flash.error') ); } @@ -1407,4 +1401,23 @@ private function renderNodeNotTranslatedPage(Node $node) ) ); } + + /** + * @param Request $request + * @var NodeAdminListConfigurator $nodeAdminListConfigurator + * + * @return array + */ + private function renderAdminList( + Request $request, + NodeAdminListConfigurator $nodeAdminListConfigurator + ) { + /** @var AdminList $adminList */ + $adminList = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); + $adminList->bindRequest($request); + + return [ + 'adminlist' => $adminList, + ]; + } } diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml index 0fbde68de3..9a17f6efe5 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml @@ -12,6 +12,7 @@ action: delete: "Delete" addsubpage: "Add subpage" duplicate: "Duplicate" + undo_delete: "Undo deleting page" modal: sourcelanguage: "Source language" @@ -82,6 +83,10 @@ kuma_node: success: The page has been edited locked: The page is currently being edited by %users% locked_success: An automatic backup has been created because the page is being edited by another user + undo_delete: + flash: + success: The deleting the page has been undone + error: There was an error while undoing deleting the page new_page: title: default: New page diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml index bfe6b6d3f8..9985f965d1 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml @@ -12,6 +12,7 @@ action: delete: "Verwijder" addsubpage: "Subpagina toevoegen" duplicate: "Dupliceer" + undo_delete: "Verwijderen ongedaan maken" modal: sourcelanguage: "Bron taal" pages: @@ -79,6 +80,10 @@ kuma_node: success: De pagina is bewerkt locked: De pagina wordt momenteel bewerkt door %users% locked_success: Een automatische back-up is aangemaakt, omdat de pagina is bewerkt door een andere gebruiker + undo_delete: + flash: + success: Het ongedaan maken van het verwijderen van de pagina is gelukt + error: Er is een probleem opgetreden tijdens het ongedaan maken van het verwijderen van de pagina new_page: title: default: Nieuwe pagina diff --git a/src/Kunstmaan/NodeBundle/Resources/views/Admin/deleted_list.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/Admin/deleted_list.html.twig new file mode 100644 index 0000000000..a2ab23e155 --- /dev/null +++ b/src/Kunstmaan/NodeBundle/Resources/views/Admin/deleted_list.html.twig @@ -0,0 +1,17 @@ +{% extends '@KunstmaanAdminList/Default/list.html.twig' %} + +{% block admin_page_title %} +
+

+ {{ 'deleted_pages.title' | trans }} + + + {{ 'deleted_pages.additional_title'|trans }} + +

+
+{% endblock %} + +{% block page_header_addition %} + +{% endblock %} From e1eed18d76cb6bd6b5627bf66b6d4127db8950c8 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 17 Jul 2020 15:35:31 +0200 Subject: [PATCH 05/17] feature/undelete-nodes --- .../DeletedNodeAdminListConfigurator.php | 5 --- .../Controller/NodeAdminController.php | 7 ++++ .../Helper/Menu/ActionsMenuBuilder.php | 42 ++++++++++++------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php index cc4514b654..48dbf0af05 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php @@ -26,11 +26,6 @@ public function buildFields() ; } - public function canEdit($item) - { - return false; - } - public function adaptQueryBuilder(QueryBuilder $queryBuilder) { parent::adaptQueryBuilder($queryBuilder); diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 325a89ff87..cd4a2cddd4 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -956,6 +956,13 @@ public function editAction(Request $request, $id, $subaction) $nodeVersion = $draftNodeVersion; $page = $nodeVersion->getRef($this->em); } else { + if (!empty($request->request->get('undo_delete'))) { + $node->setDeleted(false); + + $this->em->persist($node); + $this->em->flush(); + } + if ($request->getMethod() == 'POST') { $nodeVersionIsLocked = $this->isNodeVersionLocked($nodeTranslation, true); diff --git a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php index 5a278dbaf8..a2c75100ec 100644 --- a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php +++ b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php @@ -396,20 +396,34 @@ public function createActionsMenu() $node ) ) { - $menu->addChild( - 'action.delete', - [ - 'linkAttributes' => [ - 'type' => 'button', - 'class' => 'btn btn-default btn--raise-on-hover', - 'onClick' => 'oldEdited = isEdited; isEdited=false', - 'data-toggle' => 'modal', - 'data-keyboard' => 'true', - 'data-target' => '#delete-page-modal', - ], - 'extras' => ['renderType' => 'button'], - ] - ); + if (!$node->isDeleted()) { + $menu->addChild( + 'action.delete', + [ + 'linkAttributes' => [ + 'type' => 'button', + 'class' => 'btn btn-default btn--raise-on-hover', + 'onClick' => 'oldEdited = isEdited; isEdited=false', + 'data-toggle' => 'modal', + 'data-keyboard' => 'true', + 'data-target' => '#delete-page-modal', + ], + 'extras' => ['renderType' => 'button'], + ] + ); + } else { + $menu->addChild( + 'action.undo_delete', + [ + 'linkAttributes' => [ + 'type' => 'submit', + 'value' => 'undo_delete', + 'name' => 'undo_delete', + ], + 'extras' => ['renderType' => 'button'], + ] + ); + } } $this->dispatcher->dispatch( From ca0632722aa5aabbb8beb82afe5637e05a916d7f Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Mon, 20 Jul 2020 09:16:29 +0200 Subject: [PATCH 06/17] feature/undelete-nodes --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index c18b751109..5bbe90d56c 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -505,7 +505,7 @@ function (EntityInterface $item) use ($locale, $acl) { 'path' => 'KunstmaanNodeBundle_nodes_delete_undo', 'params' => [ '_locale' => $locale, - 'id' => $item->getNode()->getId() + 'id' => $item->getNode()->getId(), ], ]; } @@ -1335,8 +1335,6 @@ private function deleteNodeChildren( /** * @param Node $node - * - * @return void */ private function undoDeleteNode( Node $node @@ -1441,7 +1439,7 @@ private function renderNodeNotTranslatedPage(Node $node) /** * @param Request $request - * @var NodeAdminListConfigurator $nodeAdminListConfigurator + * @param NodeAdminListConfigurator $nodeAdminListConfigurator * * @return array */ From bca8eb20dc8cf4e0f37c4869d38e252c0738e119 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Mon, 20 Jul 2020 09:17:17 +0200 Subject: [PATCH 07/17] feature/undelete-nodes --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 5bbe90d56c..5469e3a623 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -1438,7 +1438,7 @@ private function renderNodeNotTranslatedPage(Node $node) } /** - * @param Request $request + * @param Request $request * @param NodeAdminListConfigurator $nodeAdminListConfigurator * * @return array From 6b67689a660d64715473f6a1754ca34a011836c4 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 7 Aug 2020 11:36:45 +0200 Subject: [PATCH 08/17] feature/undelete-nodes --- .../Controller/NodeAdminController.php | 14 +++++++-- .../Helper/Menu/ActionsMenuBuilder.php | 8 +++-- .../Resources/translations/messages.en.yml | 5 ++- .../Resources/translations/messages.nl.yml | 3 ++ .../views/Admin/undo_delete_button.html.twig | 9 ++++++ .../NodeAdmin/Modals/_undo_delete.html.twig | 31 +++++++++++++++++++ .../views/NodeAdmin/_modals.html.twig | 2 ++ 7 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig create mode 100644 src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 5469e3a623..c77d0ab865 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -5,6 +5,7 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; +use Esites\CustomerAdminBundle\Entity\User; use InvalidArgumentException; use Kunstmaan\AdminBundle\Entity\BaseUser; use Kunstmaan\AdminBundle\Entity\EntityInterface; @@ -16,6 +17,7 @@ use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap; use Kunstmaan\AdminBundle\Service\AclManager; use Kunstmaan\AdminListBundle\AdminList\AdminList; +use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction; use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction; use Kunstmaan\NodeBundle\AdminList\DeletedNodeAdminListConfigurator; use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator; @@ -359,7 +361,6 @@ public function unPublishAction(Request $request, $id) $node = $this->em->getRepository(Node::class)->find($id); $nodeTranslation = $node->getNodeTranslation($this->locale, true); - $request = $this->get('request_stack')->getCurrentRequest(); $this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator); return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId()))); @@ -512,7 +513,8 @@ function (EntityInterface $item) use ($locale, $acl) { return null; }, - 'undo' + 'undo', + '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' ); return $this->renderAdminList($request, $nodeAdminListConfigurator); @@ -1346,6 +1348,14 @@ private function undoDeleteNode( $node->setDeleted(false); + foreach ($node->getNodeTranslations() as $nodeTranslation) { + if (!$nodeTranslation instanceof NodeTranslation) { + continue; + } + + $this->nodePublisher->unPublish($nodeTranslation); + } + $this->em->persist($node); foreach ($node->getChildren() as $child) { diff --git a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php index 3b14aa2378..8aabe965d7 100644 --- a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php +++ b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php @@ -437,9 +437,11 @@ public function createActionsMenu() 'action.undo_delete', [ 'linkAttributes' => [ - 'type' => 'submit', - 'value' => 'undo_delete', - 'name' => 'undo_delete', + 'type' => 'button', + 'class' => 'btn btn-default btn--raise-on-hover', + 'data-toggle' => 'modal', + 'data-keyboard' => 'true', + 'data-target' => '#undo-delete-page-modal', ], 'extras' => ['renderType' => 'button'], ] diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml index c2d5e0c244..0b6add6aca 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml @@ -86,7 +86,7 @@ kuma_node: locked_success: An automatic backup has been created because the page is being edited by another user undo_delete: flash: - success: The deleting the page has been undone + success: Deleting the page has been undone error: There was an error while undoing deleting the page new_page: title: @@ -172,6 +172,9 @@ kuma_node: button: delete: Delete cancel: Cancel + undo_delete_page: + 'title.%page%': Undo deleting page '%page%' + 'body.%page%': This will undo deleting this page in all languages! Are you really sure about this? duplicate_page: 'title.%page%': Duplicate page '%page%' label: diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml index 9985f965d1..8d995db9d1 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.nl.yml @@ -166,6 +166,9 @@ kuma_node: button: delete: Verwijder cancel: Annuleer + undo_delete_page: + 'title.%page%': Verwijderen van de pagina '%page% ongedaan maken' + 'body.%page%': Hiermee maakt u het verwijderen van deze pagina ongedaan in alle talen! Bent u echt zeker over dit? duplicate_page: 'title.%page%': Dupliceer pagina '%page%' label: diff --git a/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig new file mode 100644 index 0000000000..c1fbc9f1bb --- /dev/null +++ b/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig @@ -0,0 +1,9 @@ + + + + + +{% include '@KunstmaanNode/NodeAdmin/Modals/_undo_delete.html.twig' with { + page: item, + node: item.node +} %} diff --git a/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig new file mode 100644 index 0000000000..54caa5e5d6 --- /dev/null +++ b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig @@ -0,0 +1,31 @@ + diff --git a/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/_modals.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/_modals.html.twig index 92219a772f..8b6b8f987d 100644 --- a/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/_modals.html.twig +++ b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/_modals.html.twig @@ -6,6 +6,8 @@ {% include '@KunstmaanNode/NodeAdmin/Modals/_add_subpage.html.twig' %} {% include '@KunstmaanNode/NodeAdmin/Modals/_delete.html.twig' %} + +{% include '@KunstmaanNode/NodeAdmin/Modals/_undo_delete.html.twig' %} {% include '@KunstmaanNode/NodeAdmin/Modals/_duplicate.html.twig' %} {% if showDuplicateWithChildren %} From e5767983398473ce6c654d2c169a6e079f2fc619 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 7 Aug 2020 11:41:31 +0200 Subject: [PATCH 09/17] feature/undelete-nodes --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index c77d0ab865..ae4592998f 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -514,7 +514,7 @@ function (EntityInterface $item) use ($locale, $acl) { return null; }, 'undo', - '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' + '@KunstmaanAdmin/Settings/undo_delete_button.html.twig' ); return $this->renderAdminList($request, $nodeAdminListConfigurator); From 4391b9f89fd8378ab4b16b0f78aca5aa863c7111 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 7 Aug 2020 11:44:16 +0200 Subject: [PATCH 10/17] feature/undelete-nodes --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 4 ++-- .../Resources/views/Admin/undo_delete_button.html.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index ae4592998f..1e2a39fd33 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -513,8 +513,8 @@ function (EntityInterface $item) use ($locale, $acl) { return null; }, - 'undo', - '@KunstmaanAdmin/Settings/undo_delete_button.html.twig' + 'fa fa-undo', + '@KunstmaanNode\Admin\undo_delete_button.html.twig' ); return $this->renderAdminList($request, $nodeAdminListConfigurator); diff --git a/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig index c1fbc9f1bb..cfc3b4a6b2 100644 --- a/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig +++ b/src/Kunstmaan/NodeBundle/Resources/views/Admin/undo_delete_button.html.twig @@ -1,5 +1,5 @@ - + From 602924a63e7cb3f1cba9215e57e4743699e49df4 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 7 Aug 2020 11:45:40 +0200 Subject: [PATCH 11/17] feature/undelete-nodes --- .../Resources/views/NodeAdmin/Modals/_undo_delete.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig index 54caa5e5d6..1bd4b5cf21 100644 --- a/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig +++ b/src/Kunstmaan/NodeBundle/Resources/views/NodeAdmin/Modals/_undo_delete.html.twig @@ -7,12 +7,12 @@ -

{{ 'kuma_node.modal.delete_page.title.%page%'|trans({'%page%': page.title}) }}

+

{{ 'kuma_node.modal.undo_delete_page.title.%page%'|trans({'%page%': page.title}) }}

From a51b83aedf208b40b49620d99cdf3b7cfb166c23 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 28 Aug 2020 11:34:53 +0200 Subject: [PATCH 12/17] Fix invalid use --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 1e2a39fd33..8f66996a15 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -5,7 +5,6 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; -use Esites\CustomerAdminBundle\Entity\User; use InvalidArgumentException; use Kunstmaan\AdminBundle\Entity\BaseUser; use Kunstmaan\AdminBundle\Entity\EntityInterface; @@ -17,7 +16,6 @@ use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap; use Kunstmaan\AdminBundle\Service\AclManager; use Kunstmaan\AdminListBundle\AdminList\AdminList; -use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction; use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction; use Kunstmaan\NodeBundle\AdminList\DeletedNodeAdminListConfigurator; use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator; From d12fa0d8f0d223842c2698153b558543c69d8cc8 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 28 Aug 2020 14:00:03 +0200 Subject: [PATCH 13/17] Set deleted parameter --- .../AdminList/DeletedNodeAdminListConfigurator.php | 5 +---- .../NodeBundle/AdminList/NodeAdminListConfigurator.php | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php index 48dbf0af05..5bf6ccdbfa 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/DeletedNodeAdminListConfigurator.php @@ -30,9 +30,6 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) { parent::adaptQueryBuilder($queryBuilder); - $queryBuilder - ->where('b.lang = :lang') - ->andWhere('n.deleted = 1') - ; + $queryBuilder->setParameter('deleted', 1); } } diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index 0093929b6b..5d0e880809 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -245,9 +245,11 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->select('b,n') ->innerJoin('b.node', 'n', Join::WITH, 'b.node = n.id') ->andWhere('b.lang = :lang') - ->andWhere('n.deleted = 0') + ->andWhere('n.deleted = :deleted') ->addOrderBy('b.updated', Criteria::DESC) - ->setParameter('lang', $this->locale); + ->setParameter('lang', $this->locale) + ->setParameter('deleted', 0) + ; if (!$this->domainConfiguration) { return; From 1a35997907686111683779b1f5b4f8071a089cc8 Mon Sep 17 00:00:00 2001 From: JZuidema <37873948+JZuidema@users.noreply.github.com> Date: Fri, 4 Sep 2020 13:02:48 +0200 Subject: [PATCH 14/17] Update src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php Co-authored-by: Numkil --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 8f66996a15..67aabc4612 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -492,7 +492,7 @@ public function deletedNodesAction(Request $request) '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' ) ); - + $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); $locale = $this->locale; $acl = $this->authorizationChecker; From d59d195edd318bd0bcacc7c5048bf4b2d39a27c7 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 25 Sep 2020 14:52:12 +0200 Subject: [PATCH 15/17] Configure enabling undo deleting nodes --- .../Controller/NodeAdminController.php | 42 +++++++++++++++---- .../DependencyInjection/Configuration.php | 1 + .../KunstmaanNodeExtension.php | 1 + .../Helper/Menu/ActionsMenuBuilder.php | 16 +++++-- .../NodeBundle/Resources/config/services.yml | 1 + 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 8f66996a15..9a07ebaf39 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -92,9 +92,16 @@ class NodeAdminController extends Controller */ protected $translator; - /** @var PageCloningHelper */ + /** + * @var PageCloningHelper + */ private $pageCloningHelper; + /** + * @var bool + */ + private $isUndoDeletingNodesEnabled; + /** * init * @@ -111,6 +118,9 @@ protected function init(Request $request) $this->nodePublisher = $this->container->get('kunstmaan_node.admin_node.publisher'); $this->translator = $this->container->get('translator'); $this->pageCloningHelper = $this->container->get(PageCloningHelper::class); + $this->isUndoDeletingNodesEnabled = $this->container->getParameter( + 'kunstmaan_node.kunstmaan_node.enable_undo_deleting_nodes' + ); } /** @@ -147,6 +157,22 @@ public function indexAction(Request $request) }; $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); + $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); + $nodeAdminListConfigurator->setShowAddHomepage( + $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') + ); + + $this->addViewDeletedNodesAction($nodeAdminListConfigurator); + + return $this->renderAdminList($request, $nodeAdminListConfigurator); + } + + private function addViewDeletedNodesAction(NodeAdminListConfigurator $nodeAdminListConfigurator): void + { + if (!$this->isUndoDeletingNodesEnabled) { + return; + } + $nodeAdminListConfigurator->addListAction( new SimpleListAction( [ @@ -158,12 +184,6 @@ public function indexAction(Request $request) '@KunstmaanAdmin/Settings/button_resolve_all.html.twig' ) ); - $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration')); - $nodeAdminListConfigurator->setShowAddHomepage( - $this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN') - ); - - return $this->renderAdminList($request, $nodeAdminListConfigurator); } /** @@ -474,6 +494,10 @@ public function deletedNodesAction(Request $request) { $this->init($request); + if (!$this->isUndoDeletingNodesEnabled) { + throw $this->createAccessDeniedException(); + } + $nodeAdminListConfigurator = new DeletedNodeAdminListConfigurator( $this->em, $this->aclHelper, @@ -534,6 +558,10 @@ public function undoDeleteAction(Request $request, $id) { $this->init($request); + if (!$this->isUndoDeletingNodesEnabled) { + throw $this->createAccessDeniedException(); + } + /* @var Node $node */ $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); diff --git a/src/Kunstmaan/NodeBundle/DependencyInjection/Configuration.php b/src/Kunstmaan/NodeBundle/DependencyInjection/Configuration.php index 6014dc3f7f..a6476dd2a1 100644 --- a/src/Kunstmaan/NodeBundle/DependencyInjection/Configuration.php +++ b/src/Kunstmaan/NodeBundle/DependencyInjection/Configuration.php @@ -61,6 +61,7 @@ public function getConfigTreeBuilder() ->booleanNode('show_add_homepage')->defaultTrue()->end() ->booleanNode('show_duplicate_with_children')->defaultFalse()->end() ->booleanNode('enable_export_page_template')->defaultFalse()->end() + ->booleanNode('enable_undo_deleting_nodes')->defaultTrue()->end() ->arrayNode('lock') ->addDefaultsIfNotSet() ->canBeEnabled() diff --git a/src/Kunstmaan/NodeBundle/DependencyInjection/KunstmaanNodeExtension.php b/src/Kunstmaan/NodeBundle/DependencyInjection/KunstmaanNodeExtension.php index fff347a8eb..f65c3d1089 100644 --- a/src/Kunstmaan/NodeBundle/DependencyInjection/KunstmaanNodeExtension.php +++ b/src/Kunstmaan/NodeBundle/DependencyInjection/KunstmaanNodeExtension.php @@ -39,6 +39,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('kunstmaan_node.show_add_homepage', $config['show_add_homepage']); $container->setParameter('kunstmaan_node.show_duplicate_with_children', $config['show_duplicate_with_children']); $container->setParameter('kunstmaan_node.enable_export_page_template', $config['enable_export_page_template']); + $container->setParameter('kunstmaan_node.enable_undo_deleting_nodes', $config['enable_undo_deleting_nodes']); $container->setParameter('kunstmaan_node.lock_check_interval', $config['lock']['check_interval']); $container->setParameter('kunstmaan_node.lock_threshold', $config['lock']['threshold']); $container->setParameter('kunstmaan_node.lock_enabled', $config['lock']['enabled']); diff --git a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php index 8aabe965d7..96dc3c4a7e 100644 --- a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php +++ b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php @@ -64,9 +64,16 @@ class ActionsMenuBuilder */ private $enableExportPageTemplate; - /** @var bool */ + /** + * @var bool + */ private $showDuplicateWithChildren; + /** + * @var bool + */ + private $enableUndoDeletingNodes; + /** * @param FactoryInterface $factory * @param EntityManager $em @@ -76,6 +83,7 @@ class ActionsMenuBuilder * @param PagesConfiguration $pagesConfiguration * @param bool $enableExportPageTemplate * @param bool $showDuplicateWithChildren + * @param bool $enableUndoDeletingNodes */ public function __construct( FactoryInterface $factory, @@ -85,7 +93,8 @@ public function __construct( AuthorizationCheckerInterface $authorizationChecker, PagesConfiguration $pagesConfiguration, $enableExportPageTemplate = true, - bool $showDuplicateWithChildren = false + bool $showDuplicateWithChildren = false, + bool $enableUndoDeletingNodes = true ) { $this->factory = $factory; $this->em = $em; @@ -95,6 +104,7 @@ public function __construct( $this->pagesConfiguration = $pagesConfiguration; $this->enableExportPageTemplate = $enableExportPageTemplate; $this->showDuplicateWithChildren = $showDuplicateWithChildren; + $this->enableUndoDeletingNodes = $enableUndoDeletingNodes; } /** @@ -432,7 +442,7 @@ public function createActionsMenu() 'extras' => ['renderType' => 'button'], ] ); - } else { + } else if ($this->enableUndoDeletingNodes) { $menu->addChild( 'action.undo_delete', [ diff --git a/src/Kunstmaan/NodeBundle/Resources/config/services.yml b/src/Kunstmaan/NodeBundle/Resources/config/services.yml index 13c3bdbbb1..2e70f714e9 100644 --- a/src/Kunstmaan/NodeBundle/Resources/config/services.yml +++ b/src/Kunstmaan/NodeBundle/Resources/config/services.yml @@ -100,6 +100,7 @@ services: - '@kunstmaan_node.pages_configuration' - '%kunstmaan_node.enable_export_page_template%' - '%kunstmaan_node.show_duplicate_with_children%' + - '%kunstmaan_node.enable_undo_deleting_nodes%' public: true kunstmaan_node.menu.sub_actions: From ed191962c28b88b266cedbd535a77be9d8aaf4c7 Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 25 Sep 2020 15:00:03 +0200 Subject: [PATCH 16/17] Return when node is not deleted --- .../Controller/NodeAdminController.php | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index f70f4e5e62..6d2c276963 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -486,12 +486,8 @@ public function deleteAction(Request $request, $id) /** * @Route("/deleted", name="KunstmaanNodeBundle_deleted_nodes") * @Template("@KunstmaanNode/Admin/deleted_list.html.twig") - * - * @param Request $request - * - * @return array */ - public function deletedNodesAction(Request $request) + public function deletedNodesAction(Request $request): array { $this->init($request); @@ -549,13 +545,8 @@ function (EntityInterface $item) use ($locale, $acl) { * requirements={"id" = "\d+"}, * name="KunstmaanNodeBundle_nodes_delete_undo", * ) - * - * @param Request $request - * @param int $id - * - * @return RedirectResponse */ - public function undoDeleteAction(Request $request, $id) + public function undoDeleteAction(Request $request, int $id): RedirectResponse { $this->init($request); @@ -564,7 +555,7 @@ public function undoDeleteAction(Request $request, $id) } /* @var Node $node */ - $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); + $node = $this->em->getRepository(Node::class)->find($id); try { $this->undoDeleteNode($node); @@ -1362,12 +1353,11 @@ private function deleteNodeChildren( } } - /** - * @param Node $node - */ - private function undoDeleteNode( - Node $node - ) { + private function undoDeleteNode(Node $node): void { + if (!$node->isDeleted()) { + return; + } + $this->denyAccessUnlessGranted( PermissionMap::PERMISSION_DELETE, $node @@ -1492,16 +1482,10 @@ private function dispatch($event, string $eventName) return $eventDispatcher->dispatch($eventName, $event); } - /** - * @param Request $request - * @param NodeAdminListConfigurator $nodeAdminListConfigurator - * - * @return array - */ private function renderAdminList( Request $request, NodeAdminListConfigurator $nodeAdminListConfigurator - ) { + ): array { /** @var AdminList $adminList */ $adminList = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); $adminList->bindRequest($request); From d379ffbdc0be6fc4f3d94fde1391c1a3354e316c Mon Sep 17 00:00:00 2001 From: Joshwin Zuidema Date: Fri, 25 Sep 2020 15:01:29 +0200 Subject: [PATCH 17/17] Fix style --- src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php | 3 ++- src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 6d2c276963..3c067e0af8 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -1353,7 +1353,8 @@ private function deleteNodeChildren( } } - private function undoDeleteNode(Node $node): void { + private function undoDeleteNode(Node $node): void + { if (!$node->isDeleted()) { return; } diff --git a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php index eb972b8a3b..92f1b54e90 100644 --- a/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php +++ b/src/Kunstmaan/NodeBundle/Helper/Menu/ActionsMenuBuilder.php @@ -443,7 +443,7 @@ public function createActionsMenu() 'extras' => ['renderType' => 'button'], ] ); - } else if ($this->enableUndoDeletingNodes) { + } elseif ($this->enableUndoDeletingNodes) { $menu->addChild( 'action.undo_delete', [