SparkDevNetwork / Rock

An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
http://www.rockrms.com
572 stars 347 forks source link

Prevent setting Parent page to self #252

Closed azturner closed 10 years ago

azturner commented 10 years ago

Currently you can set the parent page of a page to itself (or one of it's children pages) which then makes it impossible to find the page again when administering. Need to add validation to prevent this.

nairdo commented 10 years ago

Instead of validation, @azturner says to just remove current page and all of it's children from the ParentPage page-picker.

If validation was desired, we could implement IValidatableObject on the Page model and add:

   public IEnumerable<ValidationResult> Validate( ValidationContext validationContext )
   {
      if ( ParentPageId == Id )
      {
         yield return new ValidationResult
            ( "The page cannot be its own parent", new[] { "ParentPageId", "Id" } );
      }
   }

However the current PagePicker control does not give any UI when the problem (not valid) occurs.

nairdo commented 10 years ago

@azturner, I talked with @mikepetersonccv about this issue tonight. We also discovered the same issue exists in the AccountPicker, GroupPicker, LocationPicker (quite possibly all ItemPickers) -- so he's going to take a stab at a pattern-solution.