1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using Examine ;
5
+ using Umbraco . Cms . Core ;
4
6
using Umbraco . Cms . Infrastructure . Examine ;
5
7
using Umbraco . Extensions ;
6
8
@@ -10,15 +12,31 @@ public class PdfValueSetValidator : ValueSetValidator
10
12
{
11
13
public int ? ParentId { get ; }
12
14
15
+ public bool PublishedValuesOnly { get ; }
16
+
13
17
private const string PathKey = "path" ;
14
18
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 )
17
33
: base ( includeItemTypes , excludeItemTypes , null , null )
18
34
{
19
35
ParentId = parentId ;
36
+ PublishedValuesOnly = publishedValuesOnly ;
20
37
}
21
38
39
+ // TODO (next major): make this method private
22
40
public bool ValidatePath ( string path )
23
41
{
24
42
//check if this document is a descendent of the parent
@@ -33,6 +51,24 @@ public bool ValidatePath(string path)
33
51
return true ;
34
52
}
35
53
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
+
36
72
public override ValueSetValidationResult Validate ( ValueSet valueSet )
37
73
{
38
74
var baseValidate = base . Validate ( valueSet ) ;
@@ -53,7 +89,7 @@ public override ValueSetValidationResult Validate(ValueSet valueSet)
53
89
54
90
var filteredValues = valueSet . Values . ToDictionary ( x => x . Key , x => x . Value . ToList ( ) ) ;
55
91
56
- bool isFiltered = ! ValidatePath ( path ) ;
92
+ bool isFiltered = ! ValidatePath ( path ) || ! ValidateRecycleBin ( path ! , valueSet . Category ) ;
57
93
58
94
var filteredValueSet = new ValueSet ( valueSet . Id , valueSet . Category , valueSet . ItemType , filteredValues . ToDictionary ( x => x . Key , x => ( IEnumerable < object > ) x . Value ) ) ;
59
95
return new ValueSetValidationResult ( isFiltered ? ValueSetValidationStatus . Filtered : ValueSetValidationStatus . Valid , filteredValueSet ) ;
0 commit comments