Skip to content

Commit 7971f36

Browse files
authored
Add check for PluginControllerAttribute and compare area name (#11911)
* Add check for PluginControllerAttribute and compare area name * Added null check
1 parent c73d0bf commit 7971f36

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

src/Umbraco.Infrastructure/Runtime/RuntimeState.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,28 @@ private RuntimeState()
4444
{
4545
}
4646

47+
public RuntimeState(
48+
IOptions<GlobalSettings> globalSettings,
49+
IOptions<UnattendedSettings> unattendedSettings,
50+
IUmbracoVersion umbracoVersion,
51+
IUmbracoDatabaseFactory databaseFactory,
52+
ILogger<RuntimeState> logger,
53+
PendingPackageMigrations packageMigrationState,
54+
IConflictingRouteService conflictingRouteService)
55+
{
56+
_globalSettings = globalSettings;
57+
_unattendedSettings = unattendedSettings;
58+
_umbracoVersion = umbracoVersion;
59+
_databaseFactory = databaseFactory;
60+
_logger = logger;
61+
_packageMigrationState = packageMigrationState;
62+
_conflictingRouteService = conflictingRouteService;
63+
}
64+
4765
/// <summary>
4866
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
4967
/// </summary>
68+
[Obsolete("use ctor with all params")]
5069
public RuntimeState(
5170
IOptions<GlobalSettings> globalSettings,
5271
IOptions<UnattendedSettings> unattendedSettings,
@@ -65,24 +84,6 @@ public RuntimeState(
6584
{
6685
}
6786

68-
public RuntimeState(
69-
IOptions<GlobalSettings> globalSettings,
70-
IOptions<UnattendedSettings> unattendedSettings,
71-
IUmbracoVersion umbracoVersion,
72-
IUmbracoDatabaseFactory databaseFactory,
73-
ILogger<RuntimeState> logger,
74-
PendingPackageMigrations packageMigrationState,
75-
IConflictingRouteService conflictingRouteService)
76-
{
77-
_globalSettings = globalSettings;
78-
_unattendedSettings = unattendedSettings;
79-
_umbracoVersion = umbracoVersion;
80-
_databaseFactory = databaseFactory;
81-
_logger = logger;
82-
_packageMigrationState = packageMigrationState;
83-
_conflictingRouteService = conflictingRouteService;
84-
}
85-
8687
/// <inheritdoc />
8788
public Version Version => _umbracoVersion.Version;
8889

src/Umbraco.Web.BackOffice/Services/ConflictingRouteService.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Linq;
3+
using System.Reflection;
34
using Umbraco.Cms.Core.Composing;
45
using Umbraco.Cms.Core.Services;
6+
using Umbraco.Cms.Web.Common.Attributes;
57
using Umbraco.Cms.Web.Common.Controllers;
68

79
namespace Umbraco.Cms.Web.BackOffice.Services
@@ -21,10 +23,20 @@ public bool HasConflictingRoutes(out string controllerName)
2123
var controllers = _typeLoader.GetTypes<UmbracoApiControllerBase>().ToList();
2224
foreach (Type controller in controllers)
2325
{
24-
if (controllers.Count(x => x.Name == controller.Name) > 1)
26+
var potentialConflicting = controllers.Where(x => x.Name == controller.Name).ToArray();
27+
if (potentialConflicting.Length > 1)
2528
{
26-
controllerName = controller.Name;
27-
return true;
29+
//If we have any with same controller name and located in the same area, then it is a confict.
30+
var conflicting = potentialConflicting
31+
.Select(x => x.GetCustomAttribute<PluginControllerAttribute>())
32+
.GroupBy(x => x?.AreaName)
33+
.Any(x => x?.Count() > 1);
34+
35+
if (conflicting)
36+
{
37+
controllerName = controller.Name;
38+
return true;
39+
}
2840
}
2941
}
3042

0 commit comments

Comments
 (0)