Closed (fixed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
workspaces.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Oct 2018 at 12:51 UTC
Updated:
29 Nov 2018 at 14:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tetranz commentedI think this will do it.
Comment #3
eli-tJust tested the patch in #2 locally and it works.
Any reason this isn't just in the $items['workspace'] definition above, with #type, tab, #wrapper_attributes etc?
Comment #4
eli-tScreenshot of patch in #2 showing immediate update of toolbar:

Comment #5
tetranz commentedThanks and you're quite correct. I was about to do that first but thought it was going to override the #cache key at the top but now I see that we blow that away later.
I think it should retain the user.permissions context too.
New patch coming soon.
Comment #6
tetranz commentedComment #7
eli-tWith respect to retaining user.permissions; whilst this seems reasonable, I can't create the problem this is intended to solve. That is the patches in #2 and #6 seem to behave identically given the following steps.
The change seems reasonable but it seems to not be required unless there's a use case I'm missing?
Comment #8
tetranz commentedYeah, I went through similar steps with similar results so I was unsure whether to leave it in. I should probably remove it.
Comment #9
tetranz commentedComment #10
amateescu commented@Eli-T, regarding the testing from #7: I think that you're not seeing any behavior change because some other part of core uses the
user.permissionscontext in a render array, so it gets added to the page regardless of the (broken) implementation fromworkspaces_toolbar().As for the issue and the patch itself, great catch! :)
I think it would be better to put the new cache tag definition under
$items['workspace']['tab'](just after#attributes), and we should also fix the problem that we override the$items['workspace']item defined at the top of the function, by using$items['workspace'] += [ ....Comment #11
amateescu commentedAlso, it would be really good to add some small test coverage for this bug in
\Drupal\Tests\workspaces\Functional\WorkspaceTest.Comment #12
tetranz commentedThanks @amateescu I can do that in the next few days if nobody else does but ...
If I put the cache tags definition under tabs rather than under workspace and then append the array rather than overwrite it, what should I do with the cache contexts definition already added to workspace? Should I leave them under workspace so we'll have contexts under workspace and tags under tabs?
Comment #13
amateescu commentedYup, that's exactly what I would propose to do :)
Comment #14
tetranz commentedOkay, starting again.
This is just a test which should fail.
Comment #15
tetranz commentedThis should pass.
Comment #17
scott_euser commentedThis looks good to me! Just a couple minor, things I guess we can shorten directly into drupalPostForm() like attached patch / interdiff.
Comment #18
amateescu commentedI don't think we need to add another user to this test, we can simply add the
access toolbarpermission to the current list defined in thesetUp()method and use$this->editor1in the new test.show _the_ correct label :)
Same here, show _the_ new label.
Comment #19
dhirendra.mishra commentedi am uploading the patch which solves point 2 and point 3 from comment #18. Note point 1 is still remaining so i am not putting this under needs review status. I will work on that too soon if i get time in-between. Also someone can pick that remaining task by using my patch.Thanks.
Comment #20
tetranz commentedI had this ready to go and just noticed #19 as I refreshed the page before uploading so I just renamed it. Sorry if that's an inappropriate thing to do.
Related to this, I wonder if the permissions are correct in workspaces.module in function workspaces_toolbar().
It seems a little odd that we need both 'view own workspace' and 'view and workspace'. I wonder the intention was to need either.
Comment #21
amateescu commented@tetranz, note that the conditions are negated in
workspace_toolbar()and they are checked with||(OR), which means that a user needs either one of those three permissions, not all of them at the same time :)This test variable is not needed anymore.
We can drop these two permissions.
Comment #22
dhirendra.mishra commentedworking on it.
Comment #23
dhirendra.mishra commentedHere is the patch. Correction from #21
Comment #24
tetranz commented@amateescu Are you sure about the permissions logic? :) Maybe my brain isn't quite in gear this hour of the morning but it looks to me that:
If you don't have 'administer workspaces' or don't have 'view own workspace' or don't have 'view any workspace' then the early return happens. i.e., it's effectively an AND thanks to De Morgan. That's why I added the other user because I didn't want to pollute the other tests too much but maybe this needs to be addressed too. I think it's missing an extra outer set of parenthesis that the original author intended.
A manual test confirms that you need all three before the toolbar appears. I think @dhirendra.mishra's patch will fail because of this.
I think that logic needs to be this but ... I'm not sure if we should do that in this issue or create a separate issue.
Comment #26
amateescu commented@tetranz, I was 100% sure, and 100% wrong apparently :) I think it's fine to use the same issue to fix that as well, mostly for laziness-related reasons, but I if you want to open a new one please go ahead.
Comment #27
tetranz commentedNo problem. :)
I can't do it right now so if you want do it @dhirendra.mishra before me then that's fine too although we really should have interdiffs with your patches. Hopefully that change won't break anything else but ... I guess we'll find out.
Comment #28
dhirendra.mishra commentedok.working on it.Thanks.
Comment #29
dhirendra.mishra commentedSorry as had some problem with interdiff. Just have changed the permission logic in workspace.module file as suggested in #24.
Please find patch below.
Comment #31
scott_euser commentedWe need to only return nothing if user doesn't have any of the permissions, so !1 && !2 && !3:
Tests should now pass
Comment #32
amateescu commentedAgreed, #31 accomplishes the same goal as the snippet from #24. Looks good to me now :)
Comment #33
scott_euser commentedAh yes, missed that: same as suggested in #24
Comment #34
dhirendra.mishra commentedOh Yes..Got it.. I had missed that. Thanks @scott_euser
Comment #36
dhirendra.mishra commentedComment #37
catchCommitted and pushed 03fdd37de2 to 8.7.x and f41ff929db to 8.6.x. Thanks!