File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed
settings_tray/tests/src/FunctionalJavascript Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ protected function setUp() {
3030
3131 $ user = $ this ->createUser ([
3232 'administer blocks ' ,
33+ 'access administration pages ' ,
3334 'access contextual links ' ,
3435 'access toolbar ' ,
3536 'administer nodes ' ,
Original file line number Diff line number Diff line change @@ -394,6 +394,23 @@ public function testExternalLink() {
394394 $ this ->assertRaw ('title="External URL & escaped" ' );
395395 }
396396
397+ /**
398+ * Tests that there is no Manage tab in the Toolbar for authenticated users.
399+ *
400+ * The authorized user should not have a Manage tab simply with the 'access
401+ * toolbar' permission. They need 'access administration pages' for that.
402+ */
403+ public function testEmptyMenuTray () {
404+ // Log out the admin user because we're testing restricted access.
405+ $ this ->drupalLogout ();
406+ $ this ->drupalLogin ($ this ->drupalCreateUser (['access toolbar ' ]));
407+ $ this ->assertResponse (200 );
408+ // @todo The toolbar div itself still has the id "toolbar-administration".
409+ // @see https://www.drupal.org/project/drupal/issues/1044090
410+ $ this ->assertSession ()->elementExists ('css ' , 'div[id=toolbar-administration] ' );
411+ $ this ->assertSession ()->elementNotExists ('css ' , 'a[id=toolbar-item-administration] ' );
412+ }
413+
397414 /**
398415 * Get the hash value from the admin menu subtrees route path.
399416 *
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ class ToolbarIntegrationTest extends WebDriverTestBase {
2222 public function testToolbarToggling () {
2323 $ admin_user = $ this ->drupalCreateUser ([
2424 'access toolbar ' ,
25+ 'access administration pages ' ,
2526 'administer site configuration ' ,
2627 'access content overview ' ,
2728 ]);
Original file line number Diff line number Diff line change @@ -159,6 +159,18 @@ function toolbar_toolbar() {
159159 '#weight' => -20,
160160 ];
161161
162+ // If the current user cannot access administration pages, we can save a large
163+ // amount of unnecessary work by ending here. It'd be better to actually know
164+ // if the admin menu tree is empty for them, but trying to load that tree only
165+ // happens in a #pre_render callback, and at that point, it's too late. The
166+ // entire toolbar is rendered with the 'user.permissions' #cache context, so
167+ // we can safely do this here and it'll still be cached correctly.
168+ // @see toolbar_prerender_toolbar_administration_tray()
169+ // @see toolbar_page_top()
170+ if (!\Drupal::currentUser()->hasPermission('access administration pages')) {
171+ return $items;
172+ }
173+
162174 // To conserve bandwidth, we only include the top-level links in the HTML.
163175 // The subtrees are fetched through a JSONP script that is generated at the
164176 // toolbar_subtrees route. We provide the JavaScript requesting that JSONP
You can’t perform that action at this time.
0 commit comments