Affects D8 version only (afaik remember):

Scenario: using published or has role filter

Unselect all roles. Save the filter settings.
Without patching, get this:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))) ORDER BY node_field_data_created DESC LIMIT 11 OFFSET 0' at line 4: SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid FROM {node_field_data} node_field_data WHERE (node_field_data.status = 1 OR (node_field_data.uid = 1 AND 1 <> 0 AND 1 = 1) OR 1 = 1 OR 1 IN (SELECT ur.entity_id FROM {user__roles} ur WHERE ur.roles_target_id IN ())) ORDER BY node_field_data_created DESC LIMIT 11 OFFSET 0; Array ( )

See patch for fix.

Note, I believe this also affects the current user filter however I didn't yet think of a good default behavior for that when there are no roles selected.

See attached patch for "Published or has role" filter.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

joseph.olstad’s picture

joseph.olstad’s picture

Issue summary: View changes
albertski’s picture

Status: Needs review » Needs work

- Instead of doing a return can you just do an else statement for the other expression
- Can you update your comment to something like "If there are no roles selected, not querying on roles."

joseph.olstad’s picture

yes definately, good call, that would be a better patch.

I will spin up a new patch.

Thanks

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs work » Needs review
albertski’s picture

Status: Needs review » Needs work

Can you fix the coding standard issue:

FILE: ...blished_or_roles/src/Plugin/views/filter/PublishedOrHasRoles.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 79 | ERROR | [x] Expected newline after closing brace
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Also, can you fix the comment // No role was selected, default to this behavior. Can you change it to something like If there are no roles selected, not querying on roles. (Sorry, just not a fan of "this behavior").

joseph.olstad’s picture

albertski’s picture

Status: Needs review » Needs work

Can you fix the comment as well.

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community

I did change the comment to exactly what you suggested.

If there are no roles selected, not querying on roles.

joseph.olstad’s picture

albertski’s picture

Status: Reviewed & tested by the community » Fixed

Nice find and nice fix. Thanks!

joseph.olstad’s picture

Hi Albertski, how about tagging a release candidate ? or beta tag ? 8.x-1.0-beta1
?

The next issue is to resolve the access violation for the Current User filter, same problem that this issue has.
but I don't have a fix for that one.

joseph.olstad’s picture

Title: Prevent Syntax error or access violation when no roles selected » PublishedOrHasRoles - Prevent Syntax error or access violation when no roles selected
joseph.olstad’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.