Recursively hide tree sub categories at deeper levels and update permiss...

...ions for documents and categories
If position lines up with the position in the category array, you can do `categories.each_with_index do |root, position|` to avoid doing the manual count.  I'm actually not sure if this is the use though, because it might just be 0 all the time.