Handling EntityNotFoundException / Public+Private Mix

Technically, a Site can be public with a private Item Set attached to it. However, such a situation will result in a Site being added to the Site Listing Block including for a non-authenticated visitor and my code will fail in trying to retrieve a thumbnail for the Site’s attached Item Set. The fail is throwing an EntityNotFoundException.

I can try ... catch the exception, but is there an Omeka-ier way to do it? Is there a way to test isPublic() when the site visitor is not authenticated?

It feels a bit like this is a general PHP question, but there’s also an Omeka S specificity to it.

Catching the exception is really the “Omeka-y” answer in this kind of situation.

The filtering for visibility happens at a very low-level layer and you can’t really work around it: so to your code when executing as a non-privileged user, the situation of requesting a private resource is indistinguishable from the resource not existing.

1 Like

In poking around some more, I found I can execute userIsAllowed("browse") and get back what seems to be a meaningful and accurate result. That is, I can use the result to proceed appropriately for the visitor’s authentication status.

Is there a way this approach will bite me later or is otherwise Not Great?

(I don’t have any real problem with doing it try...catch style, just checking on this way as an alternative for me to think about.)

You can use userIsAllowed, sure… though what are you checking for the browse ? Anonymous users generally have the browse permission… you’re probably basically checking if the user is an admin (who has all or substantially all permissions allowed). I don’t know your use case, so it’s possible that’s appropriate.

Visibility for the current user is slightly more complicated than just their role (or lack thereof): it can be based on ownership of the resource also (some users can only see their own private items but no one else’s). Again, whether these kinds of details matter probably depends on what you’re trying to do.

Exactly the kind of cautions I was wondering if I needed to know! I’ll stick with try...catch.