diff --git a/.editorconfig b/.editorconfig index 5d270b1db0..29ad74b4d6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 = _ diff --git a/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollection.cs b/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollection.cs index f8f57ce4fd..4e85e51af3 100644 --- a/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollection.cs +++ b/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollection.cs @@ -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 { private readonly ILogger _logger; - private readonly ICurrentUserAccessor _currentUserAccessor; + private readonly IUmbracoContextAccessor _umbracoContextAccessor; - public ContentAppFactoryCollection(IEnumerable items, ILogger logger, ICurrentUserAccessor currentUserAccessor) + public ContentAppFactoryCollection(IEnumerable items, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor) : base(items) { _logger = logger; - _currentUserAccessor = currentUserAccessor; + _umbracoContextAccessor = umbracoContextAccessor; } private IEnumerable GetCurrentUserGroups() { - var currentUser = _currentUserAccessor.TryGetCurrentUser(); + var currentUser = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser; return currentUser == null ? Enumerable.Empty() : currentUser.Groups; diff --git a/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollectionBuilder.cs b/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollectionBuilder.cs index 0e21823b90..f3d3a149d5 100644 --- a/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollectionBuilder.cs +++ b/src/Umbraco.Abstractions/ContentApps/ContentAppFactoryCollectionBuilder.cs @@ -19,8 +19,8 @@ namespace Umbraco.Web.ContentApps { // get the logger just-in-time - see note below for manifest parser var logger = factory.GetInstance(); - var currentUserAccessor = factory.GetInstance(); - return new ContentAppFactoryCollection(CreateItems(factory), logger, currentUserAccessor); + var umbracoContextAccessor = factory.GetInstance(); + return new ContentAppFactoryCollection(CreateItems(factory), logger, umbracoContextAccessor); } protected override IEnumerable CreateItems(IFactory factory) diff --git a/src/Umbraco.Abstractions/Models/Identity/ICurrentUserAccessor.cs b/src/Umbraco.Abstractions/Models/Identity/ICurrentUserAccessor.cs deleted file mode 100644 index 49b2c6d9f9..0000000000 --- a/src/Umbraco.Abstractions/Models/Identity/ICurrentUserAccessor.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Umbraco.Core.Models.Membership; - -namespace Umbraco.Core.Models.Identity -{ - public interface ICurrentUserAccessor - { - /// - /// Returns the current user or null if no user is currently authenticated. - /// - /// The current user or null - IUser TryGetCurrentUser(); - } -} diff --git a/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs b/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs index cfa9de5fa6..d73dc89948 100644 --- a/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs +++ b/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs @@ -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) { diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs index 41fc097ff3..b39e5c03e9 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs @@ -148,13 +148,12 @@ namespace Umbraco.Web.Compose /// 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; /// @@ -167,21 +166,20 @@ namespace Umbraco.Web.Compose /// /// /// - 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) diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index f10c18492a..b0cde2b905 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -199,7 +199,6 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(backOfficeInfo); Composition.RegisterUnique(ipResolver); Composition.RegisterUnique(); - Composition.RegisterUnique(); Composition.RegisterUnique(TestHelper.ShortStringHelper); diff --git a/src/Umbraco.Web/Editors/TourController.cs b/src/Umbraco.Web/Editors/TourController.cs index c5be44b809..c3b9732807 100644 --- a/src/Umbraco.Web/Editors/TourController.cs +++ b/src/Umbraco.Web/Editors/TourController.cs @@ -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 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; diff --git a/src/Umbraco.Web/Models/Mapping/CommonMapper.cs b/src/Umbraco.Web/Models/Mapping/CommonMapper.cs index f8b99a444c..748ffe07f9 100644 --- a/src/Umbraco.Web/Models/Mapping/CommonMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/CommonMapper.cs @@ -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); diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index c36e1fc597..e7ae1ad7ba 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -68,7 +68,6 @@ namespace Umbraco.Web.Runtime composition.Register(); composition.Register(); composition.Register(); - composition.Register(); composition.Register(Lifetime.Singleton); composition.RegisterUnique(); // required for hybrid accessors diff --git a/src/Umbraco.Web/Security/CurrentUserAccessor.cs b/src/Umbraco.Web/Security/CurrentUserAccessor.cs deleted file mode 100644 index 3d914be77f..0000000000 --- a/src/Umbraco.Web/Security/CurrentUserAccessor.cs +++ /dev/null @@ -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; - } - - /// - public IUser TryGetCurrentUser() - { - return _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser; - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 0b0e6b6fee..388b5b10dc 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -216,7 +216,6 @@ -