Removes ICurrentUserAccessor since we don't need it, fixes editorconfig (for now)

This commit is contained in:
Shannon
2020-02-19 15:38:22 +11:00
parent 5a61b27366
commit 5cb5585574
12 changed files with 19 additions and 63 deletions

View File

@@ -25,7 +25,7 @@ dotnet_naming_rule.private_members_with_underscore.severity = suggestion
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.required_modifiers = abstract,async,readonly,static # all except const
# dotnet_naming_symbols.private_fields.required_modifiers = abstract,async,readonly,static # all except const
dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _

View File

@@ -4,7 +4,6 @@ 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
@@ -12,18 +11,18 @@ namespace Umbraco.Web.ContentApps
public class ContentAppFactoryCollection : BuilderCollectionBase<IContentAppFactory>
{
private readonly ILogger _logger;
private readonly ICurrentUserAccessor _currentUserAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger, ICurrentUserAccessor currentUserAccessor)
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor)
: base(items)
{
_logger = logger;
_currentUserAccessor = currentUserAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
}
private IEnumerable<IReadOnlyUserGroup> GetCurrentUserGroups()
{
var currentUser = _currentUserAccessor.TryGetCurrentUser();
var currentUser = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
return currentUser == null
? Enumerable.Empty<IReadOnlyUserGroup>()
: currentUser.Groups;

View File

@@ -19,8 +19,8 @@ namespace Umbraco.Web.ContentApps
{
// get the logger just-in-time - see note below for manifest parser
var logger = factory.GetInstance<ILogger>();
var currentUserAccessor = factory.GetInstance<ICurrentUserAccessor>();
return new ContentAppFactoryCollection(CreateItems(factory), logger, currentUserAccessor);
var umbracoContextAccessor = factory.GetInstance<IUmbracoContextAccessor>();
return new ContentAppFactoryCollection(CreateItems(factory), logger, umbracoContextAccessor);
}
protected override IEnumerable<IContentAppFactory> CreateItems(IFactory factory)

View File

@@ -1,13 +0,0 @@
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();
}
}

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.Models;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Examine
@@ -17,19 +18,19 @@ namespace Umbraco.Examine
{
private readonly IExamineManager _examineManager;
private readonly ILocalizationService _languageService;
private readonly ICurrentUserAccessor _currentUserAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IEntityService _entityService;
private readonly IUmbracoTreeSearcherFields _treeSearcherFields;
public BackOfficeExamineSearcher(IExamineManager examineManager,
ILocalizationService languageService,
ICurrentUserAccessor currentUserAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IEntityService entityService,
IUmbracoTreeSearcherFields treeSearcherFields)
{
_examineManager = examineManager;
_languageService = languageService;
_currentUserAccessor = currentUserAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
_entityService = entityService;
_treeSearcherFields = treeSearcherFields;
}
@@ -48,7 +49,7 @@ namespace Umbraco.Examine
query = "\"" + g.ToString() + "\"";
}
var currentUser = _currentUserAccessor.TryGetCurrentUser();
var currentUser = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
switch (entityType)
{

View File

@@ -148,13 +148,12 @@ namespace Umbraco.Web.Compose
/// </summary>
public sealed class Notifier
{
private readonly ICurrentUserAccessor _currentUserAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IRuntimeState _runtimeState;
private readonly INotificationService _notificationService;
private readonly IUserService _userService;
private readonly ILocalizedTextService _textService;
private readonly IGlobalSettings _globalSettings;
private readonly IContentSection _contentConfig;
private readonly ILogger _logger;
/// <summary>
@@ -167,21 +166,20 @@ namespace Umbraco.Web.Compose
/// <param name="globalSettings"></param>
/// <param name="contentConfig"></param>
/// <param name="logger"></param>
public Notifier(ICurrentUserAccessor currentUserAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, IContentSection contentConfig, ILogger logger)
public Notifier(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, ILogger logger)
{
_currentUserAccessor = currentUserAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
_runtimeState = runtimeState;
_notificationService = notificationService;
_userService = userService;
_textService = textService;
_globalSettings = globalSettings;
_contentConfig = contentConfig;
_logger = logger;
}
public void Notify(IAction action, params IContent[] entities)
{
var user = _currentUserAccessor.TryGetCurrentUser();
var user = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
//if there is no current user, then use the admin
if (user == null)

View File

@@ -199,7 +199,6 @@ namespace Umbraco.Tests.Testing
Composition.RegisterUnique(backOfficeInfo);
Composition.RegisterUnique(ipResolver);
Composition.RegisterUnique<IPasswordHasher, AspNetPasswordHasher>();
Composition.RegisterUnique<ICurrentUserAccessor, CurrentUserAccessor>();
Composition.RegisterUnique(TestHelper.ShortStringHelper);

View File

@@ -27,7 +27,6 @@ namespace Umbraco.Web.Editors
private readonly TourFilterCollection _filters;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
private readonly IIOHelper _ioHelper;
private readonly ICurrentUserAccessor _currentUserAccessor;
public TourController(
IGlobalSettings globalSettings,
@@ -43,14 +42,12 @@ namespace Umbraco.Web.Editors
TourFilterCollection filters,
IUmbracoSettingsSection umbracoSettingsSection,
IIOHelper ioHelper,
ICurrentUserAccessor currentUserAccessor,
IPublishedUrlProvider publishedUrlProvider)
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider)
{
_filters = filters;
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
_ioHelper = ioHelper;
_currentUserAccessor = currentUserAccessor;
}
public IEnumerable<BackOfficeTourFile> GetTours()
@@ -60,7 +57,7 @@ namespace Umbraco.Web.Editors
if (_umbracoSettingsSection.BackOffice.Tours.EnableTours == false)
return result;
var user = _currentUserAccessor.TryGetCurrentUser();
var user = UmbracoContext.Security.CurrentUser;
if (user == null)
return result;

View File

@@ -25,10 +25,9 @@ namespace Umbraco.Web.Models.Mapping
private readonly ContentAppFactoryCollection _contentAppDefinitions;
private readonly ILocalizedTextService _localizedTextService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ICurrentUserAccessor _currentUserAccessor;
public CommonMapper(IUserService userService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor,
ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService, IHttpContextAccessor httpContextAccessor, ICurrentUserAccessor currentUserAccessor)
ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService, IHttpContextAccessor httpContextAccessor)
{
_userService = userService;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
@@ -36,7 +35,6 @@ namespace Umbraco.Web.Models.Mapping
_contentAppDefinitions = contentAppDefinitions;
_localizedTextService = localizedTextService;
_httpContextAccessor = httpContextAccessor;
_currentUserAccessor = currentUserAccessor;
}
public UserProfile GetOwner(IContentBase source, MapperContext context)
@@ -54,7 +52,7 @@ namespace Umbraco.Web.Models.Mapping
public ContentTypeBasic GetContentType(IContentBase source, MapperContext context)
{
var user = _currentUserAccessor.TryGetCurrentUser();
var user = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
if (user?.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings)) ?? false)
{
var contentType = _contentTypeBaseServiceProvider.GetContentTypeOf(source);

View File

@@ -68,7 +68,6 @@ namespace Umbraco.Web.Runtime
composition.Register<IHostingEnvironment, AspNetHostingEnvironment>();
composition.Register<IBackOfficeInfo, AspNetBackOfficeInfo>();
composition.Register<IPasswordHasher, AspNetPasswordHasher>();
composition.Register<ICurrentUserAccessor, CurrentUserAccessor>();
composition.Register<IFilePermissionHelper, FilePermissionHelper>(Lifetime.Singleton);
composition.RegisterUnique<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors

View File

@@ -1,21 +0,0 @@
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;
}
}
}

View File

@@ -216,7 +216,6 @@
<Compile Include="Search\ExamineFinalComponent.cs" />
<Compile Include="Search\ExamineFinalComposer.cs" />
<Compile Include="Search\ExamineUserComponent.cs" />
<Compile Include="Security\CurrentUserAccessor.cs" />
<Compile Include="Security\BackOfficeUserStore.cs" />
<Compile Include="Security\BackOfficeUserValidator.cs" />
<Compile Include="Security\ConfiguredPasswordValidator.cs" />