Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address. Fixes #15452. #15602

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
Expand Down Expand Up @@ -43,6 +44,14 @@ public ValueTask<bool> EvaluateAsync(Condition condition)
private ValueTask<bool> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// since displaying no content type should match any negative comparision on any content type
// since displaying no content type should match any negative comparison on any content type

if (!_contentTypes.Any() && condition.Operation is INegateOperator)
{
return ValueTask.FromResult(true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can say that this will be correct for all INegateOperator implementations (the current built-in ones, yes, but this isn't necessarily future-proof and appropriate for third-party implementations). How about running operatorComparer with an empty string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought about that. I was originally thinking I only wanted to do that for negative comparisons, but you're right, that should return the expected result (false) for the other comparisons as well. I'll go ahead and make that change.


foreach (var contentType in _contentTypes)
{
if (operatorComparer.Compare(condition.Operation, contentType, condition.Value))
Expand Down
Loading