Problem/Motivation
Much like \Drupal\views\Plugin\views\filter\Bundle calculates the dependencies for its required bundle entities,
Drupal\user\Plugin\views\filter\Roles should calculate the user roles as part of their config depdencies.
Proposed resolution
- Implement calculateDependencies() in Roles.php
- There, load the roles, and call getConfigDependencyKey and getConfigDependencyName
- Add some test coverage to ensure that this happens.
Remaining tasks
User interface changes
API changes
Wanna help?
This issue is a follow-up for #2372855: Add content & config entity dependencies to views. There, we made all Views plugins calculate which dependencies they need. This is important when deploying a view; when it's deployed, we want to make sure that all things it needs to work correctly, actually exist. Until before that issue, we didn't check that, which could lead to broken sites.
Unfortunately, we forgot to update at least one Views plugin: Drupal\user\Plugin\views\filter\Roles.
You can look at the changes made to Bundle.php in #2372855-84: Add content & config entity dependencies to views as an example on how to update the Roles plugin: implement a calculateDependencies() method, and inject any services you need.
When that's done, please also verify that all other Views plugins do calculate their dependencies.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 2407107-interdiff-16-19.txt | 1.97 KB | jan.stoeckler |
| #19 | 2407107-19-Roles-calculateDependencies.patch | 4.32 KB | jan.stoeckler |
| #16 | 2407107-16-Roles-calculateDependencies.patch | 4.3 KB | jan.stoeckler |
Comments
Comment #1
wim leersComment #2
wim leersComment #3
dawehnerThis is a good issue for someone on a sprint during the weekend.
Comment #5
wim leersIndeed!
Comment #6
xjmThis is definitely a bug, and probably critical as the config dependencies will be missing. Since filtering a view by a role is a way of restricting access, this might also have security implications. What happens currently if you deploy a view filtered by role without that role? Is there an exception, or does the filter fail silently?
Comment #7
xjmComment #8
dawehnerThe filter itself just uses the string, so the filtering will continue to work, and so depending on the data, return nothing or the data which are in the tables with the corresponding values. We should write all filters that way, that they don't need the objects IMHO.
Comment #9
xjmThanks @dawehner!
Comment #10
wim leersI'll take this one on later today, unless somebody beats me to it (@dawehner, if you're already on it, let me know).
Comment #11
dawehner@Wim Leers
I was planning to give this to someone on a sprint. This is a task a lot of people, with some instructions, can work one.
This has the advantage that the person might also be able to go through all the other handlers checking whether we missed some.
Comment #12
wim leersFair point; added instructions instead, tagged for the sprint.
Comment #13
dawehnerThat is helpful, thank you for updating the IS wim.
Comment #14
jan.stoecklerI'll try this one.
Comment #15
wim leersAwesome; thank you! Let me know if you're stuck, I'll try to help :)
Comment #16
jan.stoecklerOK, let's see how that goes.
Comment #17
jan.stoecklerSorry, status change.
Comment #18
wim leersAWESOME work! Thank you very much!
s/Roles/Roles object/
s/$role_entity/$role/ to make it slightly nicer? :)
Let's also add
@group views.s/Roless/Roles/
:)
THANK YOU for writing a test! :)
But the docs/function name are a bit misleading: they suggest it tests the actual filter, but it only tests the calculated dependencies. So I suggest calling it
testFilterDependencies()or something like that.Comment #19
jan.stoecklerOK, second attempt. I omitted #3 as I was told only one group should be specified. Will add the second one if absolutely essential.
Comment #20
jan.stoecklerSorry, again.
Comment #21
berdirOn, three, I agree that there should only be one @group, we can't handle more than one in Simpletest (UI) at the moment. @Wim, see my last comment in #2301481: Mark test groups as belonging to modules in UI.
Comment #22
tstoecklerYes, adding a second group would be pretty non-standard. We have a pretty clear 1-1 relationship between @group and module/component name. I'd rather not muddy those waters. Also all the test for the user views handlers also specify @user only (which proves the point), so...
Patch looks good and Wim's review is fixed and nothing major was brought up by Wim, so I feel comfortable marking this RTBC :-)
Comment #23
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 0a38107 and pushed to 8.0.x. Thanks!
I don't think that should happen in this issue. We could open an issue to do that.
Comment #25
wim leers#21/#22: that's total news to me; I've been told for a long time that I should associate all relevant
@groups. I think dawehner taught me that, and insisted on that in his patch reviews. PHPUnit supports it just fine in any case. I agree with Berdir's proposal at #2301481-13: Mark test groups as belonging to modules in UI:That's simple, consistent, logical.
Comment #26
dawehnerFor phpunit tests I totally think we should use the full power. If simpletest doesn't support that, so what.
Comment #27
wim leers#26: agreed. But just having "put the extension's name as the first
@group" does not limit PHPUnit's power :) That's what I like in Berdir's proposal: best of both worlds.