Permissions cleanup

While trying to understand some permission related things I made these refactorings to make the code a bit more understandable. While I was at it I also enabled unit tests for dashboard-ui-core and added few basic tests for permissions.