Warning: You are browsing the documentation from version 4 to 10 of Pimcore. Please visit https://pimcore.com/docs/platform/ for the latest versions of Pimcore.
Version: Edit on GitHub

Add your own permissions

Add your permission to the database

Choose a custom unique name and add it to the users_permission_definitions table in your database. You should now be able to select the permission in the users/roles tabs: CustomPermissionPimcore

Verify the permission

Inside an AdminController

namespace App\Controller;


use Pimcore\Bundle\AdminBundle\Controller\AdminController as PimcoreAdminController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class AdminController extends PimcoreAdminController
{
    /**
     * @Route("/admin/my-admin-action")
     * @param Request $request
     */
    public function myAdminAction(Request $request) {

        /** @var \Pimcore\Security\User\User $user */
        $user = $this->getUser();
        $pimcoreUser = $user->getUser();

        if($pimcoreUser->isAllowed('my_permission')) {
            ...
        }
    }
}

In the frontend (bundle)

document.addEventListener(pimcore.events.pimcoreReady, (e) => {
    if(pimcore.currentuser.permissions.indexOf("my_permission") >= 0) {
        ...
    }
});