utlib / IiifItems

Embed Mirador in Omeka Classic 2.3+ for building rich IIIF-compliant exhibits
Apache License 2.0
17 stars 9 forks source link

Code more defensively when accessing current_user() #29

Closed fozboz closed 4 months ago

fozboz commented 5 months ago

The current_user() method returns null if the user is anonymous. With the previous implementation, one would see frequent warnings such as this in PHP logs.

PHP Warning: Attempt to read property "role" on null

This update adds checks to ensure that the current user is not null before attempting to access its properties.

I didn't update the instances of this method's use in views/admin/mirador/annotator.php because I figured it should be impossible to reach that code if you are not logged in.

My editor also removed all trailing whitespace.

dicksonlaw583 commented 4 months ago

Thank you for the PR. Going forward, instead of fetching roles from current_user(), I would prefer to migrate the permissions to an ACL-based setup. Example from a recent retrofit on Job Diagnostics: