Surrounding ModelState with the newly introduced SimpleValidationModel type
This commit is contained in:
@@ -209,7 +209,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddModelErrors(result);
|
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)
|
if (ModelState.IsValid == false)
|
||||||
{
|
{
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
// so that is why it is being used here.
|
// so that is why it is being used here.
|
||||||
ModelState.AddModelError("value", result.Errors.ToErrorMessage());
|
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
|
//They've successfully set their password, we can now update their user account to be approved
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using Umbraco.Core.PropertyEditors;
|
|||||||
using Umbraco.Core.Security;
|
using Umbraco.Core.Security;
|
||||||
using Umbraco.Core.Serialization;
|
using Umbraco.Core.Serialization;
|
||||||
using Umbraco.Core.Services;
|
using Umbraco.Core.Services;
|
||||||
|
using Umbraco.Extensions;
|
||||||
using Umbraco.Web.BackOffice.Filters;
|
using Umbraco.Web.BackOffice.Filters;
|
||||||
using Umbraco.Web.Common.ActionsResults;
|
using Umbraco.Web.Common.ActionsResults;
|
||||||
using Umbraco.Web.Common.Attributes;
|
using Umbraco.Web.Common.Attributes;
|
||||||
@@ -302,7 +303,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
catch (DuplicateNameException ex)
|
catch (DuplicateNameException ex)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("Name", ex.Message);
|
ModelState.AddModelError("Name", ex.Message);
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// map back to display model, and return
|
// map back to display model, and return
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using Constants = Umbraco.Core.Constants;
|
|||||||
using Umbraco.Core.Configuration.Models;
|
using Umbraco.Core.Configuration.Models;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Umbraco.Extensions;
|
||||||
using Umbraco.Web.Common.ActionsResults;
|
using Umbraco.Web.Common.ActionsResults;
|
||||||
using Umbraco.Web.Common.Authorization;
|
using Umbraco.Web.Common.Authorization;
|
||||||
|
|
||||||
@@ -224,7 +225,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
userCulture,
|
userCulture,
|
||||||
new Dictionary<string, string> { { "0", dictionary.Name } });
|
new Dictionary<string, string> { { "0", dictionary.Name } });
|
||||||
ModelState.AddModelError("Name", message);
|
ModelState.AddModelError("Name", message);
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dictionaryItem.ItemKey = dictionary.Name;
|
dictionaryItem.ItemKey = dictionary.Name;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Umbraco.Core.Configuration.Models;
|
|||||||
using Umbraco.Core.Mapping;
|
using Umbraco.Core.Mapping;
|
||||||
using Umbraco.Core.Models;
|
using Umbraco.Core.Models;
|
||||||
using Umbraco.Core.Services;
|
using Umbraco.Core.Services;
|
||||||
|
using Umbraco.Extensions;
|
||||||
using Umbraco.Web.Common.ActionsResults;
|
using Umbraco.Web.Common.ActionsResults;
|
||||||
using Umbraco.Web.Common.Attributes;
|
using Umbraco.Web.Common.Attributes;
|
||||||
using Umbraco.Web.Common.Authorization;
|
using Umbraco.Web.Common.Authorization;
|
||||||
@@ -114,7 +115,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
public ActionResult<Language> SaveLanguage(Language language)
|
public ActionResult<Language> SaveLanguage(Language language)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
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
|
// this is prone to race conditions but the service will not let us proceed anyways
|
||||||
var existingByCulture = _localizationService.GetLanguageByIsoCode(language.IsoCode);
|
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
|
//someone is trying to create a language that already exist
|
||||||
ModelState.AddModelError("IsoCode", "The language " + language.IsoCode + " already exists");
|
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;
|
var existingById = language.Id != default ? _localizationService.GetLanguageById(language.Id) : null;
|
||||||
@@ -147,7 +148,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
catch (CultureNotFoundException)
|
catch (CultureNotFoundException)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("IsoCode", "No Culture found with name " + language.IsoCode);
|
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)
|
// 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)
|
if (existingById.IsDefault && !language.IsDefault)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("IsDefault", "Cannot un-default the default language.");
|
ModelState.AddModelError("IsDefault", "Cannot un-default the default language.");
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
existingById.IsDefault = language.IsDefault;
|
existingById.IsDefault = language.IsDefault;
|
||||||
@@ -185,12 +186,12 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
if (!languages.ContainsKey(existingById.FallbackLanguageId.Value))
|
if (!languages.ContainsKey(existingById.FallbackLanguageId.Value))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("FallbackLanguage", "The selected fall back language does not exist.");
|
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))
|
if (CreatesCycle(existingById, languages))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("FallbackLanguage", $"The selected fall back language {languages[existingById.FallbackLanguageId.Value].IsoCode} would create a circular path.");
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ using Microsoft.Net.Http.Headers;
|
|||||||
using Semver;
|
using Semver;
|
||||||
using Umbraco.Core;
|
using Umbraco.Core;
|
||||||
using Umbraco.Core.Hosting;
|
using Umbraco.Core.Hosting;
|
||||||
|
using Umbraco.Core.Models;
|
||||||
using Umbraco.Core.Models.Packaging;
|
using Umbraco.Core.Models.Packaging;
|
||||||
using Umbraco.Core.Security;
|
using Umbraco.Core.Security;
|
||||||
using Umbraco.Core.Services;
|
using Umbraco.Core.Services;
|
||||||
|
using Umbraco.Extensions;
|
||||||
using Umbraco.Web.Common.ActionsResults;
|
using Umbraco.Web.Common.ActionsResults;
|
||||||
using Umbraco.Web.Common.Attributes;
|
using Umbraco.Web.Common.Attributes;
|
||||||
using Umbraco.Web.Common.Authorization;
|
using Umbraco.Web.Common.Authorization;
|
||||||
@@ -67,7 +69,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
public ActionResult<PackageDefinition> PostSavePackage(PackageDefinition model)
|
public ActionResult<PackageDefinition> PostSavePackage(PackageDefinition model)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid == false)
|
if (ModelState.IsValid == false)
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
|
|
||||||
//save it
|
//save it
|
||||||
if (!_packagingService.SaveCreatedPackage(model))
|
if (!_packagingService.SaveCreatedPackage(model))
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
|||||||
ModelState.AddModelError(memberName, passwordChangeResult.Result.ChangeError.ErrorMessage);
|
ModelState.AddModelError(memberName, passwordChangeResult.Result.ChangeError.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValidationErrorResult(ModelState);
|
return new ValidationErrorResult(new SimpleValidationModel(ModelState.ToErrorDictionary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user