Fatal error “Call to a member function authorise() on null” in Lends view

Started by Leauranger, Yesterday at 16:20:36

Previous topic - Next topic

Leauranger

Hello!
First thank you for this component.

Fatal error "Call to a member function authorise() on null" in Lends view for non-Super Users

Environment
  • Joomla 6.2.0
  • A
lexandria Book Library (com_abook) 4.0.18

Description
In the administrator, opening the Lends manager (view=lends) with a user who is not a Super User, but whose group has access to the component's administration, causes a fatal error:

0 Call to a member function authorise() on null
administrator/components/com_abook/views/lends/view.html.php:74
AbookViewLends->addToolbar()

The page works correctly for Super Users.

Cause
In AbookViewLends::addToolbar(), the variable $user is used but never defined:

php
if ($canDo->get('core.admin') || $user->authorise('core.options', 'com_abook')){

For a Super User, core.admin is true, so the second condition is never evaluated. For any other user, $user->authorise() is called on null, which triggers the error.

Fix
Add the Factory import and define $user at the start of addToolbar():

diff
use Joomla\CMS\Helper\ContentHelper;
+use Joomla\CMS\Factory;
diff
protected function addToolbar()
{
$canDo  = ContentHelper::getActions('com_abook');
$toolbar = Toolbar::getInstance();
+ $user    = Factory::getApplication()->getIdentity();

Tested: the Lends manager now displays correctly for non-Super Users, with toolbar buttons shown according to their permissions.

It may be worth checking other views/*/view.html.php files for the same pattern.

Regards

federica

Hi Leauranger,
I fixed the bub, please install the new version.
Thanks
Al mondo ci sono 10 tipi di persone, quelli che hanno capito il codice binario e quelli che non l'hanno capito.
Informatizzati [url="https://informatizzati.org"]https://informatizzati.org[/url]
Stacca la spina [url="https://disconnessi.org"]https://disconnessi.org[/url]

Leauranger

Thanks a lot for the quick fix! I installed 4.0.19 and the Lends view now works fine for non-Super Users. :)

federica

Al mondo ci sono 10 tipi di persone, quelli che hanno capito il codice binario e quelli che non l'hanno capito.
Informatizzati [url="https://informatizzati.org"]https://informatizzati.org[/url]
Stacca la spina [url="https://disconnessi.org"]https://disconnessi.org[/url]