Permission class not found for plugin

Hello All,



I am using this code in my controller.

Code:
$permissions = $this->factory->getSecurity()->isGranted(array( 'feedman:feed:create', ), "RETURN_ARRAY");
which is generating this error
Quote:
Uncaught PHP Exception InvalidArgumentException: "Permission class not found for FeedmanBundle!" at Uncaught PHP Exception InvalidArgumentException: "Permission class not found for FeedmanBundle!" at C:xampphtdocsmautic1.2.3appbundlesCoreBundleSecurityPermissionsCorePermissions.php line 151

I have created a permissions class in permissions folder
Quote:
<?php
// plugins/FeedManBundle/Security/Permissions/FeedManPermissions.php

namespace MauticPluginFeedManBundleSecurityPermissions;

use SymfonyComponentFormFormBuilderInterface;
use MauticCoreBundleSecurityPermissionsAbstractPermissions;

/**
* Class FeedManPermissions
*/
class FeedManPermissions extends AbstractPermissions
{

/**
* Define available permissions
*
* @param $params
*/
public function __construct($params)
{
parent::__construct($params);

$this->permissions = array(

// Custom level
'feed' => array(

// Custom permissions
'create' => 1,
'send_probe' => 2,
'visit' => 4,
// Full will almost always be included and should be significantly higher than the
// others in case new permissions need to be added later
'full' => 1024
)
);

// Add standard category permissions
$this->addStandardPermissions('categories');
}

/**
* Append the permission form fields to the Role form
*
* @param FormBuilderInterface $builder
* @param array $options
* @param array $data
*/
public function buildForm(FormBuilderInterface &$builder, array $options, array $data)
{
/* // Add standard category form fields
$this->addStandardFormFields('helloWorld', 'categories', $builder, $data);

// Add custom 'worlds' level form fields
$builder->add(

// Form element name should be bundleName:permissionLevel
'helloWorld:worlds',

// Should always be permissionlist type
'permissionlist',
array(
'choices' => array(
'use_telescope' => 'plugin.helloworld.permissions.use_telescope',
'send_probe' => 'plugin.helloworld.permissions.send_probe',
'visit' => 'plugin.helloworld.permissions.visit',
'full' => 'mautic.core.permissions.full',
),
'label' => 'plugin.helloworld.permissions',

// Set existing data
'data' => (!empty($data) ? $data : array()),

// Bundle name (used to build frontend form)
'bundle' => 'helloWorld',

// Permission level (used to build frontend form)
'level' => 'worlds'
)
);*/
}

/**
* Permission set identifier; should be bundleName
*
* @return string
*/
public function getName()
{
return 'feedman';
}
}


but not sure why it is showing error. Please help.

Thanks

Hello All,

I am using this code in my controller.

$permissions = $this->factory->getSecurity()->isGranted(array( 'feedman:feed:create', ), "RETURN_ARRAY");
which is generating this error

I have created a permissions class in permissions folder

[quote]<?php
// plugins/FeedManBundle/Security/Permissions/FeedManPermissions.php

namespace MauticPluginFeedManBundleSecurityPermissions;

use SymfonyComponentFormFormBuilderInterface;
use MauticCoreBundleSecurityPermissionsAbstractPermissions;

