Merge remote-tracking branch 'origin/v10/dev' into v11/dev

# Conflicts:
#	src/Umbraco.Core/Constants-Telemetry.cs
#	tests/Umbraco.Tests.Integration/Umbraco.Core/Telemetry/TelemetryServiceTests.cs
This commit is contained in:
Bjarke Berg
2023-05-31 08:47:01 +02:00
8 changed files with 69 additions and 15 deletions

View File

@@ -29,5 +29,6 @@ public static partial class Constants
public static string DatabaseProvider = "DatabaseProvider";
public static string CurrentServerRole = "CurrentServerRole";
public static string RuntimeMode = "RuntimeMode";
public static string BackofficeExternalLoginProviderCount = "BackofficeExternalLoginProviderCount";
}
}

View File

@@ -3010,7 +3010,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
We will send:
<ul>
<li>Anonymized site ID, Umbraco version, and packages installed.</li>
<li>Number of: Root nodes, Content nodes, Macros, Media, Document Types, Templates, Languages, Domains, User Group, Users, Members, and Property Editors in use.</li>
<li>Number of: Root nodes, Content nodes, Macros, Media, Document Types, Templates, Languages, Domains, User Group, Users, Members, Backoffice external login providers, and Property Editors in use.</li>
<li>System information: Webserver, server OS, server framework, server OS language, and database provider.</li>
<li>Configuration settings: Modelsbuilder mode, if custom Umbraco path exists, ASP environment, and if you are in debug mode.</li>
</ul>

View File

@@ -2,7 +2,7 @@ using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Infrastructure.Telemetry.Interfaces;
internal interface IDetailedTelemetryProvider
public interface IDetailedTelemetryProvider
{
IEnumerable<UsageInformation> GetInformation();
}

View File

@@ -26,6 +26,19 @@ public class TinyMceController : UmbracoAuthorizedApiController
private readonly IIOHelper _ioHelper;
private readonly IShortStringHelper _shortStringHelper;
private readonly Dictionary<string, string> _fileContentTypeMappings =
new()
{
{ "image/png", "png" },
{ "image/jpeg", "jpg" },
{ "image/gif", "gif" },
{ "image/bmp", "bmp" },
{ "image/x-icon", "ico" },
{ "image/svg+xml", "svg" },
{ "image/tiff", "tiff" },
{ "image/webp", "webp" },
};
public TinyMceController(
IHostingEnvironment hostingEnvironment,
IShortStringHelper shortStringHelper,
@@ -43,16 +56,6 @@ public class TinyMceController : UmbracoAuthorizedApiController
[HttpPost]
public async Task<IActionResult> UploadImage(List<IFormFile> file)
{
// Create an unique folder path to help with concurrent users to avoid filename clash
var imageTempPath =
_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid());
// Ensure image temp path exists
if (Directory.Exists(imageTempPath) == false)
{
Directory.CreateDirectory(imageTempPath);
}
// Must have a file
if (file.Count == 0)
{
@@ -65,13 +68,36 @@ public class TinyMceController : UmbracoAuthorizedApiController
return new UmbracoProblemResult("Only one file can be uploaded at a time", HttpStatusCode.BadRequest);
}
// Create an unique folder path to help with concurrent users to avoid filename clash
var imageTempPath =
_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid());
// Ensure image temp path exists
if (Directory.Exists(imageTempPath) == false)
{
Directory.CreateDirectory(imageTempPath);
}
IFormFile formFile = file.First();
// Really we should only have one file per request to this endpoint
// var file = result.FileData[0];
var fileName = formFile.FileName.Trim(new[] { '\"' }).TrimEnd();
var fileName = formFile.FileName.Trim(new[] {'\"'}).TrimEnd();
var safeFileName = fileName.ToSafeFileName(_shortStringHelper);
var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLowerInvariant();
string ext;
var fileExtensionIndex = safeFileName.LastIndexOf('.');
if (fileExtensionIndex is not -1)
{
ext = safeFileName.Substring(fileExtensionIndex + 1).ToLowerInvariant();
}
else
{
_fileContentTypeMappings.TryGetValue(formFile.ContentType, out var fileExtension);
ext = fileExtension ?? string.Empty;
// safeFileName will not have a file extension, so we need to add it back
safeFileName += $".{ext}";
}
if (_contentSettings.IsFileAllowedForUpload(ext) == false ||
_imageUrlGenerator.IsSupportedImageFormat(ext) == false)

View File

@@ -11,7 +11,9 @@ using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Security;
using Umbraco.Cms.Infrastructure.Telemetry.Interfaces;
using Umbraco.Cms.Web.BackOffice.Security;
using Umbraco.Cms.Web.BackOffice.Telemetry;
using Umbraco.Cms.Web.Common.AspNetCore;
using Umbraco.Cms.Web.Common.Security;
@@ -65,6 +67,7 @@ public static partial class UmbracoBuilderExtensions
services.TryAddScoped<IIpResolver, AspNetCoreIpResolver>();
services.TryAddSingleton<IBackOfficeExternalLoginProviders, BackOfficeExternalLoginProviders>();
services.TryAddSingleton<IBackOfficeTwoFactorOptions, DefaultBackOfficeTwoFactorOptions>();
services.AddTransient<IDetailedTelemetryProvider, ExternalLoginTelemetryProvider>();
return new BackOfficeIdentityBuilder(services);
}

View File

@@ -0,0 +1,22 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.Telemetry.Interfaces;
using Umbraco.Cms.Web.BackOffice.Security;
namespace Umbraco.Cms.Web.BackOffice.Telemetry;
public class ExternalLoginTelemetryProvider : IDetailedTelemetryProvider
{
private readonly IBackOfficeExternalLoginProviders _externalLoginProviders;
public ExternalLoginTelemetryProvider(IBackOfficeExternalLoginProviders externalLoginProviders)
{
_externalLoginProviders = externalLoginProviders;
}
public IEnumerable<UsageInformation> GetInformation()
{
IEnumerable<BackOfficeExternaLoginProviderScheme> providers = _externalLoginProviders.GetBackOfficeProvidersAsync().GetAwaiter().GetResult();
yield return new UsageInformation(Constants.Telemetry.BackofficeExternalLoginProviderCount, providers.Count());
}
}

View File

@@ -50,7 +50,8 @@ public class TelemetryServiceTests : UmbracoIntegrationTest
Constants.Telemetry.IsDebug,
Constants.Telemetry.DatabaseProvider,
Constants.Telemetry.CurrentServerRole,
Constants.Telemetry.RuntimeMode,
Constants.Telemetry.BackofficeExternalLoginProviderCount,
Constants.Telemetry.RuntimeMode
};
MetricsConsentService.SetConsentLevel(TelemetryLevel.Detailed);

View File

@@ -19,6 +19,7 @@ using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Infrastructure.Examine;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Common.DependencyInjection;
using Directory = Lucene.Net.Store.Directory;
using StaticServiceProvider = Umbraco.Cms.Core.DependencyInjection.StaticServiceProvider;