Surrounding ModelState with the newly introduced SimpleValidationModel type

This commit is contained in:
Elitsa Marinovska
2021-01-13 11:39:44 +01:00
parent 2e62a6c5f2
commit b572cf6809
7 changed files with 18 additions and 13 deletions

View File

@@ -209,7 +209,7 @@ namespace Umbraco.Web.BackOffice.Controllers
else
{
AddModelErrors(result);
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
}
@@ -470,7 +470,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
if (ModelState.IsValid == false)
{
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

View File

@@ -185,7 +185,7 @@ namespace Umbraco.Web.BackOffice.Controllers
// so that is why it is being used here.
ModelState.AddModelError("value", result.Errors.ToErrorMessage());
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
//They've successfully set their password, we can now update their user account to be approved

View File

@@ -15,6 +15,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Security;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Extensions;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.Common.ActionsResults;
using Umbraco.Web.Common.Attributes;
@@ -302,7 +303,7 @@ namespace Umbraco.Web.BackOffice.Controllers
catch (DuplicateNameException ex)
{
ModelState.AddModelError("Name", ex.Message);
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
// map back to display model, and return

View File

@@ -15,6 +15,7 @@ using Constants = Umbraco.Core.Constants;
using Umbraco.Core.Configuration.Models;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authorization;
using Umbraco.Extensions;
using Umbraco.Web.Common.ActionsResults;
using Umbraco.Web.Common.Authorization;
@@ -224,7 +225,7 @@ namespace Umbraco.Web.BackOffice.Controllers
userCulture,
new Dictionary<string, string> { { "0", dictionary.Name } });
ModelState.AddModelError("Name", message);
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
dictionaryItem.ItemKey = dictionary.Name;

View File

@@ -10,6 +10,7 @@ using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Extensions;
using Umbraco.Web.Common.ActionsResults;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Common.Authorization;
@@ -114,7 +115,7 @@ namespace Umbraco.Web.BackOffice.Controllers
public ActionResult<Language> SaveLanguage(Language language)
{
if (!ModelState.IsValid)
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
// this is prone to race conditions but the service will not let us proceed anyways
var existingByCulture = _localizationService.GetLanguageByIsoCode(language.IsoCode);
@@ -130,7 +131,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
//someone is trying to create a language that already exist
ModelState.AddModelError("IsoCode", "The language " + language.IsoCode + " already exists");
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
var existingById = language.Id != default ? _localizationService.GetLanguageById(language.Id) : null;
@@ -147,7 +148,7 @@ namespace Umbraco.Web.BackOffice.Controllers
catch (CultureNotFoundException)
{
ModelState.AddModelError("IsoCode", "No Culture found with name " + language.IsoCode);
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
// create it (creating a new language cannot create a fallback cycle)
@@ -170,7 +171,7 @@ namespace Umbraco.Web.BackOffice.Controllers
if (existingById.IsDefault && !language.IsDefault)
{
ModelState.AddModelError("IsDefault", "Cannot un-default the default language.");
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
existingById.IsDefault = language.IsDefault;
@@ -185,12 +186,12 @@ namespace Umbraco.Web.BackOffice.Controllers
if (!languages.ContainsKey(existingById.FallbackLanguageId.Value))
{
ModelState.AddModelError("FallbackLanguage", "The selected fall back language does not exist.");
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
if (CreatesCycle(existingById, languages))
{
ModelState.AddModelError("FallbackLanguage", $"The selected fall back language {languages[existingById.FallbackLanguageId.Value].IsoCode} would create a circular path.");
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}
}

View File

@@ -10,9 +10,11 @@ using Microsoft.Net.Http.Headers;
using Semver;
using Umbraco.Core;
using Umbraco.Core.Hosting;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Packaging;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Extensions;
using Umbraco.Web.Common.ActionsResults;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Common.Authorization;
@@ -67,7 +69,7 @@ namespace Umbraco.Web.BackOffice.Controllers
public ActionResult<PackageDefinition> PostSavePackage(PackageDefinition model)
{
if (ModelState.IsValid == false)
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
//save it
if (!_packagingService.SaveCreatedPackage(model))

View File

@@ -704,7 +704,7 @@ namespace Umbraco.Web.BackOffice.Controllers
ModelState.AddModelError(memberName, passwordChangeResult.Result.ChangeError.ErrorMessage);
}
return new ValidationErrorResult(ModelState);
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
}