Add check for PluginControllerAttribute and compare area name (#11911)

* Add check for PluginControllerAttribute and compare area name

* Added null check
This commit is contained in:
Bjarke Berg
2022-01-27 10:32:56 +01:00
committed by GitHub
parent c73d0bf6a6
commit 7971f36b78
2 changed files with 37 additions and 24 deletions

View File

@@ -44,27 +44,6 @@ namespace Umbraco.Cms.Infrastructure.Runtime
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
/// </summary>
public RuntimeState(
IOptions<GlobalSettings> globalSettings,
IOptions<UnattendedSettings> unattendedSettings,
IUmbracoVersion umbracoVersion,
IUmbracoDatabaseFactory databaseFactory,
ILogger<RuntimeState> logger,
PendingPackageMigrations packageMigrationState)
: this(
globalSettings,
unattendedSettings,
umbracoVersion,
databaseFactory,
logger,
packageMigrationState,
StaticServiceProvider.Instance.GetRequiredService<IConflictingRouteService>())
{
}
public RuntimeState(
IOptions<GlobalSettings> globalSettings,
IOptions<UnattendedSettings> unattendedSettings,
@@ -83,6 +62,28 @@ namespace Umbraco.Cms.Infrastructure.Runtime
_conflictingRouteService = conflictingRouteService;
}
/// <summary>
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
/// </summary>
[Obsolete("use ctor with all params")]
public RuntimeState(
IOptions<GlobalSettings> globalSettings,
IOptions<UnattendedSettings> unattendedSettings,
IUmbracoVersion umbracoVersion,
IUmbracoDatabaseFactory databaseFactory,
ILogger<RuntimeState> logger,
PendingPackageMigrations packageMigrationState)
: this(
globalSettings,
unattendedSettings,
umbracoVersion,
databaseFactory,
logger,
packageMigrationState,
StaticServiceProvider.Instance.GetRequiredService<IConflictingRouteService>())
{
}
/// <inheritdoc />
public Version Version => _umbracoVersion.Version;

View File

@@ -1,7 +1,9 @@
using System;
using System.Linq;
using System.Reflection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Controllers;
namespace Umbraco.Cms.Web.BackOffice.Services
@@ -21,10 +23,20 @@ namespace Umbraco.Cms.Web.BackOffice.Services
var controllers = _typeLoader.GetTypes<UmbracoApiControllerBase>().ToList();
foreach (Type controller in controllers)
{
if (controllers.Count(x => x.Name == controller.Name) > 1)
var potentialConflicting = controllers.Where(x => x.Name == controller.Name).ToArray();
if (potentialConflicting.Length > 1)
{
controllerName = controller.Name;
return true;
//If we have any with same controller name and located in the same area, then it is a confict.
var conflicting = potentialConflicting
.Select(x => x.GetCustomAttribute<PluginControllerAttribute>())
.GroupBy(x => x?.AreaName)
.Any(x => x?.Count() > 1);
if (conflicting)
{
controllerName = controller.Name;
return true;
}
}
}