Disallowed node titles are presents in the list when autocomplete search is performed.

Comments

dom.’s picture

Status: Active » Needs work

Hi!

Do you mean disallowed nodes because of user permissions ? If so, you can correct this using the SQL query. If you need to access an array of the roles of the current user using autocompletion, you can change:

In search_autocomplete.module:
change lign 24 to:
global $language, $user;
change lign 52 to:

$params   = array(':like_word'  => '%'.$word.'%',
                        ':roles'    => "(" . implode(",", $user->roles) . ")" );

This will offer you the :roles placeholder.

Even with this, I must confess the SQL statment will not be easy-peasy. That's why I'm working on a version to use VIEWS module to easily create the suggestions without using SQL. I hope to finish this new feature soon.

Thanks for using this module,
Regards,
Miro.

DizelGenerator’s picture

Hi Miroslav!
Thanks for your answer!

Yes, I've meant disallowed nodes because of user permissions. I've understood your idea and did some another changes for it works. In search_autocomplete.modile line 24 changes to:

global $language, $user;

To line 56 add (without checking for $query really has ':roles' placeholder it doesn't work):

      if (strpos($query, ':roles') !== false) {
        $params[':roles'] = implode(',', array_keys($user->roles));
      }

The SQL statement for using this workaround:

SELECT n.title FROM {node} n
INNER JOIN {node_access} na ON (na.nid = n.nid)
WHERE n.status = 1 AND n.title LIKE :like_word
  AND na.realm = 'nodeaccess_rid' AND (na.grant_view = 1 OR na.grant_update = 1)
  AND na.gid IN (:roles)
dom.’s picture

Status: Needs work » Fixed

Thanks a lot for sharing! I'm sure it will help others!

I will definitely improve the module to produce the JSON callback suggestions using views cause this is not easy enough for end-user.

Miro.

Status: Fixed » Closed (fixed)

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

OldAccount’s picture

I'd love to have this feature added, and making the option available via the UI is always preferred over module hacks. I'm using the Restrict Node Page View module to restrict direct access to the full node for certain content types, but you can still type in a restricted node title and see it come up in the autocomplete list.

Great module, by the way, thank you for all your work!