Custom permission plugin

Hi,



I am trying to develop a plugin with some special permissions and came across this problem: when you are trying to save the permission settings through Role -> Your permission then Mautic gives an error. Changing the source code in CorePermissions.php to put in debug info gives me the following stack trace. I believe there is a bug in the generatePermission function where it always assumes the plugin is a core plugin when calling getPermissionObject. I’ve hacked the code pass in pluginBundle = true when it detects the name of my plugin and it’s no longer giving an error (although still not working but that’s probably due to something in my plugin). I am trying to fix the issue properly by calling “getPluginBundles” and try to see if my bundle is in the array to turn on the pluginBundle flag but not managed to get it working yet. I am new to Mautic and php so might take me a while but this may be a 5 mins job for a pro…



I was running mautic 1.2.0.



[2015-10-26 15:30:35] mautic.CRITICAL: Uncaught PHP Exception InvalidArgumentException: “Permission class not found for HelloWorldBundle! $bundle=HelloWorld $bundleName MauticHelloWorldBundle $exists_check=not entered the class_exists check isMauticBundle=true pluginBundle=

#0 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php(231): MauticCoreBundleSecurityPermissionsCorePermissions->getPermissionObject(‘helloWorld’, true, false)

#1 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Model/RoleModel.php(77): MauticCoreBundleSecurityPermissionsCorePermissions->generatePermissions(Array)

##2 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Controller/RoleController.php(252): MauticUserBundleModelRoleModel->setRolePermissions(Object(MauticUserBundleEntityRole), Array)

##3 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Controller/CommonController.php(308): MauticUserBundleControllerRoleController->editAction(‘3’, ‘’)

##4 [internal function]: MauticCoreBundleControllerCommonController->executeAction(‘edit’, ‘3’, 0, ‘’)

##5 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3051): call_user_func_array(Array, Array)

##6 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3013): SymfonyComponentHttpKernelHttpKernel->handleRaw(Object(SymfonyComponentHttpFoundationRequest), 1)

##7 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3162): SymfonyComponentHttpKernelHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)

##8 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(2403): SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)

##9 /homepages/21/d550045627/htdocs/mautic/app/AppKernel.php(110): SymfonyComponentHttpKernelKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)

##10 /homepages/21/d550045627/htdocs/mautic/index.php(56): AppKernel->handle(Object(SymfonyComponentHttpFoundationRequest))

##11 {main}” at /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php line 161 {“exception”:"[object] (InvalidArgumentException(code: 0): Permission class not found for HelloWorldBundle! $bundle=HelloWorld $bundleName MauticHelloWorldBundle $exists_check=not entered the class_exists check isMauticBundle=true pluginBundle=

##0 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php(231): Mautic\CoreBundle\Security\Permissions\CorePermissions->getPermissionObject(‘helloWorld’, true, false)n

##1 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Model/RoleModel.php(77): Mautic\CoreBundle\Security\Permissions\CorePermissions->generatePermissions(Array)n

##2 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Controller/RoleController.php(252): Mautic\UserBundle\Model\RoleModel->setRolePermissions(Object(Mautic\UserBundle\Entity\Role), Array)n

##3 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Controller/CommonController.php(308): Mautic\UserBundle\Controller\RoleController->editAction(‘3’, ‘’)n

##4 [internal function]: Mautic\CoreBundle\Controller\CommonController->executeAction(‘edit’, ‘3’, 0, ‘’)n

##5 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3051): call_user_func_array(Array, Array)n

##6 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3013): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)n

##7 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3162): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n

##8 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(2403): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n

##9 /homepages/21/d550045627/htdocs/mautic/app/AppKernel.php(110): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n

##10 /homepages/21/d550045627/htdocs/mautic/index.php(56): AppKernel->handle(Object(Symfony\Component\HttpFoundation\Request))n

##11 {main} at /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php:161)"} [

Hi,

I am trying to develop a plugin with some special permissions and came across this problem: when you are trying to save the permission settings through Role -> Your permission then Mautic gives an error. Changing the source code in CorePermissions.php to put in debug info gives me the following stack trace. I believe there is a bug in the generatePermission function where it always assumes the plugin is a core plugin when calling getPermissionObject. I’ve hacked the code pass in pluginBundle = true when it detects the name of my plugin and it’s no longer giving an error (although still not working but that’s probably due to something in my plugin). I am trying to fix the issue properly by calling “getPluginBundles” and try to see if my bundle is in the array to turn on the pluginBundle flag but not managed to get it working yet. I am new to Mautic and php so might take me a while but this may be a 5 mins job for a pro…

