Skip to content

Commit

Permalink
v14: Remove mentions of UmbracoApiController (#15863)
Browse files Browse the repository at this point in the history
* Remove mentions of UmbracoApiController

* Remove last mentions of UmbracoApi controller
  • Loading branch information
Zeegaan authored Mar 19, 2024
1 parent 08783c6 commit 30e2dea
Show file tree
Hide file tree
Showing 17 changed files with 3 additions and 626 deletions.
35 changes: 1 addition & 34 deletions src/Umbraco.Cms.Api.Management/Routing/BackOfficeAreaRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Umbraco.Cms.Api.Management.Routing;
/// </summary>
public sealed class BackOfficeAreaRoutes : IAreaRoutes
{
private readonly UmbracoApiControllerTypeCollection _apiControllers;
private readonly GlobalSettings _globalSettings;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IRuntimeState _runtimeState;
Expand All @@ -31,13 +30,11 @@ public sealed class BackOfficeAreaRoutes : IAreaRoutes
public BackOfficeAreaRoutes(
IOptions<GlobalSettings> globalSettings,
IHostingEnvironment hostingEnvironment,
IRuntimeState runtimeState,
UmbracoApiControllerTypeCollection apiControllers)
IRuntimeState runtimeState)
{
_globalSettings = globalSettings.Value;
_hostingEnvironment = hostingEnvironment;
_runtimeState = runtimeState;
_apiControllers = apiControllers;
_umbracoPathSegment = _globalSettings.GetUmbracoMvcArea(_hostingEnvironment);
}

Expand All @@ -53,7 +50,6 @@ public void CreateRoutes(IEndpointRouteBuilder endpoints)
case RuntimeLevel.Run:

MapMinimalBackOffice(endpoints);
AutoRouteBackOfficeApiControllers(endpoints);
break;
case RuntimeLevel.BootFailed:
case RuntimeLevel.Unknown:
Expand Down Expand Up @@ -87,33 +83,4 @@ private void MapMinimalBackOffice(IEndpointRouteBuilder endpoints)
Action = nameof(BackOfficeDefaultController.Index)
});
}

/// <summary>
/// Auto-routes all back office api controllers
/// </summary>
private void AutoRouteBackOfficeApiControllers(IEndpointRouteBuilder endpoints)
{
// TODO: We could investigate dynamically routing plugin controllers so we don't have to eagerly type scan for them,
// it would probably work well, see https://www.strathweb.com/2019/08/dynamic-controller-routing-in-asp-net-core-3-0/
// will probably be what we use for front-end routing too. BTW the orig article about migrating from IRouter to endpoint
// routing for things like a CMS is here https://github.com/dotnet/aspnetcore/issues/4221

foreach (Type controller in _apiControllers)
{
PluginControllerMetadata meta = PluginController.GetMetadata(controller);

// exclude front-end api controllers
if (!meta.IsBackOffice)
{
continue;
}

endpoints.MapUmbracoApiRoute(
meta.ControllerType,
_umbracoPathSegment,
meta.AreaName,
meta.IsBackOffice,
string.Empty); // no default action (this is what we had before)
}
}
}
11 changes: 0 additions & 11 deletions src/Umbraco.Core/UmbracoApiControllerTypeCollection.cs

This file was deleted.

11 changes: 0 additions & 11 deletions src/Umbraco.Web.Common/Attributes/UmbracoApiControllerAttribute.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/Umbraco.Web.Common/Controllers/UmbracoApiController.cs

This file was deleted.

26 changes: 0 additions & 26 deletions src/Umbraco.Web.Common/Controllers/UmbracoApiControllerBase.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ public static IUmbracoBuilder AddWebComponents(this IUmbracoBuilder builder)
builder.Services.AddUnique<IUmbracoContextFactory, UmbracoContextFactory>();
builder.Services.AddUnique<IBackOfficeSecurityAccessor, BackOfficeSecurityAccessor>();

var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList();
builder.WithCollectionBuilder<UmbracoApiControllerTypeCollectionBuilder>()
.Add(umbracoApiControllerTypes);

