Improved handling for not_permitted.
Merge branch 'feature/not-permitted' into develop