Closed (fixed)
Project:
Drupal core
Version:
8.5.x-dev
Component:
media system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Mar 2017 at 10:10 UTC
Updated:
31 Jul 2018 at 11:58 UTC
Jump to comment: Most recent, Most recent file


Comments
Comment #2
sunset_bill commentedHere's an initial patch from Drupalcon.
Crabcakes!
Comment #3
phenaproximaYAY!! Thank you, @sunset_bill, for the patch :)
This is a bit premature, but I am 100% in favour of having this functionality in core Media. I can see many potential use cases for it in complex, media-heavy sites.
It will still need tests, and we'll need to reroll it once #2831274: Bring Media entity module to core as Media module lands. This is also a somewhat lower-priority issue for the Media Initiative. So I'm postponing this for now.
Comment #4
naveenvalechaComment #5
phenaproxima#2831274: Bring Media entity module to core as Media module landed, so this is now active!
Comment #6
naveenvalechaHere's the straight reroll of the patch.
Comment #7
naveenvalechaComment #8
naveenvalechaComment #9
phenaproximaThank you, @naveenvalecha!
Let us add a newline so as not to enrage the Git gods...
"medias" should be "media items".
These permissions should use the word "media", not "content". I think this is copypasta from Node.
On top of this, we'll definitely need tests.
Comment #10
seanbFixed everything in #9. Also added tests. While working on it I saw that the permission names were not in line with what is already in core (update media vs edit node and update media vs update any media). Fixed this as well. This will probably need attention in the update path from media_entity in contrib!
I removed the permissions for revision pages from this patch. I this that's out of scope for now. Let's do that in a separate issue.
Comment #12
seanbFor some reason the 'view media' permission is not removed from the role in the test. If somebody has any ideas please let me know. Will take another stab at this later...
Comment #13
hazong commentedwill work on this issue during this week-end
Comment #14
webflo commentedWorked together with @hazong on this patch. It was an tricky issue because user_role_revoke_permissions load a new instance of the role object, but ::grantPermissions uses the already instantiated object from the very beginning of the test.
Comment #15
webflo commentedPlease give @hazong commit credit on this issue. Thanks!
Comment #16
phenaproximaEDIT: Sorry, made a mistake.
Comment #18
phenaproximaEr...the patch in #14 only has changes to MediaAccessTest, but apparently no changes to the permissions?!
Comment #19
webflo commentedThats the interdiff hehe :)
Comment #20
phenaproximaLooks great! Tons of test coverage! I have but a few minor things before it's RTBC...
If we make MediaPermissions implement ContainerInjectionInterface, we can inject the entity type manager instead :)
This should be MediaTypeInterface.
So should this.
This will need a change record of its own, but we will also need to update https://www.drupal.org/node/2863992 so that it refers to the new change record, for people porting their contrib or custom modules from Media Entity to core Media, who may need to update their permissions.
Comment #21
chr.fritschHere is a new patch, to address all the comments from #20
Comment #22
phenaproximaThe patch looks great! We just need the change records fixed up as per #20, then this is RTBC.
Comment #23
chr.fritschIn the new patch i fixed the failing tests.
I am still not sure about the assertCacheContext changes i did. Can someone please verify it.
-> "Needs review" to trigger testbot, but change records are still missing
Comment #24
phenaproximaYay, it passed! Thank you, @chr.fritsch. Kicking back for change record stuff, though... :)
Comment #25
chr.fritschI never wrote a CR before, so here is the first draft: #2895605: Introduce per-bundle permissions for media types in preparation to deprecate existing ones
Comment #26
chr.fritschComment #28
acbramley commentedThis introduces a slight problem with allowing roles to administer various specific bundles in that you lose the ability to allow that role to view unpublished media entities. This also exists now in that to view an unpublished media entity the role can also create/edit/delete it (since it's tied exclusively to the administer media permission) but it's slightly less obvious since it's fairly standard to just grant the administer media permission anyway since all CRUD operations are common place for an editor role on media.
There's a few options to tackle this:
1) Adding a single "view unpublished media" permission
2) Adding a "view own unpublished media" (similar to what node does)
3) Adding "view unpublished {bundle} media" permissions
I'm not sure if this should be done here, or in a follow up issue but just some food for thought :)
Comment #29
phenaproximaRegarding #28: Good points, but I think we should defer all that to a follow-up issue. Will you open that?
The patch looks good at a glance, but, now that Media is stable, I think this will need an update path. So unfortunately I have to kick this one back yet again...
Comment #30
chr.fritschHere comes the update hook. The update path tests are still missing. I never wrote one. Have to take a look
Comment #32
chr.fritschHere comes a first draft of update hook test. Doesn't work locally for me, but i guess it's a problem with my machine.
Comment #34
chr.fritschThat should be appliable
Comment #36
phenaproximaFamous last words coming from me, but this oughta fix the tests :) Turns out the fixture was missing a few tables.
No interdiff because it's like 60KB, 99% of which is changes to the fixture. Sorry!
Comment #37
phenaproximaAdded a bit of code to revoke the old, defunct permissions.
Comment #38
vijaycs85Manually tested the patch and it looks good overall. Few questions/notes:
1. Missing Revision related permissions (e.g. Delete revisions) per bundle.
2. Is it worth having a base permission class/trait to have common functionality abstracted from NodePermission and MediaPermission?
3. Created #2911421: Add per-bundle permission system to core part of reviewing this issue.
4. Revoked "create media" permission with bundle specific on update_N and we are trying to test here with "create media"?
Not sure if those needs work. So leaving it needs review for now.
Comment #39
chr.fritsch1:
Since media is revisonable, we should also add revsion related permission
2:
Because MediaPermissions and NodePermissions are looking more or less the same, we could introduce some base class. But that could be done in a followup
4:
That should be removed, because the permission stays as it is
Comment #40
chr.fritschTalked with @vijaycs85 about 1. and we agreed that we should remove the "edit own media", "edit any media", "delete own media", "delete any media" and "create media" permissions, because we have them all as bundle permissions. Then we are on the same track as node. Also we will leave the revisions stuff out, because we currently don't have any UI for revisions support. That should all be done in a follow-up.
Comment #41
chr.fritschTalked to @seanB and he also agreed on #40. So here comes the patch
Comment #42
phenaproximaTagging per #40.
Comment #43
chr.fritschComment #44
vijaycs85Patch in #41 looks good. +1 to RTBC!
Comment #45
vijaycs85Comment #46
vijaycs85@chr.fritsch we might need to update the contentEntity definition as well?
Comment #47
vijaycs85Comment #48
chr.fritschNice catch
Comment #49
vijaycs85Interdiff looks good. +1 to RTBC.
Comment #50
vijaycs85Comment #51
larowlanAdding new permissions needs OK from product manager.
Can we get a screenshot of the permissions page showing the permissions?
Thanks
Comment #52
phenaproximaComment #53
vijaycs85Updated issue summary with screenshot.
Comment #54
xjmThanks for the screenshots.
For issues where we add permissions, we want to (a) decide whether the permission is an 80% permission that belongs in core, versus something that can be provided by contrib for sites that need more granularity, and (b) make sure that the permission list is manageable.
So those screenshots are what it's like with the default core media types out of the box. How many different media types are on a typical site? What's an example scenario where per-media type permissions are needed?
Also, this issue recommends for per-media type permissions. However, my assumption would have been that the permissions would be per source, rather than per media type. With a typical site, would we end up with a huge list of both kinds of permissions?
Generally with issues like this the product team would like to have them get usability signoff, rather than the product team which acts at a more strategic level (like whether we will add a given module at all, or what its MVP is). So switching to "Needs usability review".
Thanks!
Comment #55
seanbMost sites I have worked on have max 5 or 6 media types, while most probably only have file, image and video. I think this will probably not lead to a huge list of extra permissions.
In my experience, permissions are more useful on a type level than on a source level, for instance, a site having multiple file types. Some editors can maintain only 'official' documents, like company policies etc, while others can maintain more generic documents like random route.pdf files for an event or whatever. This is something that comes up a lot.
Hope this helps :)
Comment #56
phenaproximaHaving permissions at the source level makes zero sense to me, architecturally speaking.
The source is almost entirely under the hood. It is only exposed to site builders, when creating or editing media types. It is an intrinsic part of each media type, but it doesn't really affect the authoring experience. Authors will not generally even be aware of them. They are API-level, not UI-level. Therefore, we should not entangle the source plugins with permissions. Not only do I believe it would be extremely confusing to users, I think it would introduce a substantial amount of weirdness to the Media API. So I would strongly oppose such an idea.
+1 to @seanB's estimate that most sites will have 5-6 media types. Some sites will have more, others will have less, but I envision 5-6 as being the 90% case.
It is also worth mentioning that the current permissions in the Media module are way too broad. If we don't have per-bundle permissions in core, I guarantee this issue will be reopened. Putting it in contrib will only serve to inconvenience people. Media types are more analogous to node types than any other bundle entity type in core, and we have per-type permissions for node types.
So although it will make the Permissions page even more crowded (which is a legitimate UX problem, but well out of Media's scope), we will be doing our users a favor by having Media's permissions act consistently with the behavior people already expect from node types.
Comment #57
yoroy commentedI think we're clear on not doing this on the source level. The main question is whether to do this at all (vs. keeping the existing 1 set of permissions that applies to all media types).
My initial response is that we should follow indeed the model we have for content types and have separate permissions per media type. So that Role X can create Cat media and Role Y can create Dog media and Role Z can create Cat and Dog media. Or: authenticated users can create Review Image media to use in their review of the product they bought. Only editors can create the Official Product Image media.
I also think we're already beyond the point of a manageable permissions page. We do have to eventually focus on improving the permissions page situation. And while it's not necessarily up to Media to fix this, given the estimated 5 or 6 Media types does result in 25-30 additional rows of checkboxes, which is a pretty damn big addition. (How many types do we plan to ship with default core?)
Consider this a still undecided-but-leaning-towards-core-adding-the-per-type-permissions :)
Comment #58
phenaproximaRight now, I think the goal is to ship three media types with Standard. We already include File and Image, and once #2831944: Implement media source plugin for remote video via oEmbed lands, another one for remote video will be included.
I'd like to add another reason why we should do this now, rather than later (because, as I said, it will be requested): it is much easier to migrate the permissions now, when fewer people are using Media, than later, when thousands of people may be using it in ways we hadn't anticipated. The future maintenance burden is far lower if we do this now, and that's gotta count for something :)
Maybe this could be the issue that catalyzes a rebuild/redesign of the Permissions page. ;)
Comment #59
chr.fritschI totally agree with phenaproxima and seanB. In Thunder for example we ship with 6 different media types and I think we cover the majority of use-cases.
That this would flood the permissions page is out of scope. So I added #1765576: Redesign the permissions page as a related issue.
Comment #60
yoroy commentedIt's not really out of scope if this patch introduces the actual flooding, no? We're not adding "just" a single row of checkboxes.
3 Media types introduces 15 additional rows of checkboxes. I enabled every core module and count about 150 rows of checkboxes. So a 10 percent increase in that case, even more with only Standard profile modules enabled. If this was a performance decrease, no way would we let this happen. And in fact it is a performance decrease because people will spend that much more time finding what they need on the permissions page.
I know it's not fair to block this on a system page that has had a broken model for years, but doing nothing about it and just keep adding (a lot of) stuff is not a viable strategy either.
Comment #61
larowlanFor block content we proposed (still not fixed) #1975064: Add more granular block content permissions that there was a checkbox on the type form that said 'expose additional permissions' or something to that effect.
If that was checked, then separate permissions would exist and be used, if not, it would just use a base set.
We proposed the same for comment module too #1903138: Move global comment permissions to comment-type level
Maybe its something we should seriously explore.
Node is part of the problem too, it has so many by default.
I note that Node already has a permission handler, perhaps we need a base permission handler for bundleable entities where the bundles come from a config entity. This base handler would provide this function by default.
Then media, block_content and comment could use it. And with time, node could too.
Thoughts?
Comment #62
larowlanLink direct to that discussion - https://www.drupal.org/node/1975064#comment-11372113
Screenshot of potential UI proposed from @yoroy
Comment #63
larowlanI think having the permissions on the bundle form is a future enhancement.
I'm proposing that checking 'custom permissions' makes those permissions exist on the permissions page.
Unchecking it means the default global permissions for media/node/comment/block content/et al are used.
Comment #64
seanbTo be fair, we remove 5 permissions as well. So it's more like a 6% increase. But I see your point.
I like the solution proposed in #61. I don't think this should be blocked on that though. I also don't think that not adding these permissions, or the solution in #61 are the actual solution to the permissions page performance. The performance mostly becomes an issue when you start installing contrib modules and add a bunch of roles. Choosing not to add these media permissions will not change that.
Comment #65
phenaproximaI think #61, although it would be a new pattern in core, is a good and cool idea. However, I can imagine a fair bit of complexity arising in the implementation.
Another, simpler compromise might be to introduce per-bundle permissions now, but fewer of them. So rather than "edit own", "delete any", etc. for each media type, we'd simply have three permissions per type: create, edit, delete. This would still provide site builders with a reasonable level of flexibility, without choking the permissions page. We could add more granular (own/any) permissions in a follow-up issue once the UX problems have been ironed out, and although there would be a migration path involved, it would not be as complicated.
Comment #66
chr.fritschI wouldn't add just add the half of them. Maybe it's best to go with something like #61, because this 5 permissions are still not the end. We are currently completely missing the revisions support. #2887106: Add generic base classes for content entity revisions would probably introduce 'view all revisions', 'revert all revisions' and 'delete all revisions'.
Comment #67
Bojhan commentedYoroy has provided a review.
Comment #68
seanbThe permissions page issue is #1765576: Redesign the permissions page. That will probably take a while, but I think it is the actual place to solve the performance of the permissions page (EDIT: I see the permissions page issue was linked already, sorry about that!).
After thinking about #61 a bit more I think "hiding" the extra permissions on the media type form will probably be confusing. Especially since node/taxonomy don't work like this. Adding that this doesn't actually solve the performance issue of the permissions page, I would suggest that hiding the permissions should be a contrib module instead of the other way around. And when doing this, it should probably add the feature of hiding permissions for node/taxonomy as well.
Comment #69
yoroy commented#64: I totally expected to get corrected on my math :-)
Thought about this a bit more. We should just add the extra permissions. I wanted to stress that we need to get serious about finding a better model for the permissions UI but that should in itself not block this issue from going in. It would be better to have these more fine grained permissions directly in core from the start then having to add them later.
Comment #70
yoroy commentedI opened #2919636: Design a better model for managing permissions in the ideas queue. Carry on in here!
Comment #71
chr.fritschJust a reroll.
Comment #73
bdimaggioTrying to fix those test failures.
Comment #75
bdimaggioIf I'm reading those new test failures right, they're happening for reasons outside the scope of this patch, right?
Comment #76
bdimaggioOK, after much conversation with phenaproxima, I'm documenting where I'm stuck on this issue.
The final failing test is failing because MediaUpdateTest::testBundlePermission() calls $this->runUpdates(), which defaults to its parent class's method, i.e. UpdatePathBaseTest::runUpdates(). We see the test failure in that method, specifically here:
However, that obscures the real problem. If you comment that line out and re-run the test, you get a more useful failure:
When I chased this down to EntityDefinitionUpdateManager::getChangeList() and xdebugged that method, I found that it thought that both field_media_file and field_media_image had been deleted. Corroborating this was the fact that my test's database and my functioning D8 media site looked different as you see in the images. (That is, there's no evidence in the test database that those two fields exist.)
So, I'm stumped. Can anybody suggest reasons why, in the test, those fields would either have been deleted, or never been installed?
Comment #77
chr.fritschI think the problem is #2883813: Move File/Image media type into Standard once Media is stable. In drupal-8.media-enabled.php we try to load configuration form media/config/install. The files are not there anymore, because they were move into standard profile.
So maybe we should base drupal-8.media-enabled.php on media_test_type configuration.
Comment #78
chr.fritschI thought a bit more about it and i think it's better to load the files form the standard profile. Now drupal-8.media-enabled.php does what it's name supposed to be. It enables media module like it would be in standard profile.
Comment #79
phenaproximaLooks quite good. Only two nits, but neither should block RTBC. I'm not qualified, because I've worked on the patch too recently, but I see no reason not to proceed.
Nit: $entityTypeManager should be snake_case, not camelCase.
Nit: This comment is superfluous. :)
Comment #80
chr.fritschFixed the nits
Comment #81
eclipsegc commentedAll seems super obvious and straight forward. RTBC
Eclipse
Comment #82
yoroy commentedIs there a way to manually test this and verify through the UI that it works as intended?
Comment #83
chr.fritschCreate multiple roles and grant them access to different operations per media type. Then create some users with a role and test if you are able to execute the operations
Comment #84
yoroy commentedRight, but how to create media types in core? There's no media module to enable etc.
Comment #85
chr.fritschdrush en mediaor remove the hidden key from media.info.yml file. With enabling media module you will get a file and a image type.Hopefully that helps.
Comment #86
yoroy commentedSee, it's not that obvious :-) Yes, that does help, thanks for the instructions. I applied the patch locally and yes, the permissions are there:
Seems like the necessary follow-ups are in place as well. There's still a "needs change record updates" tag though, has that been taken care of? I see there's https://www.drupal.org/node/2895605, but can't tell if it correctly reflects discussion in #20, #21.
Comment #87
chr.fritschI opened #2923347: Migrate generic media permissions to per-type permissions as a follow-up for the media_entity upgrade path.
Comment #88
xjmI read over all the discussion since my last review. I still have some hesitations about the expanded number of permissions (by 5-10% or whatever) but @yoroy has signed off so I'll follow his recommendation. The per-bundle permissions do seem more integral to the bundle than for comments or block types, and the various usecases illustrating why they're useful also make a good case for why we want these permissions in core.
These hunks are all out of scope.
Thinking about it, this is a BC break. I agree with not showing these permissions in the UI when we have the per-bundle varieties, but we need to not break BC for anything that might already be checking for them
I filed #2924785: Provide a mechanism to deprecate permissions to provide a way to deprecate permissions. I'd suggest just removing this hunk from the patch, adding a
@todo, and addressing the deprecation in a followup (even though it will add five more permissions than needed until they can be deprecated).Comment #89
phenaproximaOkay, that all sounds good to me. The loss of permissions does represent a BC break, despite the presence of an update path, so let's open a follow-up to deprecate the old permissions (which we can postpone on #2924785: Provide a mechanism to deprecate permissions), fix up media.permissions.yml, and then I think we are back to RTBC.
Comment #90
chr.fritschOkay, i brought the old permissions back. I also removed the revocation of the old permissions. This will be done in #2925459: Deprecate generic media permissions, which i created as a follow-up.
Comment #91
phenaproximaI think we are good to go here. All of @xjm's comments have been addressed, all follow-ups are filed, and all T's are dotted and I's are crossed :) Let's do this.
Comment #92
xjmMinor issue here -- I think the "View media" permission is not going to be removed, right? So the @todo should be after it, or it should say something like "Deprecate some permissions in..."
Also, do we have a followup yet for the proposal to provide a UI and API pattern for per-bundle permissions? I don't think that's covered by #1765576: Redesign the permissions page or #2919636: Design a better model for managing permissions which both have a much wider scope.
Comment #93
chr.fritschFixed the minor issue
Comment #94
xjmSo I think not removing the permissions also means retaining the code paths for them; otherwise they're just strings in a file that don't do anything. So I think we need to add the new code paths here but not delete the previous ones, and then in #2925459: Deprecate generic media permissions we'd add
@trigger_error()to the old code paths along with the deprecation flag in the permissions file.Comment #95
chr.fritschBrought back the code path and added a
@todoComment #96
xjmOh, these need to be wrapped as per: https://www.drupal.org/node/1354#todo. The sentence should also probably have a period on it.
Comment #97
chr.fritschFixed the @todo
Comment #98
phenaproximaThe tiniest nitpick: "permissions" should be "permission" (singular).
Fixable on commit, though. So back to RTBC!
Comment #99
phenaproximaNo, wait. Back to NR for the follow-up @xjm mentioned in #92.
Comment #100
robpowellComment #101
robpowellWhen trying to apply this patch to 8.5, got the following error:
Rerolled this patch for 8.5.
Comment #102
robpowellComment #103
robpowellchanged plural comments to singular.
Comment #105
robpowellAlright, for those following at home #101 patch is too small. What happened was I was doing doing the git diff strategy to make a patch. Three of those files were new and not captured in the diff as those files were in my working tree and not committed. #103 is too big, I accidentally committed files that were not part of the patch.
Now, the goldilocks patch that is just the right size.
Comment #108
xjmI think I know what's going on here. :)
This is the test failure:
This is the merge conflict I get when I start to rebase the patch from #97:
From #97:
From the current patch:
Now, #2824851: EntityResource::patch() makes an incorrect assumption about entity keys, hence results in incorrect behavior did just get fixed, but it would be out of scope to do the removal in this issue even if the @todo were mere cruft. But it does sound kinda like it would cause that exact test failure. :) So let's try restoring the @todo and the access content grant; the patch should not change them. And then if the tests pass with that fix, then we should open up a separate followup to figure out what needs to happen following #2824851: EntityResource::patch() makes an incorrect assumption about entity keys, hence results in incorrect behavior.
Thanks!
Comment #109
robpowell@xjm thanks for the review and great find.
So TLDR; I removed a chunk of code from the reroll and we need to add it back in:
Note: local test still fail at the exact same place but hoping we get further on the test bot.
Comment #110
robpowellComment #111
phenaproximaGave this a read-through and it looks correct to me. I think it's ready to go.
I'll file the follow-up requested by @xjm in #92, based on what @larowlan said in #61 and #62.
Comment #112
phenaproximaFiled the follow-up: #2934995: Add a "Manage permissions" tab for each bundle that has associated permissions.
Comment #113
xjmWell and so. We already signed off on adding these permissions to the permission page. But then we added Audio and Video! So now we have:
Before patch with Media enabled: 113 permissions
After patch: 133 permissions
17.6% increase! :D
At the least, this makes #2925459: Deprecate generic media permissions a good deal more important.
Comment #114
starshapedAdding a screenshot of all the new media audio and video permissions.
Comment #115
xjmlol
Comment #116
xjmI pinged @yoroy for his thoughts based on the updated screenshot in the IS. Also note that if we add oEmbed and then add a remote media type, there would be another five permissions in core alone.
Comment #117
xjmThe counterpoint to the "17.6% increase" risk is that even if we unhide the module, Media will still not be in Standard. So if we are concerned about this based on the latest state, we could make it a Standard blocker instead. I'd say it's up to the UX team which.
Comment #118
berdir2 data points that might be interesting in the context of this and general issues about improving the UI
* One distribution that we have currently has 11 different media types, so that would be about 55 additional permissions. This is probably more than most sites.
* A site based on another distribution that we use that does not use media but has 27 node types, 651 permissions and 25 roles (don't ask me why..). That's 16275 checkboxes :) No, the global permissions page is not working anymore :)
The "winning" modules are..
node: 225 (27 * 8)
field_ui: 61 (did not expect that...apparently the site has 20 entity types with a field UI * 3)
taxonomy: 47 (this is still on 8.3, so this will grow a bit with 8.4)
file_entity: 32
masquerade: 26
profile: 19
Not exactly sure what my point is, probably that media is likely going to be fairly harmless on most sites compared to what node.module is already doing to them :)
One last thought, an alternative option to deprecating the old permissions would be to have a setting to switch between the two modes, either global any permissions or per-type. Then sites don't automatically get a ton of additional permissions. The screens in #2934995: Add a "Manage permissions" tab for each bundle that has associated permissions currently have a per-bundle optional checkbox, but as explained there, that doesn't really make sense, only a per-entity-type setting would, IMHO.
Comment #119
yoroy commentedThanks for the additional examples @Berdir. No objections to adding these permissions here as proposed.
Comment #120
gábor hojtsy@xjm asked for more usability feedback. I agree with @yoroy :)
Comment #121
acbramley commentedMy comment in #28 is partially address by #2889855: Unpublished media entity can not be accessed by owner and update any media/delete any media access possibly cached by user, I will create another issue for adding view any unpublished media.
Comment #122
acbramley commentedCreated the follow up #2936652: Add "view unpublished $bundle media" permissions for each media bundle
Comment #123
larowlanAdding review credits
@Berdir for providing real-world testing/insight
@hazong as per #14
@xjm for mentoring/reviews
Comment #124
larowlanFixed on commit
Committed as 4443678 and pushed to 8.6.x.
Cherry-picked as fb74ea4 and pushed to 8.5.x
Published change record
Comment #127
xjmYay, glad this landed!
Comment #129
amateescu commentedFYI: #2989469: MediaUpdateTest is broken