Custom Module permissions

Dolibarr version 14.03
Platform Ubuntu Server 18.04 LTS
Webserver Apache 2

I have developed a few custom modules and they do what is intended. The problem comes with the left menu search box. I haven’t made any changes to it but I get the following:

133

Notice*: Undefined property: stdClass::$supplier_invoice in /var/www/demo/htdocs/core/ajax/selectsearchbox.php on line *133

Notice*: Trying to get property ‘lire’ of non-object in /var/www/demo/htdocs/core/ajax/selectsearchbox.php on line *133

Notice*: Undefined property: stdClass::$banque in /var/www/demo/htdocs/core/ajax/selectsearchbox.php on line *143

Notice*: Trying to get property ‘lire’ of non-object in /var/www/demo/htdocs/core/ajax/selectsearchbox.php on line *143

The errors correspond to modules that a user has not been given access to. Granting access eliminates the errors but is not an ideal solution.

Any suggestions would be greatly appreciated.

You should alter your module to adopt the Dolibarr core modules permissions. What I mean:

  1. Let’s say you have a page, that shows some invoices information
  2. The user that opens the page does not have permission to read/view invoices

All of the above means, that in your module you should have:

if ($user->rights->facture->lire) { //If the user have rights to view invoices, show the code below
    //your code goes here
}

Similar should be done for the rest.