Problem/Motivation

Remember the page you were on and take you back there when switching Workspaces.

Proposed resolution

- Set a destination query string for the workspace button in hook_toolbar in workspace.module
- Set a destination query string for the workspace activate form in WorkspaceListBuilder
- Remove the redirect from \Drupal\workspace\Form\WorkspaceActivateForm::submitForm
- Find a way to bypass the caching of the link in hook_toolbar

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#41 2984938-41.patch5.77 KBamateescu
#40 2984938-40.patch8.3 KBamateescu
#35 2984938-35.patch16.51 KBjeqq
#35 interdiff.txt785 bytesjeqq
#34 2984938-34.patch16.52 KBjeqq
#34 interdiff.txt978 bytesjeqq
#31 interdiff-31.txt4.31 KBamateescu
#31 2984938-31.patch16.18 KBamateescu
#25 2984938-25.patch16.35 KBvijaycs85
#25 2984938-25-test-only.patch13.06 KBvijaycs85
#25 2984938-diff-23-25.txt511 bytesvijaycs85
#23 2984938-23.patch15.85 KBvijaycs85
#23 2984938-diff-19-23.txt18.14 KBvijaycs85
#19 2984938-19.patch12.41 KBvijaycs85
#19 2984938-19-test-only.patch9.48 KBvijaycs85
#19 2984938-diff-17-19.txt2.25 KBvijaycs85
#17 2984938-17-test-only.patch9.06 KBvijaycs85
#17 2984938-17.patch12 KBvijaycs85
#17 2984938-diff-14-17.txt1.8 KBvijaycs85
#14 2984938-14.patch11.86 KBvijaycs85
#14 2984938-diff-11-14.txt10.92 KBvijaycs85
#14 2984938-14-test-only.patch8.92 KBvijaycs85
#11 2984938-11.png149.32 KBvijaycs85
#11 2984938-11-test-only.patch3.53 KBvijaycs85
#11 2984938-11.patch6.38 KBvijaycs85
#6 2984938-6-test-only.patch3.54 KBvijaycs85
#6 2984938-6.patch6.37 KBvijaycs85
#3 2984938-3.patch2.83 KBvijaycs85
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

timmillwood created an issue. See original summary.

Wim Leers’s picture

Issue tags: +Usability

I was very confused by this indeed.

Let me know if you need help with

- Find a way to bypass the caching of the link in hook_toolbar

vijaycs85’s picture

Status: Active » Needs review
FileSize
2.83 KB

Here is an initial working patch. One note is, the cache context never used because the $item array was missing +

