Added permission checking. Added unit tests for the db_layer and permissions.