builder.Services.AddSingleton<UmbracoRequestLoggingMiddleware>();
builder.Services.AddSingleton<PreviewAuthenticationMiddleware>();
builder.Services.AddSingleton<UmbracoRequestMiddleware>();
Expand Down
79 changes: 0 additions & 79 deletions src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,6 @@ namespace Umbraco.Extensions;

public static class LinkGeneratorExtensions
{
/// <summary>
/// Gets the Umbraco backoffice URL (if Umbraco is installed).
/// </summary>
/// <param name="linkGenerator">The link generator.</param>
/// <returns>
/// The Umbraco backoffice URL.
/// </returns>
public static string? GetUmbracoBackOfficeUrl(this LinkGenerator linkGenerator)
=> linkGenerator.GetPathByAction("Default", "BackOffice", new { area = Constants.Web.Mvc.BackOfficeArea });

/// <summary>
/// Gets the Umbraco backoffice URL (if Umbraco is installed) or application virtual path (in most cases just <c>"/"</c>).
/// </summary>
/// <param name="linkGenerator">The link generator.</param>
/// <param name="hostingEnvironment">The hosting environment.</param>
/// <returns>
/// The Umbraco backoffice URL.
/// </returns>
public static string GetUmbracoBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment)
=> GetUmbracoBackOfficeUrl(linkGenerator) ?? hostingEnvironment.ApplicationVirtualPath;

/// <summary>
/// Return the back office url if the back office is installed
/// </summary>
/// <remarks>
/// This method contained a bug that would result in always returning "/".
/// </remarks>
[Obsolete("Use the GetUmbracoBackOfficeUrl extension method instead. This method will be removed in Umbraco 13.")]
public static string? GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment)
=> "/";

/// <summary>
/// Return the Url for a Web Api service
/// </summary>
/// <typeparam name="T">The <see cref="UmbracoApiControllerBase" /></typeparam>
public static string? GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, object? id = null)
where T : UmbracoApiControllerBase => linkGenerator.GetUmbracoControllerUrl(
actionName,
typeof(T),
new Dictionary<string, object?> { ["id"] = id });

public static string? GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, IDictionary<string, object?>? values)
where T : UmbracoApiControllerBase => linkGenerator.GetUmbracoControllerUrl(actionName, typeof(T), values);

public static string? GetUmbracoApiServiceBaseUrl<T>(
this LinkGenerator linkGenerator,
Expression<Func<T, object?>> methodSelector)
where T : UmbracoApiControllerBase
{
MethodInfo? method = ExpressionHelper.GetMethodInfo(methodSelector);
if (method == null)
{
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) +
" or the result ");
}

return linkGenerator.GetUmbracoApiService<T>(method.Name)?.TrimEnd(method.Name);
}

/// <summary>
/// Return the Url for an Umbraco controller
Expand Down Expand Up @@ -159,25 +101,4 @@ public static string GetUmbracoBackOfficeUrl(this LinkGenerator linkGenerator, I

return linkGenerator.GetUmbracoControllerUrl(actionName, ControllerExtensions.GetControllerName(controllerType), area, values);
}

public static string? GetUmbracoApiService<T>(
this LinkGenerator linkGenerator,
Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
MethodInfo? method = ExpressionHelper.GetMethodInfo(methodSelector);
IDictionary<string, object?>? methodParams = ExpressionHelper.GetMethodParams(methodSelector);
if (method == null)
{
throw new MissingMethodException(
$"Could not find the method {methodSelector} on type {typeof(T)} or the result ");
}

if (methodParams?.Any() == false)
{
return linkGenerator.GetUmbracoApiService<T>(method.Name);
}

return linkGenerator.GetUmbracoApiService<T>(method.Name, methodParams);
}
}
13 changes: 0 additions & 13 deletions src/Umbraco.Web.Common/Extensions/TypeLoaderExtensions.cs

This file was deleted.

Loading

0 comments on commit 30e2dea

Please sign in to comment.