diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 7abaac3404..343310dd4e 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -312,10 +312,10 @@ namespace Umbraco.Core.Models public bool Blueprint { get; internal set; } /// - 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 } /// - 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 diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index 8bf57f4270..fceaba158f 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -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(); } - /// - /// Validates the content item's properties for the provided culture/segment - /// - /// - /// - /// - /// - /// This will not perform validation for properties that do not match the required ContentVariation based on the culture/segment values provided - /// - public virtual Property[] Validate(string culture = null, string segment = null) + /// + public bool IsValid(string culture = null, string segment = null) + { + var name = GetName(culture); + if (name.IsNullOrWhiteSpace()) return false; + return ValidateProperties(culture, segment).Length == 0; + } + + /// + 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(); } diff --git a/src/Umbraco.Core/Models/IContent.cs b/src/Umbraco.Core/Models/IContent.cs index fca50c328c..51cc3e42ff 100644 --- a/src/Umbraco.Core/Models/IContent.cs +++ b/src/Umbraco.Core/Models/IContent.cs @@ -169,8 +169,9 @@ namespace Umbraco.Core.Models /// The document must then be published via the content service. /// Values are not published if they are not valid. /// - //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(); /// /// Publishes values. @@ -190,8 +191,9 @@ namespace Umbraco.Core.Models /// /// The document must then be published via the content service. /// Values are not published if they are not valie. - /// - bool PublishCultureValues(string culture = null); + /// + //fixme - needs API review as this is not used apart from in tests + //bool PublishCultureValues(string culture = null); /// /// Clears all published values. diff --git a/src/Umbraco.Core/Models/IContentBase.cs b/src/Umbraco.Core/Models/IContentBase.cs index 3007eea900..e127b42fe9 100644 --- a/src/Umbraco.Core/Models/IContentBase.cs +++ b/src/Umbraco.Core/Models/IContentBase.cs @@ -108,20 +108,36 @@ namespace Umbraco.Core.Models /// Sets the (edited) value of a Property /// void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null); + + /// + /// Checks if the content and property values are valid in order to be persisted. + /// + /// + /// + /// + bool IsValid(string culture = null, string segment = null); /// - /// Gets a value indicating whether the content and all its properties values are valid. - /// - Property[] ValidateAll(); + /// Gets a value indicating if all properties values are valid. + /// + //fixme - needs API review as this is not used apart from in tests + //Property[] ValidateAllProperties(); /// - /// Gets a value indicating whether the content and its properties values are valid. + /// Validates the content item's properties for the provided culture/segment /// - Property[] Validate(string culture = null, string segment = null); + /// + /// + /// + /// + /// This will not perform validation for properties that do not match the required ContentVariation based on the culture/segment values provided + /// + Property[] ValidateProperties(string culture = null, string segment = null); /// - /// Gets a value indicating whether the content and its culture/any properties values are valid. - /// - Property[] ValidateCulture(string culture = null); + /// Gets a value indicating if the culture properties values are valid. + /// + //fixme - needs API review as this is not used apart from in tests + //Property[] ValidatePropertiesForCulture(string culture = null); } } diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 19a63925df..bb4c7f338d 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -332,11 +332,13 @@ namespace Umbraco.Core.Models } /// - /// Gets a value indicating whether everything is valid. + /// Gets a value indicating whether all properties are valid. /// /// - 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. /// /// An invalid value can be saved, but only valid values can be published. - 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))) diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index aa70b453d1..84f8773ed4 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -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 diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js index ec377c913f..cebbdea7fd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js @@ -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 diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 14d5029682..2caa64fc98 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -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);