User groups for Decorators?
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User groups for Decorators?
Laravel framework version: 9.52.5
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
Is it possible to have a decorator work only for a specific user group?
If not, what is the best way to check if a user is in the admin group inside a decorator?
Thanks
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
Is it possible to have a decorator work only for a specific user group?
If not, what is the best way to check if a user is in the admin group inside a decorator?
Thanks
Re: User groups for Decorators?
Where do you want to use the decorator? Frontend? Admin backend?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: User groups for Decorators?
Hello, I wanted to use the decorator in the backend.
I think I already found the solution.
Solution if you want to use the group ID:
Solution if you want to use the group code:
But I don't need this code anymore, because I've created the decorator in a different way.
It used to mess with order modifications in the frontend, but I think it's fixed now.
The decorator is in a different location now -> Aimeos\Admin\JQAdm\Common\Decorator.
Used to be in Aimeos\MShop\Common\Manager\Decorator.
I think I already found the solution.
Solution if you want to use the group ID:
Code: Select all
$context = $this->context();
$customer = \Aimeos\MShop::create( $context, 'customer' )->get( $context->user() );
$groups = $customer->getGroups();
$isAdmin = in_array( 1, $groups );
$isEditor = in_array( 2, $groups );
dump( 'isAdmin', $isAdmin );
dump( 'isEditor', $isEditor );
dump( 'isSuper', $customer->isSuper() );
Code: Select all
$context = $this->context();
$customer = \Aimeos\MShop::create( $context, 'customer' )->get( $context->user() );
$groups = $customer->getRefItems( 'customer/group' );
$isAdmin = (bool) $groups->find( function( $value, $key ) {
return $value->getCode() === 'admin';
});
$isEditor = (bool) $groups->find( function( $value, $key ) {
return $value->getCode() === 'editor';
});
dump( 'isAdmin', $isAdmin );
dump( 'isEditor', $isEditor );
dump( 'isSuper', $customer->isSuper() );
It used to mess with order modifications in the frontend, but I think it's fixed now.
The decorator is in a different location now -> Aimeos\Admin\JQAdm\Common\Decorator.
Used to be in Aimeos\MShop\Common\Manager\Decorator.
Re: User groups for Decorators?
Don't mess with group IDs and use the access() view helper instead:
https://aimeos.org/docs/latest/infrastr ... ew/#access
https://aimeos.org/docs/latest/infrastr ... ew/#access
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: User groups for Decorators?
I tried this, but in the following case the user is in the admin group, but not in the editor group.aimeos wrote: ↑07 Apr 2023, 09:15 Don't mess with group IDs and use the access() view helper instead:
https://aimeos.org/docs/latest/infrastr ... ew/#access
Code: Select all
$view = $this->view();
dump( $view->access( ['editor'] ) );
This is done in a decorator Aimeos\Admin\JQAdm\Common\Decorator\<My Decorator>::save()
Re: User groups for Decorators?
It's OK to do that in a decorator or a template - that doesn't matter.kdim95 wrote: ↑07 Apr 2023, 09:37 I tried this, but in the following case the user is in the admin group, but not in the editor group.
Whatever I put in the array, be it 'editor', 'admin', it always returns true.Code: Select all
$view = $this->view(); dump( $view->access( ['editor'] ) );
This is done in a decorator Aimeos\Admin\JQAdm\Common\Decorator\<My Decorator>::save()
If it returns true in both cases, then the user must be in both groups because the code for checking is very easy:
https://github.com/aimeos/aimeos-base/b ... rd.php#L52
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star