Enabling a ProcessMaker Plugin By Permission

I received a question last week and thought it would make a good subject for a blog post.

So here is the question:

Hi Ethan,

I created my plugin and with the plugin I also created a Role for the plugin as well as a Permission.

I assigned some users with the correct Role and Permissions.

My problem is, the plugin is now showing for all users, even the ones that don’t have the Role or Permission assigned to them.

I don’t understand what I am doing wrong.

Can you please help me figure this out?

Sincerely,

A Desperate Developer

So here is the answer:

After you create the Role and Permission in the plugin-name.php file (which sits at the root of the plugins folder) you need to still add a check in the menu file.

If are writing a plugin that will extend the ProcessMaker Menu, then the file would be located within the folder for your plugin, with the name of menuPluginName.php.

If you are developing a plugin that adds a link to the cases menu in the home tab, then the file would be located inside your plugin’s folder, with the name of menuCasesPluginName.php.

You can copy and paste the following code, of course you will need to change the name of the Permission:

global $G_TMP_MENU;
global $RBAC;
if ($RBAC->userCanAccess('MY_PERMISSION_NAME') == 1) {
$G_TMP_MENU->AddIdRawOption(‘PLUGIN_ID’, 'url', ‘Text for the menu’);
}

 

If you have added the above code, your plugin will now correctly display only for the users that have your plugins Permission assigned to their role.

 

Edit: Thank you Alejandro Romero for pointing out the missing line of code.

About This Author

Customer & Partner Support Manager for Colosa Inc. and ProcessMaker.

  • Alejandro Romero

    Hi, I try to do it, but it doesn’t work. When I login into processmaker my screen turns blank, like it happened an error.

    My code is:

    userCanAccess(‘PM_CONTROLADOR’) == 1){

    $G_TMP_MENU->AddIdRawOption(“ID_CONTROLADOR_MNU_01”, “controlador/controladorApplication”, “controlador – application1”);

    }

    ?>

    • Alejandro Romero

      I found the error, you forgot declare $rbac varible at the begin of the code

      • Thank you for the correction. Good eye!

        I have fixed the post.

  • Rui Cordeiro

    hi,

    I’m trying to implement this but I always get a blank page.

    I believe your code is for a new tab but my plugin is a new option on the cases tree on the left.

    I believe the code should be on the setup portion:

    public function setup()
    {
    $this->registerMenu(“cases”, “menuCasesTest.php”);
    }

    This is loaded everytime someone clicks a link, the control should be done here, right?

    *** Solved it ***

    I used only the code:

    global $RBAC;
    if ($RBAC->userCanAccess(‘MY_PERMISSION_NAME’) == 1) {

    }

    This was included inside the menu declaration php file, inside the plugin folder.