/**

  • Class FeedManPermissions
    */
    class FeedManPermissions extends AbstractPermissions
    {

    /**

    • Define available permissions

    • @param $params
      */
      public function __construct($params)
      {
      parent::__construct($params);

      $this->permissions = array(

       // Custom level
       'feed' => array(
      
           // Custom permissions
           'create' => 1,
           'send_probe'    => 2,
           'visit'         => 4,
           // Full will almost always be included and should be significantly higher than the
           // others in case new permissions need to be added later 
           'full'          => 1024
       )
      

      );

      // Add standard category permissions
      $this->addStandardPermissions(‘categories’);
      }

    /**

    • Append the permission form fields to the Role form

    • @param FormBuilderInterface $builder

    • @param array $options

    • @param array $data
      /
      public function buildForm(FormBuilderInterface &$builder, array $options, array $data)
      {
      /
      // Add standard category form fields
      $this->addStandardFormFields(‘helloWorld’, ‘categories’, $builder, $data);

      // Add custom ‘worlds’ level form fields
      $builder->add(

       // Form element name should be bundleName:permissionLevel
       'helloWorld:worlds',
      
       // Should always be permissionlist type
       'permissionlist',
       array(
           'choices' => array(
               'use_telescope' => 'plugin.helloworld.permissions.use_telescope',
               'send_probe'    => 'plugin.helloworld.permissions.send_probe',
               'visit'         => 'plugin.helloworld.permissions.visit',
               'full'          => 'mautic.core.permissions.full',
           ),
           'label'   => 'plugin.helloworld.permissions',
      
           // Set existing data
           'data'    => (!empty($data['worlds']) ? $data['worlds'] : array()),
      
           // Bundle name (used to build frontend form)
           'bundle'  => 'helloWorld',
      
           // Permission level (used to build frontend form)
           'level'   => 'worlds'
       )
      

      );*/
      }

    /**

    • Permission set identifier; should be bundleName
    • @return string
      */
      public function getName()
      {
      return ‘feedman’;
      }
      }[/quote]

but not sure why it is showing error. Please help.

Thanks

When calling plugin permissions, you need to preface it with plugin:. https://developer.mautic.org/#using-permissions

Try plugin:feedman:feed:create.

Thanks!

[quote=6069:@alanhartless]When calling plugin permissions, you need to preface it with plugin:. https://developer.mautic.org/#using-permissions

Try plugin:feedman:feed:create.

Thanks![/quote]
Sorry for delay in responding. I have tried that but it is still not working.
It seems like something is wrong with FeedManPermissions.php Class
Below is my code in controller

