Problem/Motivation

We have a set of users that have access to the Admin Theme. Therefore, they also get access to the Admin Toolbar.

I couldn't understand why Search did not work for them but worked for me (administrator).

It turns out that users need "Administer Search", which they cannot have.
So the Search box just looks broken.

Proposed resolution

I am submitting a patch that checks if the user has the correct permission.
If not, the Search button is not added to the toolbar.

Remaining tasks

This patch needs to be reviewed.
I have tested it to my satisfaction! :)

User interface changes

The Search button and text box will not appear when this patch is applied, if the user does not have the right permission.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnaldop created an issue. See original summary.

arnaldop’s picture

adriancid’s picture

I tried the patch with an user with the 'administer site configuration' permission and is not working, are you sure this is the only permission needed?

romainj’s picture

I think that we face two different problems here:
- do we need a specific permission to use the search feature?
- to access the result page, we also need specific permission (for example the 'Administer users' to access the users overview page).

IMO we should not need to have the 'Administer site configuration' to access the search feature. In any case the result pages do have their specific permissions.

aiphes’s picture

Suscribe to this issue, not user friendly at all. Will keep an eye on this progress.

ckaotik’s picture

Status: Needs review » Needs work
Related issues: +#3090760: Move search feature to a submodule

Some feedback from my point of view:

  1. The admin_toolbar.search route should not require the administer site configuration permission, as stated by @romainj. access toolbar should do just fine, until we make the search feature its own module (see #3090760: Move search feature to a submodule).
  2. The patch is ignoring cacheability, consider adding $items['administration_search']['#cache']['contexts'][] = 'user.permissions';
  3. The access check itself could also be done using a single line of code: $items['administration_search']['#access'] = \Drupal::currentUser()->hasPermission('access toolbar'); (or whichever permission we end up using)
caspervoogt’s picture

It would actually be great to be able to remove the search from the admin toolbar. It confuses many of our site users, who think it would let them search the site's content. Perhaps this requires a separate permission rather than relying on "access toolbar" or "Administer Search". Something like "Use Toolbar Search" would make sense to me.

I know work is being done on moving search into a submodule, which would address this.

texas-bronius’s picture

I agree that 'administer site configuration' is too broad (and overly restrictive). Many users may have admin_toolbar access and not whole-site admin who could use the built-in toolbar search.

@ckaotik provides great suggestions in #6. I'd add that each $links[] = .. could be wrapped with an access check.

texas-bronius’s picture

Patch-attached:

This patch only provides the Admin Toolbar search item when the user has the new permission (provided by this patch) 'admin toolbar tools use search' "Use the toolbar search" (so namespaced to fit the module, so labeled so it fits core Toolbar nomenclature) by preventing the adding of the entire set of $items related to this search, because merely blocking access like @ckaotik cleverly proposed only blocks the parent item-- its sub elements like 'tray' and '#attached' were still added, causing a garbled-looking toolbar.

Earlier, I had also suggested $links[] = .. could be wrapped with an access check. These are under _additional_ links beyond what the clientside js already discerns from admin toolbar links from dom query (pretty clever -- so this part, at least, already has built-in access check by menu item). I don't know about these getExtraLinks() so I let it be :)

I also secured the ajax search callback endpoint /admin/admin-toolbar-search with this new user permission.

texas-bronius’s picture

Ooh -- sorry. Same comment and patch as before but includes the missing permissions yml this time.

oknate’s picture

Status: Needs review » Needs work

I don't think we should list the module 'admin toolbar tools' in the permission, as we're considering moving the search feature to its own submodule:

--- a/admin_toolbar_tools/admin_toolbar_tools.routing.yml
+++ b/admin_toolbar_tools/admin_toolbar_tools.routing.yml
@@ -93,4 +93,4 @@ admin_toolbar.search:
   defaults:
     _controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::search'
   requirements:
-    _permission: 'administer site configuration'
+    _permission: 'admin toolbar tools use search'
texas-bronius’s picture

Yep, I gave that consideration: If and when that occurs, things like this will need to be updated at that time-- if it's imminent, ok, please advise what that new submodule's name will be and we could crowbar it in with this commit. Not knowing that issue's real status, it made sense to me to stick to Drupal naming convention with this modest contribution.

oknate’s picture

Status: Needs work » Needs review
FileSize
4.92 KB

Updated patch + test coverage. Lots of good points in #6.

Liliplanet’s picture

Sorry to highjack, but the menu item ‘Manage’ should also be removed for non-admin roles :)

oknate’s picture

@liliplanet, please open a separate issue for this.

adriancid’s picture

Hi @oknate, do you think we need to update the patch now that #3090760: Move search feature to a submodule was committed?

oknate’s picture

Status: Needs review » Needs work

The last submitted patch, 17: 3091968-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

oknate’s picture

Status: Needs work » Needs review
FileSize
5.78 KB
641 bytes

Oops, fixing the other test.

oknate’s picture

I think this is good to go, if someone can review it.

  • adriancid committed 9a7cc0f on 8.x-2.x authored by oknate
    Issue #3091968 by oknate, texas-bronius, arnaldop, adriancid, romainj,...
adriancid’s picture

Status: Needs review » Fixed

Merci ;-)

adriancid’s picture

#3117860: Add a permission to the Manage menu to discuss about the permission for the Manage menu item

Status: Fixed » Closed (fixed)

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

adriancid’s picture

texas-bronius’s picture

Hello, closed issue. Is it something I'm doing wrong that with the latest release (which includes this patch), I see Search for an unprivileged user (unexpected), but it's unusable (as expected)?
search still shows
and
search still shows
It was with this observation that I advocated for my #10 (#9 desc) patch. It might be my theme or structure-sync'd menu. Just wanted to float it by anyone else who might see what I see or can advise on what's going on.
Disabling the new admin_toolbar_search module removes it cleanly.

treevis’s picture

We're seeing the same issue as @texas-bronius where when the permission is not granted, the search elements still appear and in a broken state. Should a new issue be created since this issue is closed and released?

adriancid’s picture

Hi, @texas-bronius yes, open a new issue using the Issue Summary Template and add the steps to reproduce the issue.