November Happy Hour will be moved to Thursday December 5th.

Validate - ValidateError

Vote:
 

Hi guys!,

I'm trying to use a custom validation for my type SitePageData where non-adminusers won't be able to change the sortorder for pages directly under the startpage.

This seams to work, most of the time but we have incidents where 'page.Property[property].IsModified;' returns false (even tho a change has been made!).

I have a hard time to debug this because of the changing behaviour from time to time. But, I have successfully logged this.

What am I missing? (or am I doing something wrong?).

public class SitePageValidator : IValidate
	{
		IEnumerable IValidate.Validate(SitePageData instance)
		{
				if (!Utils.IsCurrentUserInAdmin())
				{
					if (instance.HasPropertyModifiedAndIsStartPageChild(MetaDataProperties.PagePeerOrder))
					{
instance.Property[MetaDataProperties.PagePeerOrder]);

						result = new[]
						{
							new ValidationError()
								{
									ErrorMessage = "Du får inte ändra sidors sorteringsindex i denna nivå.",
									PropertyName = MetaDataProperties.PagePeerOrder,
									RelatedProperties = new string[] {MetaDataProperties.PagePeerOrder},
									Severity = ValidationErrorSeverity.Error,
									ValidationType = ValidationErrorType.AttributeMatched
								}
						};

						instance.Property[MetaDataProperties.PagePeerOrder].IsModified = false;

						return result;
					}
		}
	}



		public static bool HasPropertyModifiedAndIsStartPageChild(this PageData page, string property)
		{
			if (page.ParentLink == ContentReference.StartPage)
			{
				
				bool result = page.Property[property].IsModified;
				
				return result;
			}

			return false;
		}
#113855
Nov 28, 2014 13:25
Vote:
 

Yeah, I should add that we have checked all user rights and it seems to me that this only happens, when I use the operation (drag-and-drop) directly in the treelist.

EDIT: I have now compared the sortingindex-property of a page that was not suppose to validate before/after and it was the same!. Even tho the page changed position/place in the tree and on the site.. is this an EPiServer bug?

#113856
Edited, Nov 28, 2014 13:28
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.