Querying nodes in a custom repo always return 0 results

Enonic version: 7.2
OS: linux/macOS

We have created an event-listener that copies certain content to a separate repo in order to perform some specialized queries on the data. Basically we are converting a list of dates in an option-set to be separate date nodes in a repository.

The problem is now I am unable to query the nodes in the custom repository. It only works if I am logged in as the user who created the nodes (su).

I figured this was a permissions issue, and assigned these permissions to my custom repo nodes, but it still failed:
[
{
‘principal’: ‘role:cms.cm.app’,
‘allow’: [
‘READ’
],
‘deny’: []
},
{
‘principal’: ‘role:system.admin’,
‘allow’: [
‘READ’,
‘CREATE’,
‘MODIFY’,
‘DELETE’,
‘PUBLISH’,
‘READ_PERMISSIONS’,
‘WRITE_PERMISSIONS’
],
‘deny’: []
},
{
‘principal’: ‘role:cms.admin’,
‘allow’: [
‘READ’,
‘CREATE’,
‘MODIFY’,
‘DELETE’,
‘PUBLISH’,
‘READ_PERMISSIONS’,
‘WRITE_PERMISSIONS’
],
‘deny’: []
},
{
‘principal’: ‘role:system.everyone’,
‘allow’: [
‘READ’
],
‘deny’: []
}
]

Do you have any idea what might be causing this? Or, any help in figuring out this issue would be a great help!

You can use run from the Context library to execute functions as another user then the logged-in user.

If you want, you can run code as the su user, with all permissions.

But be warned :skull_and_crossbones: , work with the permission system when you can, instead of going around it. It’s easy to shoot yourself in the foot with this kind of power. :gun: :wink:

Ok. I am running the event listeners through the context.run function, will try using it for the query part for now.

I’d rather have the correct permissions if possible for the query part yes.

Generally, avoid using permissions for nodes unless you actually need it. Example: if you intend to protect selected items with permissions it’s fine. Otherwise, just use an approach like setting a contextual role or user to access the data.

Otherwise hard to tell why you have problems accessing these data, could be related to query also I guess?

2 Likes

This was resolved. Turns out the problem was in the query.
Permissions was also a problem, but was resolved by setting the permissions outlined in my first post.