diff --git a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs
index c74623c5fe..eeb3982118 100644
--- a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs
+++ b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs
@@ -36,10 +36,10 @@ namespace Umbraco.Cms.Core.Editors
/// The start media ids of the user being saved (can be null or empty)
/// The user aliases of the user being saved (can be null or empty)
///
- public Attempt IsAuthorized(IUser currentUser,
+ public Attempt IsAuthorized(IUser? currentUser,
IUser savingUser,
- IEnumerable startContentIds, IEnumerable startMediaIds,
- IEnumerable userGroupAliases)
+ IEnumerable? startContentIds, IEnumerable? startMediaIds,
+ IEnumerable? userGroupAliases)
{
var currentIsAdmin = currentUser.IsAdmin();
diff --git a/src/Umbraco.Core/Notifications/UserLogoutSuccessNotification.cs b/src/Umbraco.Core/Notifications/UserLogoutSuccessNotification.cs
index e8d4693852..92e7dea03f 100644
--- a/src/Umbraco.Core/Notifications/UserLogoutSuccessNotification.cs
+++ b/src/Umbraco.Core/Notifications/UserLogoutSuccessNotification.cs
@@ -2,7 +2,7 @@ namespace Umbraco.Cms.Core.Notifications
{
public class UserLogoutSuccessNotification : UserNotification
{
- public UserLogoutSuccessNotification(string ipAddress, string affectedUserId, string performingUserId) : base(ipAddress, affectedUserId, performingUserId)
+ public UserLogoutSuccessNotification(string ipAddress, string? affectedUserId, string performingUserId) : base(ipAddress, affectedUserId, performingUserId)
{
}
diff --git a/src/Umbraco.Core/Notifications/UserNotification.cs b/src/Umbraco.Core/Notifications/UserNotification.cs
index aa3223e980..f0ce83c8fb 100644
--- a/src/Umbraco.Core/Notifications/UserNotification.cs
+++ b/src/Umbraco.Core/Notifications/UserNotification.cs
@@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Notifications
{
public abstract class UserNotification : INotification
{
- protected UserNotification(string ipAddress, string affectedUserId, string performingUserId)
+ protected UserNotification(string ipAddress, string? affectedUserId, string performingUserId)
{
DateTimeUtc = DateTime.UtcNow;
IpAddress = ipAddress;
@@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Notifications
///
/// The user affected by the event raised
///
- public string AffectedUserId { get; }
+ public string? AffectedUserId { get; }
///
/// If a user is performing an action on a different user, then this will be set. Otherwise it will be -1
diff --git a/src/Umbraco.Core/Security/ContentPermissions.cs b/src/Umbraco.Core/Security/ContentPermissions.cs
index a0bcb64ced..e1f8fb9e44 100644
--- a/src/Umbraco.Core/Security/ContentPermissions.cs
+++ b/src/Umbraco.Core/Security/ContentPermissions.cs
@@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core.Security
public ContentAccess CheckPermissions(
IContent content,
- IUser user,
+ IUser? user,
IReadOnlyList permissionsToCheck)
{
if (user == null) throw new ArgumentNullException(nameof(user));
@@ -70,12 +70,12 @@ namespace Umbraco.Cms.Core.Security
public ContentAccess CheckPermissions(
IUmbracoEntity entity,
- IUser user,
+ IUser? user,
char permissionToCheck) => CheckPermissions(entity, user, new[] { permissionToCheck });
public ContentAccess CheckPermissions(
IUmbracoEntity entity,
- IUser user,
+ IUser? user,
IReadOnlyList permissionsToCheck)
{
if (user == null) throw new ArgumentNullException(nameof(user));
@@ -159,7 +159,7 @@ namespace Umbraco.Cms.Core.Security
///
public ContentAccess CheckPermissions(
int nodeId,
- IUser user,
+ IUser? user,
out IContent? contentItem,
IReadOnlyList? permissionsToCheck = null)
{
diff --git a/src/Umbraco.Core/Security/MediaPermissions.cs b/src/Umbraco.Core/Security/MediaPermissions.cs
index 99b4d15cd6..d30ab90af2 100644
--- a/src/Umbraco.Core/Security/MediaPermissions.cs
+++ b/src/Umbraco.Core/Security/MediaPermissions.cs
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Security
///
/// The content to lookup, if the contentItem is not specified
///
- public MediaAccess CheckPermissions(IUser user, int nodeId, out IMedia? media)
+ public MediaAccess CheckPermissions(IUser? user, int nodeId, out IMedia? media)
{
if (user == null) throw new ArgumentNullException(nameof(user));
@@ -63,7 +63,7 @@ namespace Umbraco.Cms.Core.Security
return hasPathAccess ? MediaAccess.Granted : MediaAccess.Denied;
}
- public MediaAccess CheckPermissions(IMedia media, IUser user)
+ public MediaAccess CheckPermissions(IMedia? media, IUser? user)
{
if (user == null) throw new ArgumentNullException(nameof(user));
diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs
index 3149ad0370..10f6a04020 100644
--- a/src/Umbraco.Core/Services/IUserService.cs
+++ b/src/Umbraco.Core/Services/IUserService.cs
@@ -120,7 +120,7 @@ namespace Umbraco.Cms.Core.Services
///
/// Ids of the users to retrieve
///
- IEnumerable GetUsersById(params int[] ids);
+ IEnumerable GetUsersById(params int[]? ids);
///
/// Removes a specific section from all user groups
diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs
index 3131180732..87922a5d83 100644
--- a/src/Umbraco.Core/Services/UserService.cs
+++ b/src/Umbraco.Core/Services/UserService.cs
@@ -687,9 +687,9 @@ namespace Umbraco.Cms.Core.Services
}
}
- public IEnumerable GetUsersById(params int[] ids)
+ public IEnumerable GetUsersById(params int[]? ids)
{
- if (ids.Length <= 0) return Enumerable.Empty();
+ if (ids?.Length <= 0) return Enumerable.Empty();
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
diff --git a/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs b/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs
index 2a357430ed..01dbe15463 100644
--- a/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs
+++ b/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs
@@ -10,6 +10,6 @@ namespace Umbraco.Cms.Core.Security
{
void NotifyForgotPasswordRequested(IPrincipal currentUser, string userId);
void NotifyForgotPasswordChanged(IPrincipal currentUser, string userId);
- SignOutSuccessResult NotifyLogoutSuccess(IPrincipal currentUser, string userId);
+ SignOutSuccessResult NotifyLogoutSuccess(IPrincipal currentUser, string? userId);
}
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
index 36d01675d5..819e0b127b 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
@@ -57,35 +57,35 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
return Task.FromResult(true);
}
- int[] userIds;
+ int[]? userIds;
if (int.TryParse(queryString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var userId))
{
userIds = new[] { userId };
}
else
{
- var ids = queryString.ToString().Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList();
- if (ids.Count == 0)
+ var ids = queryString.ToString()?.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList();
+ if (ids?.Count == 0)
{
// Must succeed this requirement since we cannot process it.
return Task.FromResult(true);
}
- userIds = ids
+ userIds = ids?
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var output) ? Attempt.Succeed(output) : Attempt.Fail())
.Where(x => x.Success)
.Select(x => x.Result)
.ToArray();
}
- if (userIds.Length == 0)
+ if (userIds?.Length == 0)
{
// Must succeed this requirement since we cannot process it.
return Task.FromResult(true);
}
IEnumerable users = _userService.GetUsersById(userIds);
- var isAuth = users.All(user => _userEditorAuthorizationHelper.IsAuthorized(_backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser, user, null, null, null) != false);
+ var isAuth = users.All(user => _userEditorAuthorizationHelper.IsAuthorized(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, user, null, null, null) != false);
return Task.FromResult(isAuth);
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/BackOfficeHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/BackOfficeHandler.cs
index fd7f8eb971..99fd24348a 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/BackOfficeHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/BackOfficeHandler.cs
@@ -34,12 +34,12 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
case var _ when _runtimeState.EnableInstaller():
return Task.FromResult(true);
default:
- if (!_backOfficeSecurity.BackOfficeSecurity.IsAuthenticated())
+ if (!_backOfficeSecurity.BackOfficeSecurity?.IsAuthenticated() ?? false)
{
return Task.FromResult(false);
}
- var userApprovalSucceeded = !requirement.RequireApproval || (_backOfficeSecurity.BackOfficeSecurity.CurrentUser?.IsApproved ?? false);
+ var userApprovalSucceeded = !requirement.RequireApproval || (_backOfficeSecurity.BackOfficeSecurity?.CurrentUser?.IsApproved ?? false);
return Task.FromResult(userApprovalSucceeded);
}
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsPublishBranchHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsPublishBranchHandler.cs
index b620daf0f8..8c9814d41b 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsPublishBranchHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsPublishBranchHandler.cs
@@ -42,7 +42,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
///
protected override Task IsAuthorized(AuthorizationHandlerContext context, ContentPermissionsPublishBranchRequirement requirement, IContent resource)
{
- IUser currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
+ IUser? currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser;
var denied = new List();
var page = 0;
diff --git a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringHandler.cs
index 10d2aaffde..adb4521bfe 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringHandler.cs
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
int nodeId;
if (requirement.NodeId.HasValue == false)
{
- if (!HttpContextAccessor.HttpContext.Request.Query.TryGetValue(requirement.QueryStringName, out StringValues routeVal))
+ if (HttpContextAccessor.HttpContext is null || requirement.QueryStringName is null || !HttpContextAccessor.HttpContext.Request.Query.TryGetValue(requirement.QueryStringName, out StringValues routeVal))
{
// Must succeed this requirement since we cannot process it
return Task.FromResult(true);
@@ -61,11 +61,11 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
ContentPermissions.ContentAccess permissionResult = _contentPermissions.CheckPermissions(
nodeId,
- BackOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
- out IContent contentItem,
+ BackOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser,
+ out IContent? contentItem,
new[] { requirement.PermissionToCheck });
- if (contentItem != null)
+ if (HttpContextAccessor.HttpContext is not null && contentItem is not null)
{
// Store the content item in request cache so it can be resolved in the controller without re-looking it up.
HttpContextAccessor.HttpContext.Items[typeof(IContent).ToString()] = contentItem;
diff --git a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringRequirement.cs b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringRequirement.cs
index d958968d6e..e5a432fb93 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringRequirement.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsQueryStringRequirement.cs
@@ -41,7 +41,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
///
/// Gets the querystring parameter name.
///
- public string QueryStringName { get; }
+ public string? QueryStringName { get; }
///
/// Gets the permission to authorize the current user against.
diff --git a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsResourceHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsResourceHandler.cs
index 3c1bf8ae56..63d90b4565 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsResourceHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/ContentPermissionsResourceHandler.cs
@@ -35,12 +35,12 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
ContentPermissions.ContentAccess permissionResult = resource.NodeId.HasValue
? _contentPermissions.CheckPermissions(
resource.NodeId.Value,
- _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
- out IContent _,
+ _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser,
+ out IContent? _,
resource.PermissionsToCheck)
: _contentPermissions.CheckPermissions(
resource.Content,
- _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
+ _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser,
resource.PermissionsToCheck);
return Task.FromResult(permissionResult != ContentPermissions.ContentAccess.Denied);
diff --git a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsQueryStringHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsQueryStringHandler.cs
index 6deccbc0cb..fae3da7d63 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsQueryStringHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsQueryStringHandler.cs
@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
///
protected override Task IsAuthorized(AuthorizationHandlerContext context, MediaPermissionsQueryStringRequirement requirement)
{
- if (!HttpContextAccessor.HttpContext.Request.Query.TryGetValue(requirement.QueryStringName, out StringValues routeVal))
+ if (HttpContextAccessor.HttpContext is null || !HttpContextAccessor.HttpContext.Request.Query.TryGetValue(requirement.QueryStringName, out StringValues routeVal))
{
// Must succeed this requirement since we cannot process it.
return Task.FromResult(true);
@@ -50,9 +50,9 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
}
MediaPermissions.MediaAccess permissionResult = _mediaPermissions.CheckPermissions(
- BackOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
+ BackOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser,
nodeId,
- out IMedia mediaItem);
+ out IMedia? mediaItem);
if (mediaItem != null)
{
diff --git a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResource.cs b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResource.cs
index 48eed0a844..10ac4d6d75 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResource.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResource.cs
@@ -18,6 +18,6 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
}
public int? NodeId { get; }
- public IMedia Media { get; }
+ public IMedia? Media { get; }
}
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResourceHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResourceHandler.cs
index 71cace6b6f..9ddce4c576 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResourceHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/MediaPermissionsResourceHandler.cs
@@ -34,12 +34,12 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
{
MediaPermissions.MediaAccess permissionResult = resource.NodeId.HasValue
? _mediaPermissions.CheckPermissions(
- _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
+ _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser,
resource.NodeId.Value,
out _)
: _mediaPermissions.CheckPermissions(
resource.Media,
- _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser);
+ _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser);
return Task.FromResult(permissionResult != MediaPermissions.MediaAccess.Denied);
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
index e8433dd1a8..cdb9ba63d9 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
@@ -67,7 +67,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
nodeId = parsedId;
return true;
}
- else if (UdiParser.TryParse(argument, true, out Udi udi))
+ else if (UdiParser.TryParse(argument, true, out Udi? udi))
{
nodeId = EntityService.GetId(udi).Result;
return true;
diff --git a/src/Umbraco.Web.BackOffice/Authorization/SectionHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/SectionHandler.cs
index 4b2ffd356d..f081c65817 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/SectionHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/SectionHandler.cs
@@ -27,7 +27,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
///
protected override Task IsAuthorized(AuthorizationHandlerContext context, SectionRequirement requirement)
{
- var authorized = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser != null &&
+ var authorized = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser != null &&
requirement.SectionAliases
.Any(app => _backOfficeSecurityAccessor.BackOfficeSecurity.UserHasSectionAccess(
app, _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser));
diff --git a/src/Umbraco.Web.BackOffice/Authorization/TreeHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/TreeHandler.cs
index 6e9269e6bd..e580495907 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/TreeHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/TreeHandler.cs
@@ -44,7 +44,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
.Distinct()
.ToArray();
- var isAuth = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser != null &&
+ var isAuth = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser != null &&
apps.Any(app => _backOfficeSecurityAccessor.BackOfficeSecurity.UserHasSectionAccess(
app, _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser));
diff --git a/src/Umbraco.Web.BackOffice/Authorization/UserGroupHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/UserGroupHandler.cs
index 118aede07a..037d59c89e 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/UserGroupHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/UserGroupHandler.cs
@@ -61,7 +61,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
///
protected override Task IsAuthorized(AuthorizationHandlerContext context, UserGroupRequirement requirement)
{
- IUser currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
+ IUser? currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser;
var querystring = _httpContextAccessor.HttpContext?.Request.Query[requirement.QueryStringName];
if (querystring is null)
@@ -87,7 +87,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
_entityService,
_appCaches);
- Attempt isAuth = authHelper.AuthorizeGroupAccess(currentUser, intIds);
+ Attempt isAuth = authHelper.AuthorizeGroupAccess(currentUser, intIds);
return Task.FromResult(isAuth.Success);
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
index c47a602f15..d478784fa3 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
@@ -127,7 +127,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)] // Needed to enforce the principle set on the request, if one exists.
public IDictionary GetPasswordConfig(int userId)
{
- Attempt currentUserId = _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId();
+ Attempt currentUserId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId() ?? Attempt.Fail();
return _passwordConfiguration.GetConfiguration(
currentUserId.Success
? currentUserId.Result != userId
@@ -592,7 +592,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
_logger.LogInformation("User {UserName} from IP address {RemoteIpAddress} has logged out", User.Identity == null ? "UNKNOWN" : User.Identity.Name, HttpContext.Connection.RemoteIpAddress);
- var userId = result.Principal.Identity.GetUserId();
+ var userId = result.Principal.Identity?.GetUserId();
var args = _userManager.NotifyLogoutSuccess(User, userId);
if (!args.SignOutRedirectUrl.IsNullOrWhiteSpace())
{
@@ -612,13 +612,17 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
///
///
///
- private UserDetail GetUserDetail(IUser user)
+ private UserDetail? GetUserDetail(IUser? user)
{
if (user == null) throw new ArgumentNullException(nameof(user));
var userDetail = _umbracoMapper.Map(user);
- // update the userDetail and set their remaining seconds
- userDetail.SecondsUntilTimeout = _globalSettings.TimeOut.TotalSeconds;
+
+ if (userDetail is not null)
+ {
+ // update the userDetail and set their remaining seconds
+ userDetail.SecondsUntilTimeout = _globalSettings.TimeOut.TotalSeconds;
+ }
return userDetail;
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs
index e34223fec1..f206168237 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs
@@ -13,7 +13,9 @@ using Umbraco.Cms.Core.Features;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Mail;
using Umbraco.Cms.Core.Media;
+using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
+using Umbraco.Cms.Core.Models.TemplateQuery;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Core.WebAssets;
@@ -24,6 +26,7 @@ using Umbraco.Cms.Web.BackOffice.Routing;
using Umbraco.Cms.Web.BackOffice.Security;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Cms.Web.Common.Attributes;
+using Umbraco.Cms.Web.Common.Models;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.BackOffice.Controllers
@@ -136,7 +139,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
// TODO: This is ultra confusing! this same key is used for different things, when returning the full app when authenticated it is this URL but when not auth'd it's actually the ServerVariables address
// so based on compat and how things are currently working we need to replace the serverVarsJs one
- ((Dictionary)defaults["umbracoUrls"])["serverVarsJs"]
+ ((Dictionary)defaults["umbracoUrls"])["serverVarsJs"]
= _linkGenerator.GetPathByAction(
nameof(BackOfficeController.ServerVariables),
ControllerExtensions.GetControllerName(),
@@ -156,7 +159,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
var defaultVals = new Dictionary
{
{
- "umbracoUrls", new Dictionary
+ "umbracoUrls", new Dictionary
{
// TODO: Add 'umbracoApiControllerBaseUrl' which people can use in JS
// to prepend their URL. We could then also use this in our own resources instead of
@@ -186,15 +189,15 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"userApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostSaveUser(null))
+ controller => controller.PostSaveUser(new UserSave()))
},
{
"userGroupsApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostSaveUserGroup(null))
+ controller => controller.PostSaveUserGroup(new UserGroupSave()))
},
{
"contentApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostSave(null))
+ controller => controller.PostSave(new ContentItemSave()))
},
{
"publicAccessApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -218,7 +221,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"treeApplicationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetApplicationTrees(null, null, null, TreeUse.None))
+ controller => controller.GetApplicationTrees(string.Empty, string.Empty, FormCollection.Empty, TreeUse.None))
},
{
"contentTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -234,15 +237,15 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"macroApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.Create(null))
+ controller => controller.Create(string.Empty))
},
{
"authenticationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostLogin(null))
+ controller => controller.PostLogin(new LoginModel()))
},
{
"currentUserApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostChangePassword(null))
+ controller => controller.PostChangePassword(new ChangingPasswordModel()))
},
{
"entityApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -254,7 +257,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"dashboardApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetDashboard(null))
+ controller => controller.GetDashboard(string.Empty))
},
{
"logApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -302,15 +305,15 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"memberTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetNodes("-1", null))
+ controller => controller.GetNodes("-1", FormCollection.Empty))
},
{
"mediaTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetNodes("-1", null))
+ controller => controller.GetNodes("-1", FormCollection.Empty))
},
{
"contentTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetNodes("-1", null))
+ controller => controller.GetNodes("-1", FormCollection.Empty))
},
{
"tagsDataBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -326,7 +329,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"templateQueryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.PostTemplateQuery(null))
+ controller => controller.PostTemplateQuery(new QueryModel()))
},
{
"codeFileApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -370,11 +373,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
},
{
"tinyMceApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.UploadImage(null))
+ controller => controller.UploadImage(new FormFileCollection()))
},
{
"imageUrlGeneratorApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetCropUrl(null, null, null, null))
+ controller => controller.GetCropUrl(string.Empty, null, null, null))
},
{
"elementTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl(
@@ -481,10 +484,10 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
private class PluginTree
{
[DataMember(Name = "alias")]
- public string Alias { get; set; }
+ public string? Alias { get; set; }
[DataMember(Name = "packageFolder")]
- public string PackageFolder { get; set; }
+ public string? PackageFolder { get; set; }
}
private IEnumerable GetPluginTrees()
@@ -520,10 +523,10 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
/// Returns the server variables regarding the application state
///
///
- private Dictionary GetApplicationState()
+ private Dictionary GetApplicationState()
{
var version = _runtimeState.SemanticVersion.ToSemanticStringWithoutBuild();
- var app = new Dictionary
+ var app = new Dictionary
{
// add versions - see UmbracoVersion for details & differences
@@ -531,7 +534,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
{ "version", version },
// the assembly version (eg "8.0.0")
- { "assemblyVersion", _umbracoVersion.AssemblyVersion.ToString() }
+ { "assemblyVersion", _umbracoVersion.AssemblyVersion?.ToString() }
};
diff --git a/src/Umbraco.Web.BackOffice/Controllers/UserGroupEditorAuthorizationHelper.cs b/src/Umbraco.Web.BackOffice/Controllers/UserGroupEditorAuthorizationHelper.cs
index ea74b47e87..35eab84432 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/UserGroupEditorAuthorizationHelper.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/UserGroupEditorAuthorizationHelper.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
@@ -33,17 +34,19 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
///
///
///
- public Attempt AuthorizeGroupAccess(IUser currentUser, params int[] groupIds)
+ public Attempt AuthorizeGroupAccess(IUser? currentUser, params int[] groupIds)
{
- if (currentUser.IsAdmin())
- return Attempt.Succeed();
+ if (currentUser?.IsAdmin() ?? false)
+ {
+ return Attempt.Succeed();
+ }
var groups = _userService.GetAllUserGroups(groupIds.ToArray());
var groupAliases = groups.Select(x => x.Alias).ToArray();
- var userGroups = currentUser.Groups.Select(x => x.Alias).ToArray();
+ var userGroups = currentUser?.Groups.Select(x => x.Alias).ToArray() ?? Array.Empty();
var missingAccess = groupAliases.Except(userGroups).ToArray();
return missingAccess.Length == 0
- ? Attempt.Succeed()
+ ? Attempt.Succeed()
: Attempt.Fail("User is not a member of " + string.Join(", ", missingAccess));
}
@@ -53,10 +56,10 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
///
///
///
- public Attempt AuthorizeGroupAccess(IUser currentUser, params string[] groupAliases)
+ public Attempt AuthorizeGroupAccess(IUser currentUser, params string[] groupAliases)
{
if (currentUser.IsAdmin())
- return Attempt.Succeed();
+ return Attempt.Succeed();
var existingGroups = _userService.GetUserGroupsByAlias(groupAliases);
@@ -65,32 +68,32 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
// We're dealing with new groups,
// so authorization should be given to any user with access to Users section
if (currentUser.AllowedSections.Contains(Constants.Applications.Users))
- return Attempt.Succeed();
+ return Attempt.Succeed();
}
var userGroups = currentUser.Groups.Select(x => x.Alias).ToArray();
var missingAccess = groupAliases.Except(userGroups).ToArray();
return missingAccess.Length == 0
- ? Attempt.Succeed()
+ ? Attempt.Succeed()
: Attempt.Fail("User is not a member of " + string.Join(", ", missingAccess));
}
///
/// Authorize that the user is not adding a section to the group that they don't have access to
///
- public Attempt AuthorizeSectionChanges(
+ public Attempt AuthorizeSectionChanges(
IUser currentUser,
IEnumerable existingSections,
IEnumerable proposedAllowedSections)
{
if (currentUser.IsAdmin())
- return Attempt.Succeed();
+ return Attempt.Succeed();
var sectionsAdded = proposedAllowedSections.Except(existingSections).ToArray();
var sectionAccessMissing = sectionsAdded.Except(currentUser.AllowedSections).ToArray();
return sectionAccessMissing.Length > 0
? Attempt.Fail("Current user doesn't have access to add these sections " + string.Join(", ", sectionAccessMissing))
- : Attempt.Succeed();
+ : Attempt.Succeed();
}
///
@@ -102,7 +105,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
///
///
///
- public Attempt AuthorizeStartNodeChanges(IUser currentUser,
+ public Attempt AuthorizeStartNodeChanges(IUser currentUser,
int? currentContentStartId,
int? proposedContentStartId,
int? currentMediaStartId,
@@ -128,7 +131,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
}
}
- return Attempt.Succeed();
+ return Attempt.Succeed();
}
}
}
diff --git a/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs b/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs
index 7f02de4794..be20144533 100644
--- a/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs
+++ b/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs
@@ -36,7 +36,7 @@ namespace Umbraco.Cms.Web.BackOffice.PropertyEditors
///
///
[AllowHttpJsonConfigration]
- public IEnumerable GetTags(string tagGroup, string culture, string query = null)
+ public IEnumerable GetTags(string tagGroup, string? culture, string? query = null)
{
if (culture == string.Empty) culture = null;
diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj
index 7172a94291..6f88b97fa3 100644
--- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj
+++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj
@@ -7,6 +7,8 @@
Umbraco.Cms.Web.BackOffice
Umbraco CMS Back Office
Contains the Back Office assembly needed to run the back office of Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco
+ enable
+ Nullable
diff --git a/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs b/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs
index aa3323e101..0335e60f4e 100644
--- a/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs
+++ b/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs
@@ -204,7 +204,7 @@ namespace Umbraco.Cms.Web.Common.Security
(currentUserId, ip) => new UserLoginSuccessNotification(ip, userId, currentUserId)
);
- public SignOutSuccessResult NotifyLogoutSuccess(IPrincipal currentUser, string userId)
+ public SignOutSuccessResult NotifyLogoutSuccess(IPrincipal currentUser, string? userId)
{
var notification = Notify(currentUser,
(currentUserId, ip) => new UserLogoutSuccessNotification(ip, userId, currentUserId)