User permissions

Tests added, sdUserPermissions directive tidied.