New Backoffice: Fix feedback to users controller (#14031)

* Add specific not found results

* Add tests for the enable/disable not found tweak

* Cache ids and key in UserIdKeyResolver

* Don't cache null keys

* BackOffice not Backoffice

* Move fetching the user out of the ChangePasswordUsersController

* Move resolving user out of SetAvatar

* Move resolving user out of Update

* Return more specific notfound in bykey

* Use ErrorResult for all endpoints with unknown errors

* Split integration tests

* Add mappers

* Use ?: consistently

* Add reuseable iso code validator

* Validate ISO code

* Update supressions

* Use method from base to get current user key

* Rename ISo to Iso

* Use keys in services instead of user groups + Added a couple of new validations

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Mole
2023-04-04 15:41:12 +02:00
committed by GitHub
parent 6313b8b3a1
commit 21b0a7ffae
61 changed files with 731 additions and 364 deletions

View File

@@ -6,12 +6,12 @@ using Umbraco.Cms.Web.Common.Security;
namespace Umbraco.Cms.Web.BackOffice.Security;
public class BackofficePasswordChanger : IBackofficePasswordChanger
public class BackOfficePasswordChanger : IBackOfficePasswordChanger
{
private readonly IPasswordChanger<BackOfficeIdentityUser> _passwordChanger;
private readonly IBackOfficeUserManager _userManager;
public BackofficePasswordChanger(
public BackOfficePasswordChanger(
IPasswordChanger<BackOfficeIdentityUser> passwordChanger,
IBackOfficeUserManager userManager)
{
@@ -19,8 +19,8 @@ public class BackofficePasswordChanger : IBackofficePasswordChanger
_userManager = userManager;
}
public async Task<Attempt<PasswordChangedModel?>> ChangeBackofficePassword(
ChangeBackofficeUserPasswordModel model)
public async Task<Attempt<PasswordChangedModel?>> ChangeBackOfficePassword(
ChangeBackOfficeUserPasswordModel model)
{
var mappedModel = new ChangingPasswordModel
{

View File

@@ -15,13 +15,13 @@ namespace Umbraco.Cms.Web.BackOffice.Security;
public class InviteUriProvider : IInviteUriProvider
{
private readonly LinkGenerator _linkGenerator;
private readonly ICoreBackofficeUserManager _userManager;
private readonly ICoreBackOfficeUserManager _userManager;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly WebRoutingSettings _webRoutingSettings;
public InviteUriProvider(
LinkGenerator linkGenerator,
ICoreBackofficeUserManager userManager,
ICoreBackOfficeUserManager userManager,
IHttpContextAccessor httpContextAccessor,
IOptions<WebRoutingSettings> webRoutingSettings)
{

View File

@@ -47,7 +47,7 @@ internal class PasswordChanger<TUser> : IPasswordChanger<TUser> where TUser : Um
{
return Attempt.Fail(new PasswordChangedModel
{
ChangeError = new ValidationResult("Cannot set an empty password", new[] { "value" })
Error = new ValidationResult("Cannot set an empty password", new[] { "value" })
});
}
@@ -58,7 +58,7 @@ internal class PasswordChanger<TUser> : IPasswordChanger<TUser> where TUser : Um
// this really shouldn't ever happen... but just in case
return Attempt.Fail(new PasswordChangedModel
{
ChangeError = new ValidationResult("Password could not be verified", new[] { "oldPassword" })
Error = new ValidationResult("Password could not be verified", new[] { "oldPassword" })
});
}
@@ -77,7 +77,7 @@ internal class PasswordChanger<TUser> : IPasswordChanger<TUser> where TUser : Um
_logger.LogWarning("Could not reset user password {PasswordErrors}", errors);
return Attempt.Fail(new PasswordChangedModel
{
ChangeError = new ValidationResult(errors, new[] { "value" })
Error = new ValidationResult(errors, new[] { "value" })
});
}
@@ -91,7 +91,7 @@ internal class PasswordChanger<TUser> : IPasswordChanger<TUser> where TUser : Um
// no, fail with an error message for "oldPassword"
return Attempt.Fail(new PasswordChangedModel
{
ChangeError = new ValidationResult("Incorrect password", new[] { "oldPassword" })
Error = new ValidationResult("Incorrect password", new[] { "oldPassword" })
});
}
@@ -104,7 +104,7 @@ internal class PasswordChanger<TUser> : IPasswordChanger<TUser> where TUser : Um
_logger.LogWarning("Could not change user password {PasswordErrors}", errors);
return Attempt.Fail(new PasswordChangedModel
{
ChangeError = new ValidationResult(errors, new[] { "password" })
Error = new ValidationResult(errors, new[] { "password" })
});
}