How can I allow that a method, triggered by an anonymous user action, change folder state to private

I created a folder to store my custom dexterity and a permission to allow anonymous user create objects on this folder. It's working. But, I also would like to change the folder state to private after N objects. Unfortunately it works only with authenticated user. How can I allow this method, triggered by anonymous user, change folder state to private?
Something similar happens when I try to query catalog to get the objects of this folder. It only works with authenticated user. Is there a way to allow this method, triggered by anonymous user, query this private objects?


I think you can use plone.api.env.adopt_roles in order to acquire the manager role and then you can do what you want.

Thank you for your help. It worked.