Moved code out of block, added unit test. Still uses db.invalUserOrRoleChannels and db.invaluserRoles to invalidate the user docs and save to db. When the username matches the current db.user name then the db.user is reloaded from the db, where the channels list is reconstructed.