As far as @landreev and I know the ability to restrict (or unrestrict) files is limited to the GUI so I'm creating this issue as a feature request for the API. Personally, I would use it in integration testing (for #2466 (comment) for example) but I imagine it would be useful for third party developers as well.