Fix permissions logic