Changed back Attempt<int?> to Attempt<int> (#12468)
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
/// <returns>The current user's Id that has been authenticated for the request.</returns>
|
||||
/// <remarks>If authentication hasn't taken place this will be unsuccessful.</remarks>
|
||||
// TODO: This should just be an extension method on ClaimsIdentity
|
||||
Attempt<int?> GetUserId();
|
||||
Attempt<int> GetUserId();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified user as access to the app
|
||||
|
||||
@@ -130,7 +130,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<string, object> GetPasswordConfig(int userId)
|
||||
{
|
||||
Attempt<int?> currentUserId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId() ?? Attempt<int?>.Fail();
|
||||
Attempt<int> currentUserId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId() ?? Attempt<int>.Fail();
|
||||
return _passwordConfiguration.GetConfiguration(
|
||||
currentUserId.Success
|
||||
? currentUserId.Result != userId
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[ValidateAngularAntiForgeryToken]
|
||||
public async Task<Dictionary<string, string>> GetCurrentUserLinkedLogins()
|
||||
{
|
||||
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().ResultOr(0)?.ToString(CultureInfo.InvariantCulture));
|
||||
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
// deduplicate in case there are duplicates (there shouldn't be now since we have a unique constraint on the external logins
|
||||
// but there didn't used to be)
|
||||
|
||||
@@ -742,8 +742,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[Authorize(Policy = AuthorizationPolicies.AdminUserEditsRequireAdmin)]
|
||||
public IActionResult PostDisableUsers([FromQuery]int[] userIds)
|
||||
{
|
||||
var tryGetCurrentUserId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId() ?? Attempt<int?>.Fail();
|
||||
if (tryGetCurrentUserId.Success && userIds.Contains(tryGetCurrentUserId.Result!.Value))
|
||||
var tryGetCurrentUserId = _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId() ?? Attempt<int>.Fail();
|
||||
if (tryGetCurrentUserId.Success && userIds.Contains(tryGetCurrentUserId.Result))
|
||||
{
|
||||
return ValidationProblem("The current user cannot disable itself");
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public class BackOfficeSecurity : IBackOfficeSecurity
|
||||
// Check again
|
||||
if (_currentUser == null)
|
||||
{
|
||||
Attempt<int?> id = GetUserId();
|
||||
if (id.Success && id.Result is not null)
|
||||
Attempt<int> id = GetUserId();
|
||||
if (id.Success)
|
||||
{
|
||||
_currentUser = id.Success ? _userService.GetUserById(id.Result.Value) : null;
|
||||
_currentUser = id.Success ? _userService.GetUserById(id.Result) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,10 +50,12 @@ public class BackOfficeSecurity : IBackOfficeSecurity
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Attempt<int?> GetUserId()
|
||||
public Attempt<int> GetUserId()
|
||||
{
|
||||
ClaimsIdentity? identity = _httpContextAccessor.HttpContext?.GetCurrentIdentity();
|
||||
return identity == null ? Attempt.Fail<int?>() : Attempt.Succeed(identity.GetId());
|
||||
|
||||
var id = identity?.GetId();
|
||||
return id.HasValue is false ? Attempt.Fail<int>() : Attempt.Succeed(id.Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.CoreThings
|
||||
public void CanConvertIntToNullableInt()
|
||||
{
|
||||
int i = 1;
|
||||
Attempt<int?> result = i.TryConvertTo<int?>();
|
||||
Attempt<int> result = i.TryConvertTo<int>();
|
||||
Assert.That(result.Success, Is.True);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user