Fixes validation check for variant nodes that don't have names assigned
This commit is contained in:
@@ -312,10 +312,10 @@ namespace Umbraco.Core.Models
|
||||
public bool Blueprint { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool TryPublishAllValues()
|
||||
internal virtual bool TryPublishAllValues()
|
||||
{
|
||||
// the values we want to publish should be valid
|
||||
if (ValidateAll().Any())
|
||||
if (ValidateAllProperties().Any())
|
||||
return false; //fixme this should return an attempt with error results
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
@@ -347,7 +347,7 @@ namespace Umbraco.Core.Models
|
||||
ContentType.ValidateVariation(culture, segment, throwIfInvalid: true);
|
||||
|
||||
// the values we want to publish should be valid
|
||||
if (Validate(culture, segment).Any())
|
||||
if (ValidateProperties(culture, segment).Any())
|
||||
return false; //fixme this should return an attempt with error results
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
@@ -370,10 +370,12 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool PublishCultureValues(string culture = null)
|
||||
{
|
||||
internal virtual bool PublishCultureValues(string culture = null)
|
||||
{
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
|
||||
// the values we want to publish should be valid
|
||||
if (ValidateCulture(culture).Any())
|
||||
if (ValidatePropertiesForCulture(culture).Any())
|
||||
return false;
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
|
||||
@@ -307,21 +307,23 @@ namespace Umbraco.Core.Models
|
||||
|
||||
#region Validation
|
||||
|
||||
public virtual Property[] ValidateAll()
|
||||
{
|
||||
internal virtual Property[] ValidateAllProperties()
|
||||
{
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
|
||||
return Properties.Where(x => !x.IsAllValid()).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the content item's properties for the provided culture/segment
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="segment"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This will not perform validation for properties that do not match the required ContentVariation based on the culture/segment values provided
|
||||
/// </remarks>
|
||||
public virtual Property[] Validate(string culture = null, string segment = null)
|
||||
/// <inheritdoc />
|
||||
public bool IsValid(string culture = null, string segment = null)
|
||||
{
|
||||
var name = GetName(culture);
|
||||
if (name.IsNullOrWhiteSpace()) return false;
|
||||
return ValidateProperties(culture, segment).Length == 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Property[] ValidateProperties(string culture = null, string segment = null)
|
||||
{
|
||||
return Properties.Where(x =>
|
||||
{
|
||||
@@ -337,8 +339,10 @@ namespace Umbraco.Core.Models
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
public virtual Property[] ValidateCulture(string culture = null)
|
||||
{
|
||||
internal virtual Property[] ValidatePropertiesForCulture(string culture = null)
|
||||
{
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
|
||||
return Properties.Where(x => !x.IsCultureValid(culture)).ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -169,8 +169,9 @@ namespace Umbraco.Core.Models
|
||||
/// <para>The document must then be published via the content service.</para>
|
||||
/// <para>Values are not published if they are not valid.</para>
|
||||
/// </remarks>
|
||||
//fixme return an Attempt with some error results if it doesn't work
|
||||
bool TryPublishAllValues();
|
||||
//fixme return an Attempt with some error results if it doesn't work
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
//bool TryPublishAllValues();
|
||||
|
||||
/// <summary>
|
||||
/// Publishes values.
|
||||
@@ -190,8 +191,9 @@ namespace Umbraco.Core.Models
|
||||
/// <remarks>
|
||||
/// <para>The document must then be published via the content service.</para>
|
||||
/// <para>Values are not published if they are not valie.</para>
|
||||
/// </remarks>
|
||||
bool PublishCultureValues(string culture = null);
|
||||
/// </remarks>
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
//bool PublishCultureValues(string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Clears all published values.
|
||||
|
||||
@@ -108,20 +108,36 @@ namespace Umbraco.Core.Models
|
||||
/// Sets the (edited) value of a Property
|
||||
/// </summary>
|
||||
void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the content and property values are valid in order to be persisted.
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="segment"></param>
|
||||
/// <returns></returns>
|
||||
bool IsValid(string culture = null, string segment = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content and all its properties values are valid.
|
||||
/// </summary>
|
||||
Property[] ValidateAll();
|
||||
/// Gets a value indicating if all properties values are valid.
|
||||
/// </summary>
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
//Property[] ValidateAllProperties();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content and its properties values are valid.
|
||||
/// Validates the content item's properties for the provided culture/segment
|
||||
/// </summary>
|
||||
Property[] Validate(string culture = null, string segment = null);
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="segment"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This will not perform validation for properties that do not match the required ContentVariation based on the culture/segment values provided
|
||||
/// </remarks>
|
||||
Property[] ValidateProperties(string culture = null, string segment = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content and its culture/any properties values are valid.
|
||||
/// </summary>
|
||||
Property[] ValidateCulture(string culture = null);
|
||||
/// Gets a value indicating if the culture properties values are valid.
|
||||
/// </summary>
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
//Property[] ValidatePropertiesForCulture(string culture = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,11 +332,13 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether everything is valid.
|
||||
/// Gets a value indicating whether all properties are valid.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsAllValid()
|
||||
{
|
||||
internal bool IsAllValid()
|
||||
{
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
|
||||
// invariant-neutral is supported, validate invariant-neutral
|
||||
// includes mandatory validation
|
||||
if (PropertyType.ValidateVariation(null, null, false) && !IsValidValue(_pvalue)) return false;
|
||||
@@ -359,8 +361,10 @@ namespace Umbraco.Core.Models
|
||||
/// Gets a value indicating whether the culture/any values are valid.
|
||||
/// </summary>
|
||||
/// <remarks>An invalid value can be saved, but only valid values can be published.</remarks>
|
||||
public bool IsCultureValid(string culture)
|
||||
{
|
||||
internal bool IsCultureValid(string culture)
|
||||
{
|
||||
//fixme - needs API review as this is not used apart from in tests
|
||||
|
||||
// culture-neutral is supported, validate culture-neutral
|
||||
// includes mandatory validation
|
||||
if (PropertyType.ValidateVariation(culture, null, false) && !IsValidValue(GetValue(culture)))
|
||||
|
||||
@@ -1330,7 +1330,7 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// content cannot publish values because they are invalid
|
||||
Assert.IsFalse(contentCanPublishValues);
|
||||
Assert.IsNotEmpty(content.Validate());
|
||||
Assert.IsNotEmpty(content.ValidateProperties());
|
||||
|
||||
// and therefore cannot be published,
|
||||
// because it did not have a published version at all
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
_.each(vm.variants,
|
||||
function (variant) {
|
||||
variant.compositeId = variant.language.id + "_" + (variant.segment ? variant.segment : "");
|
||||
variant.compositeId = variant.language.culture + "_" + (variant.segment ? variant.segment : "");
|
||||
variant.htmlId = "publish_variant_" + variant.compositeId;
|
||||
|
||||
//check for pristine variants
|
||||
|
||||
@@ -741,7 +741,7 @@ namespace Umbraco.Web.Editors
|
||||
if (!contentItem.PersistedContent.IsCulturePublished(lang.IsoCode))
|
||||
{
|
||||
var errMsg = Services.TextService.Localize("speechBubbles/contentReqCulturePublishError", new[] { allLangs[lang.IsoCode].CultureName });
|
||||
ModelState.AddModelError("publish_variant_" + lang.Id + "_", errMsg);
|
||||
ModelState.AddModelError("publish_variant_" + lang.IsoCode + "_", errMsg);
|
||||
canPublish = false;
|
||||
}
|
||||
}
|
||||
@@ -751,10 +751,10 @@ namespace Umbraco.Web.Editors
|
||||
//validate all other variants to be published
|
||||
foreach (var publishVariation in otherVariantsToValidate)
|
||||
{
|
||||
//validate the culture property values, we don't need to validate any invariant property values here because they will have
|
||||
//validate the content item and the culture property values, we don't need to validate any invariant property values here because they will have
|
||||
//been validated in the post.
|
||||
var invalidProperties = contentItem.PersistedContent.Validate(publishVariation.Culture);
|
||||
if (invalidProperties.Length > 0)
|
||||
var valid = contentItem.PersistedContent.IsValid(publishVariation.Culture);
|
||||
if (!valid)
|
||||
{
|
||||
var errMsg = Services.TextService.Localize("speechBubbles/contentCultureValidationError", new[] { allLangs[publishVariation.Culture].CultureName });
|
||||
ModelState.AddModelError("publish_variant_" + publishVariation.Culture + "_", errMsg);
|
||||
|
||||
Reference in New Issue
Block a user