From d52c084e3ba93db117aacdc7d20ab1e148a3aabf Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 1 Feb 2021 11:26:17 +0100 Subject: [PATCH] Minor style changes --- .../Controllers/DictionaryController.cs | 2 +- ...erSwapControllerActionSelectorAttribute.cs | 18 +-- .../CheckIfUserTicketDataIsStaleAttribute.cs | 106 +++++++++--------- .../Extensions/HttpRequestExtensions.cs | 1 + 4 files changed, 64 insertions(+), 63 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs index 519dcc6c6a..bf5c487a92 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs @@ -141,7 +141,7 @@ namespace Umbraco.Web.BackOffice.Controllers /// /// The . Returns a not found response when dictionary item does not exist /// - public ActionResult GetById(int id) + public ActionResult GetById(int id) { var dictionary = _localizationService.GetDictionaryItemById(id); if (dictionary == null) diff --git a/src/Umbraco.Web.BackOffice/Controllers/ParameterSwapControllerActionSelectorAttribute.cs b/src/Umbraco.Web.BackOffice/Controllers/ParameterSwapControllerActionSelectorAttribute.cs index 5e423af270..1337180e83 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ParameterSwapControllerActionSelectorAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ParameterSwapControllerActionSelectorAttribute.cs @@ -50,7 +50,7 @@ namespace Umbraco.Web.BackOffice.Controllers return candidate; } - //if it's a post we can try to read from the body and bind from the json value + // if it's a post we can try to read from the body and bind from the json value if (context.RouteContext.HttpContext.Request.Method == HttpMethod.Post.ToString()) { // We need to use the asynchronous method here if synchronous IO is not allowed (it may or may not be, depending @@ -88,11 +88,11 @@ namespace Umbraco.Web.BackOffice.Controllers } catch (JsonReaderException) { - //can't convert + // can't convert } catch (JsonSerializationException) { - //can't convert + // can't convert } } } @@ -112,22 +112,21 @@ namespace Umbraco.Web.BackOffice.Controllers if (requestParam == string.Empty && _supportedTypes.Length > 0) { - //if it's empty then in theory we can select any of the actions since they'll all need to deal with empty or null parameters - //so we'll try to use the first one available + // if it's empty then in theory we can select any of the actions since they'll all need to deal with empty or null parameters + // so we'll try to use the first one available foundCandidate = MatchByType(_supportedTypes[0], context); if (foundCandidate.HasValue) { return true; } - } if (requestParam != null) { foreach (var paramType in _supportedTypes) { - //check if this is IEnumerable and if so this will get it's type - //we need to know this since the requestParam will always just be a string + // check if this is IEnumerable and if so this will get it's type + // we need to know this since the requestParam will always just be a string var enumType = paramType.GetEnumeratedType(); var converted = requestParam.TryConvertTo(enumType ?? paramType); @@ -150,11 +149,12 @@ namespace Umbraco.Web.BackOffice.Controllers { if (context.Candidates.Count() > 1) { - //choose the one that has the parameter with the T type + // choose the one that has the parameter with the T type var candidate = context.Candidates.FirstOrDefault(x => x.Action.Parameters.FirstOrDefault(p => p.Name == _parameterName && p.ParameterType == idType) != null); return candidate; } + return null; } diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index e6e2d579b5..97765df837 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -101,63 +101,63 @@ namespace Umbraco.Web.BackOffice.Filters { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { - if (actionContext?.HttpContext.Request == null || actionContext.HttpContext.User?.Identity == null) - { - return; - } - - // don't execute if it's already been done - if (!(_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null)) - { - return; - } - - var identity = actionContext.HttpContext.User.Identity as UmbracoBackOfficeIdentity; - if (identity == null) - { - return; - } - - Attempt userId = identity.Id.TryConvertTo(); - if (userId == false) - { - return; - } - - IUser user = _userService.GetUserById(userId.Result); - if (user == null) - { - return; - } - - // a list of checks to execute, if any of them pass then we resync - var checks = new Func[] - { - () => user.Username != identity.Username, - () => + if (actionContext?.HttpContext.Request == null || actionContext.HttpContext.User?.Identity == null) { - CultureInfo culture = user.GetUserCulture(_localizedTextService, _globalSettings.Value); - return culture != null && culture.ToString() != identity.Culture; - }, - () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, - () => user.Groups.Select(x => x.Alias).UnsortedSequenceEqual(identity.Roles) == false, - () => - { - var startContentIds = user.CalculateContentStartNodeIds(_entityService); - return startContentIds.UnsortedSequenceEqual(identity.StartContentNodes) == false; - }, - () => - { - var startMediaIds = user.CalculateMediaStartNodeIds(_entityService); - return startMediaIds.UnsortedSequenceEqual(identity.StartMediaNodes) == false; + return; } - }; - if (checks.Any(check => check())) - { - await ReSync(user, actionContext); + // don't execute if it's already been done + if (!(_requestCache.Get(nameof(CheckIfUserTicketDataIsStaleFilter)) is null)) + { + return; + } + + var identity = actionContext.HttpContext.User.Identity as UmbracoBackOfficeIdentity; + if (identity == null) + { + return; + } + + Attempt userId = identity.Id.TryConvertTo(); + if (userId == false) + { + return; + } + + IUser user = _userService.GetUserById(userId.Result); + if (user == null) + { + return; + } + + // a list of checks to execute, if any of them pass then we resync + var checks = new Func[] + { + () => user.Username != identity.Username, + () => + { + CultureInfo culture = user.GetUserCulture(_localizedTextService, _globalSettings.Value); + return culture != null && culture.ToString() != identity.Culture; + }, + () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, + () => user.Groups.Select(x => x.Alias).UnsortedSequenceEqual(identity.Roles) == false, + () => + { + var startContentIds = user.CalculateContentStartNodeIds(_entityService); + return startContentIds.UnsortedSequenceEqual(identity.StartContentNodes) == false; + }, + () => + { + var startMediaIds = user.CalculateMediaStartNodeIds(_entityService); + return startMediaIds.UnsortedSequenceEqual(identity.StartMediaNodes) == false; + } + }; + + if (checks.Any(check => check())) + { + await ReSync(user, actionContext); + } } - } } /// diff --git a/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs b/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs index 29c178e655..db8dab2813 100644 --- a/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/HttpRequestExtensions.cs @@ -86,6 +86,7 @@ namespace Umbraco.Extensions { request.Body.Seek(0, SeekOrigin.Begin); } + return result; } }