sulu/SuluAutomationBundle

Server error when navigating from page to contacts

Closed this issue · 2 comments

Q A
Bug? yes
New Feature? no
Bundle Version 2.0-dev
Sulu Version 2.2.8

Actual Behavior

After installing and enabling the SuluAutomationBundle in a Sulu 2.2 project, the following request is sent to the server when navigating from a page to a unlocalized view like the contact list:

http://demo.localhost:8001/admin/api/task/count?locale=undefined&entityId=undefined&entityClass=Sulu%5CBundle%5CPageBundle%5CDocument%5CBasePageDocument

This leads to the following error on the server:

{
   "code":0,
   "message":"Permission \"view\" in localization \"undefined\" for object with id \"\" and of type \"\" not granted",
   "errors":[
      "Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException: Permission \"view\" in localization \"undefined\" for object with id \"\" and of type \"\" not granted in \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/sulu\/sulu\/src\/Sulu\/Component\/Security\/Authorization\/AbstractSecurityChecker.php:38\nStack trace:\n#0 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/sulu\/sulu\/src\/Sulu\/Bundle\/SecurityBundle\/EventListener\/SuluSecurityListener.php(106): Sulu\\Component\\Security\\Authorization\\AbstractSecurityChecker->checkPermission(Object(Sulu\\Component\\Security\\Authorization\\SecurityCondition), 'view')\n#1 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php(117): Sulu\\Bundle\\SecurityBundle\\EventListener\\SuluSecurityListener->onKernelController(Object(Symfony\\Component\\HttpKernel\\Event\\ControllerEvent), 'kernel.controll...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#2 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(230): Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke(Object(Symfony\\Component\\HttpKernel\\Event\\ControllerEvent), 'kernel.controll...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#3 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(59): Symfony\\Component\\EventDispatcher\\EventDispatcher->callListeners(Array, 'kernel.controll...', Object(Symfony\\Component\\HttpKernel\\Event\\ControllerEvent))\n#4 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php(151): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ControllerEvent), 'kernel.controll...')\n#5 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/HttpKernel.php(145): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ControllerEvent), 'kernel.controll...')\n#6 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/HttpKernel.php(79): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#7 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/Kernel.php(195): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#8 \/Users\/niklas\/Development\/projects\/sulu-demo\/public\/index.php(67): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#9 {main}\n\nNext Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException: Permission \"view\" in localization \"undefined\" for object with id \"\" and of type \"\" not granted in \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/security-http\/Firewall\/ExceptionListener.php:137\nStack trace:\n#0 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/security-http\/Firewall\/ExceptionListener.php(102): Symfony\\Component\\Security\\Http\\Firewall\\ExceptionListener->handleAccessDeniedException(Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent), Object(Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException))\n#1 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php(117): Symfony\\Component\\Security\\Http\\Firewall\\ExceptionListener->onKernelException(Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent), 'kernel.exceptio...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#2 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(230): Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke(Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent), 'kernel.exceptio...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#3 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php(59): Symfony\\Component\\EventDispatcher\\EventDispatcher->callListeners(Array, 'kernel.exceptio...', Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent))\n#4 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php(151): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent), 'kernel.exceptio...')\n#5 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/HttpKernel.php(218): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch(Object(Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent), 'kernel.exceptio...')\n#6 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/HttpKernel.php(90): Symfony\\Component\\HttpKernel\\HttpKernel->handleThrowable(Object(Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException), Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#7 \/Users\/niklas\/Development\/projects\/sulu-demo\/vendor\/symfony\/http-kernel\/Kernel.php(195): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#8 \/Users\/niklas\/Development\/projects\/sulu-demo\/public\/index.php(67): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#9 {main}"
   ]
}

Expected Behavior

Switching from a page form to an unlocalized view should not lead to any errors on the server.

Steps to Reproduce

  1. Open the edit form of a page
  2. Navigate to an unlocalized view like the contact list

I think this happens because Sulu tries to update the content of the badge of the automation tab when the route is changed. It looks like this reaction is still triggered when navigating away from the view that includes the badge.

One way to solve this would be passing the route of the Tab view that renders the badge to the badge via a tabRoute prop here:
https://github.com/sulu/sulu/blob/457947c60f68abf37ad7c7eecdeeab2fcbf5d0a8/src/Sulu/Bundle/AdminBundle/Resources/js/views/Tabs/Tabs.js#L173-L181

After this, we can only send a request to the server if the new route is a child/descendant of the given tabRoute in the BadgeStore:
https://github.com/sulu/sulu/blob/457947c60f68abf37ad7c7eecdeeab2fcbf5d0a8/src/Sulu/Bundle/AdminBundle/Resources/js/containers/Badge/stores/BadgeStore.js#L35-L37