Fix permissions for multiple groups

This fixes permissions not registering if multiple groups have the same permission, and adds some documentation type specification.

Previously, if group a and group b both had the permission 'perm', then only users from group 'b' would have access to it.

This also adds debug logging of permissions