I was running mautic 1.2.0.

[2015-10-26 15:30:35] mautic.CRITICAL: Uncaught PHP Exception InvalidArgumentException: “Permission class not found for HelloWorldBundle! $bundle=HelloWorld $bundleName MauticHelloWorldBundle $exists_check=not entered the class_exists check isMauticBundle=true pluginBundle=
#0 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php(231): MauticCoreBundleSecurityPermissionsCorePermissions->getPermissionObject(‘helloWorld’, true, false)
#1 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Model/RoleModel.php(77): MauticCoreBundleSecurityPermissionsCorePermissions->generatePermissions(Array)
##2 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Controller/RoleController.php(252): MauticUserBundleModelRoleModel->setRolePermissions(Object(MauticUserBundleEntityRole), Array)
##3 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Controller/CommonController.php(308): MauticUserBundleControllerRoleController->editAction(‘3’, ‘’)
##4 [internal function]: MauticCoreBundleControllerCommonController->executeAction(‘edit’, ‘3’, 0, ‘’)
##5 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3051): call_user_func_array(Array, Array)
##6 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3013): SymfonyComponentHttpKernelHttpKernel->handleRaw(Object(SymfonyComponentHttpFoundationRequest), 1)
##7 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3162): SymfonyComponentHttpKernelHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)
##8 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(2403): SymfonyComponentHttpKernelDependencyInjectionContainerAwareHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)
##9 /homepages/21/d550045627/htdocs/mautic/app/AppKernel.php(110): SymfonyComponentHttpKernelKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)
##10 /homepages/21/d550045627/htdocs/mautic/index.php(56): AppKernel->handle(Object(SymfonyComponentHttpFoundationRequest))
##11 {main}” at /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php line 161 {“exception”:"[object] (InvalidArgumentException(code: 0): Permission class not found for HelloWorldBundle! $bundle=HelloWorld $bundleName MauticHelloWorldBundle $exists_check=not entered the class_exists check isMauticBundle=true pluginBundle=
##0 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php(231): Mautic\CoreBundle\Security\Permissions\CorePermissions->getPermissionObject(‘helloWorld’, true, false)n
##1 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Model/RoleModel.php(77): Mautic\CoreBundle\Security\Permissions\CorePermissions->generatePermissions(Array)n
##2 /homepages/21/d550045627/htdocs/mautic/app/bundles/UserBundle/Controller/RoleController.php(252): Mautic\UserBundle\Model\RoleModel->setRolePermissions(Object(Mautic\UserBundle\Entity\Role), Array)n
##3 /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Controller/CommonController.php(308): Mautic\UserBundle\Controller\RoleController->editAction(‘3’, ‘’)n
##4 [internal function]: Mautic\CoreBundle\Controller\CommonController->executeAction(‘edit’, ‘3’, 0, ‘’)n
##5 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3051): call_user_func_array(Array, Array)n
##6 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3013): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)n
##7 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(3162): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n
##8 /homepages/21/d550045627/htdocs/mautic/app/bootstrap.php.cache(2403): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n
##9 /homepages/21/d550045627/htdocs/mautic/app/AppKernel.php(110): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n
##10 /homepages/21/d550045627/htdocs/mautic/index.php(56): AppKernel->handle(Object(Symfony\Component\HttpFoundation\Request))n
##11 {main} at /homepages/21/d550045627/htdocs/mautic/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php:161)"} [

You might be right. However it’s hard to test it. I’d have to develop a sample plugin with permissions. Would you mind to give me your plugin for testing? Or even better, fix the problem in the Mautic and send a pull request.

mine is just the helloworld plugin in the example in developer.mautic.org so a bit embarressed to send over. I am happy to continue working on a fix as described above.

We’ve also came across issues with using uppercase letter (helloWorld) in the plugin name whereas helloworld would work. This may be something we are doing wrong but if not then it may be worth updating the guide at developer.mautic.org.

Cheers,

Linh

Hi John,

I’ve commited a fix to this to my staging branch on github. However, I’ve also committed another fix to a different problem this morning and created a pull request for the earlier fix. Now I cannot work out how to create a new pull request. It keeps getting bunched with the PR for the earlier commit. I’m new to git (always svn until now) so please help if you can. I think the 2 issues deserves 2 different tickets!

Thanks,

Linh