@@ -162,12 +163,12 @@ function workspace_toolbar() {
   /** @var \Drupal\workspace\WorkspaceInterface $active_workspace */
   $active_workspace = \Drupal::service('workspace.manager')->getActiveWorkspace();

-  $items['workspace'] = [
+  $items['workspace'] += [
amateescu’s picture

Tested #3 manually and it's working great!

timmillwood’s picture

Issue tags: +Needs tests

I can't believe in #2949991-39: Add workspace UI in top dialog I was just missing that +.

It looks as though the missing + dates back to the original commit, so only if the user doesn't have one of the permissions the cache context is added.

I guess we needs tests now for the missing + bug fix, and the user redirect.

vijaycs85’s picture

Adding tests (test-only file is inter-diff)...

The last submitted patch, 6: 2984938-6.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: 2984938-6-test-only.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Gábor Hojtsy’s picture

Component: workspace.module » workspaces.module

Fix component following module rename.

vijaycs85’s picture

updated patch for the change in #10.

Not sure why it's failing on toolbar visibility but both test cases are green locally.

Turns out we found a bug (#2987956: Entity queries with sorting and ordering are not working in a non-default workspace) as part of the tests here.

The last submitted patch, 11: 2984938-11.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 11: 2984938-11-test-only.patch, failed testing. View results

vijaycs85’s picture

1. We are not getting user.permissions context because toolbar has content specific to the user (i.e. username) which is more granular. reference from docs:

Drupal automatically uses the hierarchy information to simplify cache contexts as much as possible. For example, when one part of the page is varied per user (user cache context) and another part of the page is varied per permissions (user.permissions cache context), then it doesn't make sense to vary the final result (e.g.: the page) per permissions, since varying per user is already more granular.
In other words: optimize([user, user.permissions]) = [user].

2. I believe test failure because of width wasn't set.

3. Added some access tests.

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

Status: Needs review » Needs work

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

vijaycs85’s picture

Status: Needs review » Needs work

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

vijaycs85’s picture

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

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Awesome work on this @vijaycs85!

amateescu’s picture

Status: Reviewed & tested by the community » Needs work

The off-canvas test looks really good to me. Here's a review for the other parts:

  1. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceAccessTest.php
    @@ -0,0 +1,188 @@
    +  public function testWorkspaceAccess() {
    

    This method seems to assert only cache contexts, so not really "access" parts. Can we move all the cache context assertions to the existing WorkspacePermissionsTest test?

  2. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceAccessTest.php
    @@ -0,0 +1,188 @@
    +  public function testWorkspaceToolbarAccess() {
    

    I'm not sure what exactly is being tested here, that a hook_toolbar() implementation forces a user cache context on every page?

    If so, \Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testToolbarCacheContextsCaller() already provides test coverage for that, so I think we can remove this test class altogether :)

  3. +++ b/core/modules/workspaces/tests/src/FunctionalJavascript/WorkspaceToolbarIntegrationTest.php
    @@ -0,0 +1,86 @@
    +      'access content overview',
    

    Is this permission really needed?

  4. +++ b/core/modules/workspaces/tests/src/FunctionalJavascript/WorkspaceToolbarIntegrationTest.php
    @@ -0,0 +1,86 @@
    +    // Make sure stay on same page after switch.
    

    Missing a 'we' between 'sure' and 'stay' :P

  5. +++ b/core/modules/workspaces/workspaces.module
    @@ -144,13 +145,6 @@ function workspaces_cron() {
    -  $items['workspace'] = [
    -    '#cache' => [
    -      'contexts' => [
    -        'user.permissions',
    -      ],
    -    ],
    -  ];
    

    I don't think this should be removed, our hook_toolbar() implementation still depends on the user's permissions, and the fact that other implementations like shortcut_toolbar() add the more generic user context should not affect us in any way.

vijaycs85’s picture

Status: Needs work » Needs review
FileSize
18.14 KB
15.85 KB

Thanks for the review @timmillwood & @amateescu. Here is an update for #22

#22.1 - Moved
#22.2 - Removed
#22.3 - Removed
#22.4 - Fixed
#22.5 - Added back. but the "user" context is granular and "user.permissions" is generic. However, I see there is no harm in having it.

Status: Needs review » Needs work

The last submitted patch, 23: 2984938-23.patch, failed testing. View results

vijaycs85’s picture

Status: Needs work » Needs review
FileSize
511 bytes
13.06 KB
16.35 KB
amateescu’s picture

+++ b/core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php
@@ -161,16 +170,19 @@ public function testDeleteOwnWorkspace() {
     $this->drupalGet("/admin/config/workflow/workspaces/manage/{$packers->id()}/delete");
...
+    $this->assertCacheContext('user');
...
     $this->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/delete");
...
+    $this->assertCacheContext('user.permissions');

These cache context are different even though we are basically visiting the same page, so I wonder what exactly are we testing with them?

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

vijaycs85’s picture

+++ b/core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php
@@ -161,16 +170,19 @@ public function testDeleteOwnWorkspace() {
     $this->drupalGet("/admin/config/workflow/workspaces/manage/{$packers->id()}/delete");
...
+    $this->assertCacheContext('user');
+    $assert_session->statusCodeEquals(200);
...
     $this->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/delete");
...
+    $this->assertCacheContext('user.permissions');
+    $assert_session->statusCodeEquals(403);

It's just matter of what's been rendered on that page. first one is 200 which renders something user specific and the second one is 404. just permission level.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Got it! I don't have anything else to complain about, great work :)

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/workspaces/tests/src/FunctionalJavascript/WorkspaceToolbarIntegrationTest.php
    @@ -0,0 +1,85 @@
    +    $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
    ...
    +    $this->assertTrue($this->assertSession()->elementExists('css', '.workspaces-dialog'), 'Workspace canvas is not visible after closing.');
    ...
    +    $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
    ...
    +    $this->assertSession()->waitForElementVisible('css', '.messages--status');
    ...
    +    $this->assertSession()->responseContains('<em class="placeholder">Stage</em> is now the active workspace.');
    +    $this->assertSession()->addressEquals('admin');
    

    can we use some local variables here for assertSession() to avoid creating new objects each time?

  2. +++ b/core/modules/workspaces/workspaces.module
    @@ -162,12 +161,12 @@ function workspaces_toolbar() {
    +      '#url' => $active_workspace->toUrl('collection', ['query' => ['destination' => Url::fromRoute('<current>')->toString()]]),
    

    we should use ['query' => \Drupal::destination()->getAsArray()] here

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
16.18 KB
4.31 KB

Thanks @larowlan for the review :) Addressed #30 and back to RTBC since they were very simple changes.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: 2984938-31.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jeqq’s picture

Status: Needs work » Needs review
Issue tags: +DevDaysTransylvania, +DevDaysCluj
FileSize
978 bytes
16.52 KB

Fixed the failing test because of the more generic cache context.

jeqq’s picture

Fixed the typo.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Discussed with @jeqq and he told me that we have a test module in core specifically for removing the user item from the toolbar (toolbar_disable_user_toolbar.module), and we could've used it in our test, but he went with the approach of testing both cases for better coverage, and I agree :)

rosinegrean’s picture

Issue tags: -DevDaysCluj

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: 2984938-35.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated error in the tests for the new composer scaffold component.

amateescu’s picture

@alexpott reviewed this patch and asked why do we need all the changes to WorkspacePermissionsTest. Since this patch does not change anything related to cache context, I agree with him that those extra assertions are not really in scope of this issue.

So here's a reroll of #35 with all the changes to WorkspacePermissionsTest reverted.

amateescu’s picture

Reviewing the patch again, the changes to WorkspaceSwitcherTest and WorkspaceTestUtilities are also not in scope, so I've removed them as well.

Gábor Hojtsy’s picture

Adjusting credits.

  • Gábor Hojtsy committed c2d897e on 8.8.x
    Issue #2984938 by vijaycs85, amateescu, jeqq, timmillwood, larowlan, Wim...
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

I verified the removed test parts are indeed unrelated. The patch looks good otherwise and got reviews from @larowlan and @alexpott already.

Committed c2d897e and pushed to 8.8.x. Thanks!

Gábor Hojtsy’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Fixed » Reviewed & tested by the community

Should be merged to 8.7 once that is out of freeze.

  • Gábor Hojtsy committed e65a1fb on 8.7.x
    Issue #2984938 by vijaycs85, amateescu, jeqq, timmillwood, larowlan, Wim...
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Cherry-picked to 8.7.x! Thanks again!

Status: Fixed » Closed (fixed)

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

tom.moffett’s picture

I recently started trying out the Workspaces module since it seems like something that would be very helpful for our process. The destination that is appended to the Live/Stage URLs appears to be cached for me. So, I'll be on a page, switch my Workspace, and then taken back to some page I was on previously.

My expectation is that the destination should be correctly updated to point to the page that the user is on.

I haven't had time to dig into that to see if it's specific to my instance since it's somewhat low priority (although frustrating), but I wanted to post a comment here in case anyone else is seeing that too.

tom.moffett’s picture

Not sure if this is the best way to go about it, but it was quick and got the job done, without having to waste a lot of time debugging. I also didn't bother spending the time to get into why it wasn't working to begin with since I don't have that kind of time for the project I'm working on right now, and I just need to move forward. This worked for me. I hope it helps anyone else running into this same problem.

I implemented this hook in a custom module I have in my Drupal instance:

/**
 * Implements hook_toolbar_alter.
 */
function YOUR_MODULE_toolbar_alter(&$items) {
  $items['workspace']['tab']['#cache']['max-age'] = 0;
}

Make sure to clear your cache once after adding that hook function, and you should see it working with the proper destination being appended.