Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,15 @@ public class SearchMediaItemController : MediaItemControllerBase
private readonly IIndexedEntitySearchService _indexedEntitySearchService;
private readonly IMediaPresentationFactory _mediaPresentationFactory;
private readonly IDataTypeService _dataTypeService;
private readonly IMediaTypeService _mediaTypeService;

[ActivatorUtilitiesConstructor]
public SearchMediaItemController(
IIndexedEntitySearchService indexedEntitySearchService,
IMediaPresentationFactory mediaPresentationFactory,
IDataTypeService dataTypeService,
IMediaTypeService mediaTypeService)
IDataTypeService dataTypeService)
{
_indexedEntitySearchService = indexedEntitySearchService;
_mediaPresentationFactory = mediaPresentationFactory;
_dataTypeService = dataTypeService;
_mediaTypeService = mediaTypeService;
}

[Obsolete("Use the non-obsolete constructor instead, will be removed in Umbraco 18.")]
public SearchMediaItemController(
IIndexedEntitySearchService indexedEntitySearchService,
IMediaPresentationFactory mediaPresentationFactory,
IDataTypeService dataTypeService)
: this(
indexedEntitySearchService,
mediaPresentationFactory,
dataTypeService,
StaticServiceProvider.Instance.GetRequiredService<IMediaTypeService>())
{
}

[Obsolete("Use the non-obsolete constructor instead, will be removed in Umbraco 18.")]
Expand Down Expand Up @@ -96,13 +79,9 @@ public async Task<IActionResult> SearchFromParentWithAllowedTypes(
{
// We always want to include folders in the search results (aligns with behaviour in Umbraco 13, and allows folders
// to be selected to find the selectable items inside).
if (allowedMediaTypes is not null)
if (allowedMediaTypes is not null && allowedMediaTypes.Contains(Constants.MediaTypes.Guids.FolderGuid) is false)
{
IMediaType? folderMediaType = _mediaTypeService.Get(Constants.Conventions.MediaTypes.Folder);
if (folderMediaType is not null && allowedMediaTypes.Contains(folderMediaType.Key) is false)
{
allowedMediaTypes = [..allowedMediaTypes, folderMediaType.Key];
}
allowedMediaTypes = [.. allowedMediaTypes, Constants.MediaTypes.Guids.FolderGuid];
}

var ignoreUserStartNodes = await IgnoreUserStartNodes(dataTypeId);
Expand Down
10 changes: 10 additions & 0 deletions src/Umbraco.Core/Constants-MediaTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public static class Guids
/// </summary>
public const string File = "4c52d8ab-54e6-40cd-999c-7a5f24903e4d";

/// <summary>
/// The GUID for the Folder media type as a string.
/// </summary>
public const string Folder = "f38bd2d7-65d0-48e6-95dc-87ce06ec2d3d";

/// <summary>
/// The GUID for the Image media type as a string.
/// </summary>
Expand Down Expand Up @@ -54,6 +59,11 @@ public static class Guids
/// </summary>
public static readonly Guid FileGuid = new(File);

/// <summary>
/// The GUID for the Folder media type.
/// </summary>
public static readonly Guid FolderGuid = new(Folder);

/// <summary>
/// The GUID for the Image media type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;

Check notice on line 1 in src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Lines of Code in a Single File

The lines of code decreases from 2454 to 2453, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
using System.Globalization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -926,21 +926,20 @@
}

private void CreateNodeDataForMediaTypes()
{
var folderUniqueId = new Guid("f38bd2d7-65d0-48e6-95dc-87ce06ec2d3d");
ConditionalInsert(
Constants.Configuration.NamedOptions.InstallDefaultData.MediaTypes,
folderUniqueId.ToString(),
Constants.MediaTypes.Guids.Folder,
new NodeDto
{
NodeId = 1031,
Trashed = false,
ParentId = -1,
UserId = -1,
Level = 1,
Path = "-1,1031",
SortOrder = 2,
UniqueId = folderUniqueId,
UniqueId = Constants.MediaTypes.Guids.FolderGuid,

Check notice on line 942 in src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Large Method

CreateNodeDataForMediaTypes decreases from 137 to 136 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
Text = Constants.Conventions.MediaTypes.Folder,
NodeObjectType = Constants.ObjectTypes.MediaType,
CreateDate = DateTime.UtcNow,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Constants = Umbraco.Cms.Core.Constants;

Expand All @@ -25,7 +25,7 @@ public EnsureDefaultMediaFolderHasDefaultCollection(
protected override async Task MigrateAsync()
{
IMediaType? folderMediaType = _mediaTypeService
.Get(Guid.Parse("f38bd2d7-65d0-48e6-95dc-87ce06ec2d3d")); // Folder media type default key.
.Get(Constants.MediaTypes.Guids.FolderGuid);

if (folderMediaType is null || folderMediaType.ListView is not null)
{
Expand Down
Loading