1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using Examine ;
5+ using Umbraco . Cms . Core ;
46using Umbraco . Cms . Infrastructure . Examine ;
57using Umbraco . Extensions ;
68
@@ -10,15 +12,31 @@ public class PdfValueSetValidator : ValueSetValidator
1012 {
1113 public int ? ParentId { get ; }
1214
15+ public bool PublishedValuesOnly { get ; }
16+
1317 private const string PathKey = "path" ;
1418
15- public PdfValueSetValidator ( int ? parentId ,
16- IEnumerable < string > includeItemTypes = null , IEnumerable < string > excludeItemTypes = null )
19+ [ Obsolete ( "Please use the constructor taking all parameters. This constructor will be removed in a future version." ) ]
20+ public PdfValueSetValidator (
21+ int ? parentId ,
22+ IEnumerable < string > includeItemTypes = null ,
23+ IEnumerable < string > excludeItemTypes = null )
24+ : this ( parentId , false , includeItemTypes , excludeItemTypes )
25+ {
26+ }
27+
28+ public PdfValueSetValidator (
29+ int ? parentId ,
30+ bool publishedValuesOnly ,
31+ IEnumerable < string > includeItemTypes = null ,
32+ IEnumerable < string > excludeItemTypes = null )
1733 : base ( includeItemTypes , excludeItemTypes , null , null )
1834 {
1935 ParentId = parentId ;
36+ PublishedValuesOnly = publishedValuesOnly ;
2037 }
2138
39+ // TODO (next major): make this method private
2240 public bool ValidatePath ( string path )
2341 {
2442 //check if this document is a descendent of the parent
@@ -33,6 +51,24 @@ public bool ValidatePath(string path)
3351 return true ;
3452 }
3553
54+ private bool ValidateRecycleBin ( string path , string category )
55+ {
56+ var recycleBinId = category == IndexTypes . Content
57+ ? Constants . System . RecycleBinContentString
58+ : Constants . System . RecycleBinMediaString ;
59+
60+ //check for recycle bin
61+ if ( PublishedValuesOnly )
62+ {
63+ if ( path . Contains ( string . Concat ( "," , recycleBinId , "," ) ) )
64+ {
65+ return false ;
66+ }
67+ }
68+
69+ return true ;
70+ }
71+
3672 public override ValueSetValidationResult Validate ( ValueSet valueSet )
3773 {
3874 var baseValidate = base . Validate ( valueSet ) ;
@@ -53,7 +89,7 @@ public override ValueSetValidationResult Validate(ValueSet valueSet)
5389
5490 var filteredValues = valueSet . Values . ToDictionary ( x => x . Key , x => x . Value . ToList ( ) ) ;
5591
56- bool isFiltered = ! ValidatePath ( path ) ;
92+ bool isFiltered = ! ValidatePath ( path ) || ! ValidateRecycleBin ( path ! , valueSet . Category ) ;
5793
5894 var filteredValueSet = new ValueSet ( valueSet . Id , valueSet . Category , valueSet . ItemType , filteredValues . ToDictionary ( x => x . Key , x => ( IEnumerable < object > ) x . Value ) ) ;
5995 return new ValueSetValidationResult ( isFiltered ? ValueSetValidationStatus . Filtered : ValueSetValidationStatus . Valid , filteredValueSet ) ;
0 commit comments