[code]<?php
/**

namespace MauticPluginFeedManBundleController;
use MauticCoreBundleControllerFormController as CommonFormController;
use SymfonyComponentHttpFoundationResponse;
/**

  • Class DefaultController
    */
    class DefaultController extends CommonFormController
    {

    /**

    • @param int $objectId
    • @param int $page
    • @return SymfonyComponentHttpFoundationJsonResponse|SymfonyComponentHttpFoundationRedirectResponse|SymfonyComponentHttpFoundationResponse
      */
      public function indexAction($page=1)
      {

    //set some permissions
    $permissions = $this->factory->getSecurity()->isGranted(array(
    ‘plugin:feedman:feed:create’,

     ), "RETURN_ARRAY");
     //$permissions['plugin:feedman:feed:create'] =4;
      $viewParameters = array(
        /*  'searchValue' => $search,
        'items'       => $forms,
         'totalItems'  => $count,*/
          /*'page'        => $page,
         'limit'       => $limit,*/
         'permissions' => $permissions,
         'security'    => $this->factory->getSecurity(),
         'tmpl'        => $this->request->get('tmpl', 'index')
     );
      return $this->delegateView(array(
     	  'viewParameters'  => $viewParameters,
         'contentTemplate' => 'FeedManBundle:Default:index.html.php',
         'passthroughVars' => array(
             'activeLink'     => '#feedman_index',
             'mauticContent'  => 'mydemo',
             'route'          => $this->generateUrl('feedman_index')
         )
     ));
     
     /*
     $formModel = $this->factory->getModel('form.form');
     $form      = $formModel->getEntity($objectId);
     $session   = $this->factory->getSession();
     $formPage  = $session->get('mautic.form.page', 1);
     $returnUrl = $this->generateUrl('mautic_form_index', array('page' => $formPage));
    
     if ($form === null) {
         //redirect back to form list
         return $this->postActionRedirect(array(
             'returnUrl'       => $returnUrl,
             'viewParameters'  => array('page' => $formPage),
             'contentTemplate' => 'MauticFormBundle:Form:index',
             'passthroughVars' => array(
                 'activeLink'    => 'mautic_form_index',
                 'mauticContent' => 'form'
             ),
             'flashes'         => array(array(
                 'type'    => 'error',
                 'msg'     => 'mautic.form.error.notfound',
                 'msgVars' => array('%id%' => $objectId)
             ))
         ));
     } elseif (!$this->factory->getSecurity()->hasEntityAccess(
         'form:forms:viewown', 'form:forms:viewother', $form->getCreatedBy()
     ))  {
         return $this->accessDenied();
     }
    
     if ($this->request->getMethod() == 'POST') {
         $this->setListFilters();
     }
    
     //set limits
     $limit = $session->get('mautic.formresult.'.$objectId.'.limit', $this->factory->getParameter('default_pagelimit'));
    
     $start = ($page === 1) ? 0 : (($page-1) * $limit);
     if ($start < 0) {
         $start = 0;
     }
    
     $orderBy    = $session->get('mautic.formresult.'.$objectId.'.orderby', 's.date_submitted');
     $orderByDir = $session->get('mautic.formresult.'.$objectId.'.orderbydir', 'ASC');
     $filters    = $session->get('mautic.formresult.'.$objectId.'.filters', array());
    
     $model = $this->factory->getModel('form.submission');
    
     //get the results
     $entities = $model->getEntities(
         array(
             'start'          => $start,
             'limit'          => $limit,
             'filter'         => array('force' => $filters),
             'orderBy'        => $orderBy,
             'orderByDir'     => $orderByDir,
             'form'           => $form,
             'withTotalCount' => true
         )
     );
    
     $count   = $entities['count'];
     $results = $entities['results'];
     unset($entities);
    
     if ($count && $count < ($start + 1)) {
         //the number of entities are now less then the current page so redirect to the last page
         $lastPage = ($count === 1) ? 1 : (ceil($count / $limit)) ?: 1;
         $session->set('mautic.formresult.page', $lastPage);
         $returnUrl = $this->generateUrl('mautic_form_results', array('objectId' => $objectId, 'page' => $lastPage));
    
         return $this->postActionRedirect(array(
             'returnUrl'       => $returnUrl,
             'viewParameters'  => array('page' => $lastPage),
             'contentTemplate' => 'MauticFormBundle:Result:index',
             'passthroughVars' => array(
                 'activeLink'    => 'mautic_form_index',
                 'mauticContent' => 'formresult'
             )
         ));
     }
    
     //set what page currently on so that we can return here if need be
     $session->set('mautic.formresult.page', $page);
    
     $tmpl = $this->request->isXmlHttpRequest() ? $this->request->get('tmpl', 'index') : 'index';
     return $this->delegateView(array(
         'viewParameters'  => array(
             'items'       => $results,
             'filters'     => $filters,
             'form'        => $form,
             'page'        => $page,
             'totalCount'  => $count,
             'limit'       => $limit,
             'tmpl'        => $tmpl,
             'canDelete'   => $this->factory->getSecurity()->hasEntityAccess('form:forms:editown', 'form:forms:editother', $form->getCreatedBy())
         ),
         'contentTemplate' => 'MauticFormBundle:Result:list.html.php',
         'passthroughVars' => array(
             'activeLink'    => 'mautic_form_index',
             'mauticContent' => 'formresult',
             'route'         => $this->generateUrl('mautic_form_results', array(
                 'objectId'       => $objectId,
                 'page'           => $page
             ))
         )
     ));*/
    

    }

    /**

    • @param int $objectId

    • @param string $format

    • @return SymfonyComponentHttpFoundationStreamedResponse

    • @throws Exception
      */
      public function worldAction($objectId, $page){

      return “Hello worerer”;

    }
    public function adminAction($objectId, $page){

     return "Hello admin";
    

    }
    public function goodbyeAction($objectId, $page){

     return "Hello goodbye";
    

    }
    public function contactAction($objectId, $page){

     return "Hello contact";
    

    }
    public function howdyAction($objectId, $page){

     return "Hello howdy";
    

    }
    }
    [/code]

I noticed something here in your error message:

Uncaught PHP Exception InvalidArgumentException: "Permission class not found for FeedmanBundle!

Feedman has a lowercase m while your bundle is named FeedMan.

This might be what’s causing the issue?

Yes, that was the issue. plugin:feedMan:feed:create. Here was the case issue.
Thanks for helping me vln104 alanhartless