How to redirect editors after login to product list

Questions around the Aimeos bundle for the Symfony framework
Forum rules
Always add your Symfony, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
rasch
Posts: 22
Joined: 02 Sep 2019, 11:51

How to redirect editors after login to product list

Post by rasch » 12 Nov 2019, 09:02

Hi,

How can only editors be redirected to the product list after logging into the backend? Admins and superadmins should continue to be redirected to the dashboard.

Thank your for your help.
--
aimeos: 2019.10.4
symfony: 4.3
php: 7.2
ubuntu: 18

User avatar
aimeos
Administrator
Posts: 8356
Joined: 01 Jan 1970, 00:00

Re: How to redirect editors after login to product list

Post by aimeos » 13 Nov 2019, 10:21

Redirecting admin and editors is done here in the source code:
https://github.com/aimeos/aimeos-symfon ... hp#L33-L47

You can overwrite the controller and the route to make that configurable.
Alternatively, we would also accept a PR that make it configurable based on configuration :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rasch
Posts: 22
Joined: 02 Sep 2019, 11:51

Re: How to redirect editors after login to product list

Post by rasch » 15 Nov 2019, 13:47

I can do that as soon as I understand Aimeos correctly. :)

How can I access groups of the user? In the user object I have access to the role as an array (ROLE_ADMIN), but the groups are empty.
Attachments
empty groups.JPG
empty groups.JPG (16.73 KiB) Viewed 207469 times

User avatar
aimeos
Administrator
Posts: 8356
Joined: 01 Jan 1970, 00:00

Re: How to redirect editors after login to product list

Post by aimeos » 17 Nov 2019, 08:00

You can get the Aimeos groups and use a configuration for the default panel with:

Code: Select all

$config = $context->getConfig();
$custManager = \Aimeos\MShop::create( $context, 'customer' );

foreach( $custManager->getItem( $user->getId(), ['customer/group'] )->getRefItems( 'customer/group' ) as $groupItem )
{
    if( ( $panel = $config->get( 'admin/jqadm/panel/' . $groupItem->getCode() ) !== null ) {
        $resource = $panel;
    }
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rasch
Posts: 22
Joined: 02 Sep 2019, 11:51

Re: How to redirect editors after login to product list

Post by rasch » 20 Nov 2019, 14:03

Many thanks for the help. It works for me.

First I extended the AdminController, get the local object and insert your code in file /src/Controller/MyShopAdminController.php

Code: Select all

namespace App\Controller;

use Symfony\Component\HttpFoundation\Request;
use Aimeos\ShopBundle\Controller\AdminController;

class MyShopAdminController extends AdminController
{
	public function indexAction(Request $request)
	{
		if ($this->hasRole(['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'])) {
			$context = $this->get( 'aimeos.context' )->get(true);
			$config = $context->getConfig();
			$siteManager = \Aimeos\MShop::create( $context, 'locale/site' );
			$user = $this->get( 'security.token_storage' )->getToken()->getUser();
			$siteCode = ( $user->getSiteId() ? $siteManager->getItem( $user->getSiteId() )->getCode() : 'default' );
			$locale = $user->getLanguageId() ?: ( $this->container->hasParameter( 'locale' ) ? $this->container->getParameter( 'locale' ) : 'en' );
			$customerManager = \Aimeos\MShop::create($context, 'customer');
			foreach ($customerManager->getItem($user->getId(), ['customer/group'])->getRefItems('customer/group') as $groupItem) {
				$resource = $config->get('admin/jqadm/panel/' . $groupItem->getCode()) ?: 'dashboard';
			}
			$params = array(
				'resource' => $resource,
				'site' => $request->attributes->get('site', $request->query->get('site', $siteCode)),
				'lang' => $request->attributes->get('lang', $request->query->get('lang', $locale)),
			);
			return $this->redirect($this->generateUrl('aimeos_shop_jqadm_search', $params));
		}
then I added the new configuration option panel in the file config/packages/aimeos_shop.yaml

Code: Select all

admin:
    jqadm:
        panel:
            editor: product
and last changed the route in the file config/routes.yaml

Code: Select all

aimeos_shop_admin:
   path: /admin
   controller: App\Controller\MyShopAdminController::indexAction

Post Reply