AB4385 - Moved Content Apps to Infrastructure - Introduced ICurrentUserAccessor in Abstractions
This commit is contained in:
@@ -4,6 +4,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models.ContentEditing;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Web.ContentApps
|
||||
@@ -11,17 +12,18 @@ namespace Umbraco.Web.ContentApps
|
||||
public class ContentAppFactoryCollection : BuilderCollectionBase<IContentAppFactory>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor;
|
||||
|
||||
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger)
|
||||
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger, ICurrentUserAccessor currentUserAccessor)
|
||||
: base(items)
|
||||
{
|
||||
_logger = logger;
|
||||
_currentUserAccessor = currentUserAccessor;
|
||||
}
|
||||
|
||||
private IEnumerable<IReadOnlyUserGroup> GetCurrentUserGroups()
|
||||
{
|
||||
var umbracoContext = Composing.Current.UmbracoContext;
|
||||
var currentUser = umbracoContext?.Security?.CurrentUser;
|
||||
var currentUser = _currentUserAccessor.TryGetCurrentUser();
|
||||
return currentUser == null
|
||||
? Enumerable.Empty<IReadOnlyUserGroup>()
|
||||
: currentUser.Groups;
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Models.ContentEditing;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
|
||||
namespace Umbraco.Web.ContentApps
|
||||
{
|
||||
@@ -18,8 +19,8 @@ namespace Umbraco.Web.ContentApps
|
||||
{
|
||||
// get the logger just-in-time - see note below for manifest parser
|
||||
var logger = factory.GetInstance<ILogger>();
|
||||
|
||||
return new ContentAppFactoryCollection(CreateItems(factory), logger);
|
||||
var currentUserAccessor = factory.GetInstance<ICurrentUserAccessor>();
|
||||
return new ContentAppFactoryCollection(CreateItems(factory), logger, currentUserAccessor);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IContentAppFactory> CreateItems(IFactory factory)
|
||||
@@ -28,8 +29,8 @@ namespace Umbraco.Web.ContentApps
|
||||
// simply getting the builder in order to configure the collection, would require
|
||||
// its dependencies too, and that can create cycles or other oddities
|
||||
var manifestParser = factory.GetInstance<IManifestParser>();
|
||||
|
||||
return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x, Current.IOHelper)));
|
||||
var ioHelper = factory.GetInstance<IIOHelper>();
|
||||
return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x, ioHelper)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Core.Models.Identity
|
||||
{
|
||||
public interface ICurrentUserAccessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current user or null if no user is currently authenticated.
|
||||
/// </summary>
|
||||
/// <returns>The current user or null</returns>
|
||||
IUser TryGetCurrentUser();
|
||||
}
|
||||
}
|
||||
@@ -51,10 +51,12 @@ using FileSystems = Umbraco.Core.IO.FileSystems;
|
||||
using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Testing
|
||||
{
|
||||
@@ -195,6 +197,7 @@ namespace Umbraco.Tests.Testing
|
||||
Composition.RegisterUnique(backOfficeInfo);
|
||||
Composition.RegisterUnique(ipResolver);
|
||||
Composition.RegisterUnique<IPasswordHasher, AspNetPasswordHasher>();
|
||||
Composition.RegisterUnique<ICurrentUserAccessor, CurrentUserAccessor>();
|
||||
Composition.RegisterUnique(TestHelper.ShortStringHelper);
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Migrations.PostMigrations;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Core.Runtime;
|
||||
@@ -59,6 +60,7 @@ namespace Umbraco.Web.Runtime
|
||||
composition.Register<IHostingEnvironment, AspNetHostingEnvironment>();
|
||||
composition.Register<IBackOfficeInfo, AspNetBackOfficeInfo>();
|
||||
composition.Register<IPasswordHasher, AspNetPasswordHasher>();
|
||||
composition.Register<ICurrentUserAccessor, CurrentUserAccessor>();
|
||||
|
||||
composition.RegisterUnique<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors
|
||||
|
||||
|
||||
21
src/Umbraco.Web/Security/CurrentUserAccessor.cs
Normal file
21
src/Umbraco.Web/Security/CurrentUserAccessor.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Web.Security
|
||||
{
|
||||
internal class CurrentUserAccessor : ICurrentUserAccessor
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
|
||||
public CurrentUserAccessor(IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IUser TryGetCurrentUser()
|
||||
{
|
||||
return _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,11 +145,6 @@
|
||||
<Compile Include="Composing\CompositionExtensions\Installer.cs" />
|
||||
<Compile Include="Composing\LightInject\LightInjectContainer.cs" />
|
||||
<Compile Include="Compose\BackOfficeUserAuditEventsComponent.cs" />
|
||||
<Compile Include="ContentApps\ContentAppFactoryCollection.cs" />
|
||||
<Compile Include="ContentApps\ContentAppFactoryCollectionBuilder.cs" />
|
||||
<Compile Include="ContentApps\ContentEditorContentAppFactory.cs" />
|
||||
<Compile Include="ContentApps\ContentInfoContentAppFactory.cs" />
|
||||
<Compile Include="ContentApps\ListViewContentAppFactory.cs" />
|
||||
<Compile Include="Dashboards\ContentDashboard.cs" />
|
||||
<Compile Include="Dashboards\DashboardCollection.cs" />
|
||||
<Compile Include="Dashboards\DashboardCollectionBuilder.cs" />
|
||||
@@ -221,6 +216,7 @@
|
||||
<Compile Include="Search\ExamineFinalComponent.cs" />
|
||||
<Compile Include="Search\ExamineFinalComposer.cs" />
|
||||
<Compile Include="Search\ExamineUserComponent.cs" />
|
||||
<Compile Include="Security\CurrentUserAccessor.cs" />
|
||||
<Compile Include="Security\MembershipProviderBase.cs" />
|
||||
<Compile Include="Security\MembershipProviderExtensions.cs" />
|
||||
<Compile Include="Security\UmbracoMembershipProviderBase.cs" />
|
||||
@@ -747,7 +743,6 @@
|
||||
<Compile Include="Install\Controllers\InstallController.cs" />
|
||||
<Compile Include="Install\InstallAuthorizeAttribute.cs" />
|
||||
<Compile Include="Models\ContentEditing\ListViewAwareContentItemDisplayBase.cs" />
|
||||
<Compile Include="Models\ContentEditing\PropertyTypeValidation.cs" />
|
||||
<Compile Include="Models\ImageCropRatioMode.cs" />
|
||||
<Compile Include="Models\IContentModel.cs" />
|
||||
<Compile Include="Models\PartialViewMacroModelExtensions.cs" />
|
||||
@@ -963,8 +958,6 @@
|
||||
<Compile Include="Models\ContentEditing\ContentItemDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentPropertyCollectionDto.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentItemSave.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentPropertyBasic.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentPropertyDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentPropertyDto.cs" />
|
||||
<Compile Include="HttpRequestExtensions.cs" />
|
||||
<Compile Include="HttpUrlHelperExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user