allow layer replace to respect the current permissions

fix #870