From cdbad7795e4a13d16309d7566bece13c8ddaa908 Mon Sep 17 00:00:00 2001 From: Ryan Wawrzaszek Date: Wed, 27 Mar 2024 10:36:17 -0400 Subject: [PATCH 1/2] Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation. --- .../Drivers/ContentTypeConditionEvaluatorDriver.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs b/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs index 59fe11dd09e..79902a05a94 100644 --- a/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; @@ -43,6 +44,14 @@ public ValueTask EvaluateAsync(Condition condition) private ValueTask EvaluateAsync(ContentTypeCondition condition) { var operatorComparer = _operatorResolver.GetOperatorComparer(condition.Operation); + + // If no content types are considered and the operation is an INegateOperator, return true, + // since displaying no content type should match any negative comparision on any content type + if (!_contentTypes.Any() && condition.Operation is INegateOperator) + { + return ValueTask.FromResult(true); + } + foreach (var contentType in _contentTypes) { if (operatorComparer.Compare(condition.Operation, contentType, condition.Value)) From ba17907c324c37119f10c4b42fc16058a0bea6d4 Mon Sep 17 00:00:00 2001 From: Ryan Wawrzaszek Date: Wed, 27 Mar 2024 12:45:01 -0400 Subject: [PATCH 2/2] Adjust logic to compare condition value to empty string rather than assuming all implementations of INegateOperation should return true when no content types are considered. --- .../Drivers/ContentTypeConditionEvaluatorDriver.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs b/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs index 79902a05a94..f713809c120 100644 --- a/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Rules/Drivers/ContentTypeConditionEvaluatorDriver.cs @@ -45,11 +45,11 @@ private ValueTask EvaluateAsync(ContentTypeCondition condition) { var operatorComparer = _operatorResolver.GetOperatorComparer(condition.Operation); - // If no content types are considered and the operation is an INegateOperator, return true, - // since displaying no content type should match any negative comparision on any content type - if (!_contentTypes.Any() && condition.Operation is INegateOperator) + // If no content types are considered, use the empty string as the value to compare against, + // since we still want comparisons such as "Does Not Equal", "Does Not Start With", etc. to evaluate to true in this case. + if (!_contentTypes.Any()) { - return ValueTask.FromResult(true); + return ValueTask.FromResult(operatorComparer.Compare(condition.Operation, string.Empty, condition.Value)); } foreach (var contentType in _contentTypes)