< 082022-09-09⋎10 >

Topic for #farmOS is: farmOS (farmos.org) is a free and open source, web-based farm management system. User guide: farmos.org/guide/ - Forum: farmOS.discourse.groupSet by mstenta on 2021-06-15 at 12:52
00:07symbioquine[m]It works. If I change the last line to `return AccessResult::neutral();` then the permission failure is the same as before. If I change the last line to `return AccessResult::allowedIfHasPermission($account, "Xcreate " . $entity_bundle . " " . $entity_type_id);` then it fails with the message "The current user is not permitted to upload a file for this field. The 'Xcreate animal asset' permission is required."
00:07symbioquine[m]As written above, creating a file succeeds when I have the `farm_manager` permission.
00:09symbioquine[m]... and gives me permission denied again if I change my user to only have `farm_viewer` permissions, but with the new message "The current user is not permitted to upload a file for this field. The 'create animal asset' permission is required."
00:12symbioquine[m]I'll send a PR...
00:18paul121[m]woohoo! that was a great find!
00:19paul121[m]and another reminder we need to test not using the admin user 😅
00:22symbioquine[m]github.com/farmOS/farmOS/pull/563
01:30*GudjonEinarMagnu has quit (Ping timeout: 248 seconds)
01:30*evered[m] has quit (Ping timeout: 248 seconds)
01:30*symbioquine[m] has quit (Ping timeout: 248 seconds)
01:30*jgaehring[m] has quit (Ping timeout: 248 seconds)
01:35*dazinism[m] has quit (Ping timeout: 268 seconds)
01:35*FarmerEd[m] has quit (Ping timeout: 268 seconds)
01:35*KarsonWynne[m] has quit (Ping timeout: 268 seconds)
01:35*mstenta[m] has quit (Ping timeout: 268 seconds)
01:45*jgaehring[m] has joined
01:51*jonasbits has quit (Quit: No Ping reply in 180 seconds.)
02:24*GudjonEinarMagnu has joined
02:32*evered[m] has joined
02:34*symbioquine[m] has joined
09:00*GerardoLisboa[m] has quit (Quit: You have been kicked for being idle)
09:09*FarmerEd[m] has joined
09:20*KarsonWynne[m] has joined
09:41*mstenta[m] has joined
10:03*dazinism[m] has joined
11:43mstenta[m]Nice work symbioquine and paul121 ! Just catching up on all this...
11:44mstenta[m]I did a little digging through the Drupal core issue queue and found this, which sounds related (but is "Closed (fixed)"): www.drupal.org/project/drupal/issues/315
11:46mstenta[m]Seems like this is the issue that may have added some of the logic in the first place, and dealt with this exact base/bundle field conundrum.
11:46mstenta[m]> This is happening because the file field is a base field. ...
11:46mstenta[m]> So the question because how can we check create access for files being attached to base fields. I think is we can't determine the bundle then checking the generic create access is all we can do.
11:46mstenta[m]- @alexpott
11:47mstenta[m]s/- @alexpott/ - @alexpott/
11:47mstenta[m]s/-/\-/
11:47mstenta[m]> That means $bundle will be NULL for a node base field. It should use $entity->bundle() if the entity type supports bundles.
11:47mstenta[m]> ...
11:47mstenta[m]> Oh wait, that doesn't work because that code is only used when there is no entity. Not sure how we would get it to check on the right bundle then.
11:47mstenta[m]\- @Berdir
11:48mstenta[m]So it seems like this issue was mainly to enable file uploads for entities that use base fields, but was not focused on the bundle issue we are running into... maybe?
11:49mstenta[m]eg: the original issue was about adding a `file` base field to `user` entities (which do not have bundles)
11:50mstenta[m]That thread then led me to this one: www.drupal.org/project/drupal/issues/294
11:51mstenta[m]I haven't dug through that one in great detail yet, but I wonder if it may address this. (Marked "Critical" and "Needs work")
11:53mstenta[m]In either case, it seems that the hook you wrote makes sense for now symbioquine! I would like to link to add some more comments and links to core issues in it though, so we remember why it's there, and potentially remove it if/when this gets resolved upstream.
11:53mstenta[m]Ideally I think we'd want an automated test for this too... if possible...
11:54mstenta[m]eg: If core fixes this upstream, and we no longer need the hook, the test would still pass if we removed the hook
11:55mstenta[m]Lastly, I think this hook belongs in the `farm_api` module, not `farm_entity`, because it's specific to JSON:API
12:28symbioquine[m]Makes sense. Thanks for looking into it!
12:42symbioquine[m]<mstenta[m]> "I haven't dug through that one..." <- Sadly, the current version of the patch seems to perpetuate the same behaviour (assuming I'm reading the code correctly), and the discussion doesn't appear to make any mention of this permission issue being in-scope.
12:43mstenta[m]Hmm OK
12:43mstenta[m]I'm not surprised
12:43mstenta[m]The focus is on unifying all the code
12:43mstenta[m]Feels like there should be an issue for this specifically
12:43symbioquine[m]Yeah, it's kind of a weird case we're talking about too...
12:43symbioquine[m]bundle-level permissions for a base field :)
12:44mstenta[m]I don't know if I consider it that weird
12:44mstenta[m]This would affect nodes in Drupal core too
12:44mstenta[m](unless I'm mistaken)
12:45symbioquine[m]Is there precedent for the permissions working that way elsewhere?
12:45mstenta[m]I think the same issue would occur if you added a base file field to node entities
12:46symbioquine[m]Assuming the site does use bundles for the nodes and doesn't grant a blanket "create node" permission to the users who are doing the file uploads.
12:47mstenta[m]right - but that IS an issue IMO
12:47mstenta[m]it's too broad
12:47symbioquine[m]cool
12:48mstenta[m](fyi nodes always use bundles, impossible not to)
12:48mstenta[m](SOME entity types don't, like `user`... but most entity types, both in core and contrib, do)
12:49mstenta[m](we use the `entity` module to auto-generate bundle-specific permissions for our entity types, but that really just mimics the same permissions that core applies to `node`)
12:49symbioquine[m]good to know
12:49mstenta[m](so those permissions are "standard" in that sense)
12:49mstenta[m](although maybe not "standard enough" because it's not exactly a core standard)
12:50mstenta[m]so yea... we'll probably have this hook for a while 😅
12:50mstenta[m]but i wonder if it would actually make sense to contribute it to the `entity` contrib module
12:51mstenta[m]the overall goal of `entity` (contrib) is to provide stuff that core hasn't yet
12:51mstenta[m]specifically to support other modules that provide their own entity types (like ours)
12:52mstenta[m]but in theory, that stuff should move to core over time
12:52mstenta[m]sort of a staging ground
12:53mstenta[m]so... i wonder... maybe instead of adding a hook to farmOS, should we make a patch for `entity.module`? and apply that in our `composer.json`? we already patch that module for a few other things
12:54mstenta[m]the movement of that module (and Drupal core) is glacial... so i wouldn't be too worried about chasing `HEAD` on a patch like that... and it is sort of specific to the permissions that the `entity` module itself are providing
12:55mstenta[m](i think... maybe paul121 can point out flaws in this thinking)
12:55mstenta[m]just thinking out loud 😄
12:56symbioquine[m]mstenta[m]: So the idea would be to open the issue against the entity project with a patch that we would apply right away to farmOS and use the issue to track this long term?
12:56mstenta[m]yea
12:56mstenta[m]the benefit of that is then we have a tracking issue we're following - so it's explicit
12:56mstenta[m]and gets more folks involved
12:56symbioquine[m]Does the entity module already provide similar things connected with JSON:API?
12:57mstenta[m]because it's not necessarily farmOS-specific
12:57mstenta[m]good question... i don't know if it does
12:57mstenta[m]but this feels like a pretty harmless patch to toss up and start a convo
12:57mstenta[m](still... i wouldn't expect much of a response initially... but this is the type of thing that others might stumble upon over time as JSON:API file uploads get more uptake)
12:58mstenta[m](especially if the error message is explicitly included in the title, description, link to related issues, etc etc)
12:58symbioquine[m]This is kind of similar: git.drupalcode.org/project/entity/-/blob
12:59mstenta[m]oh yea ok
12:59mstenta[m]fyi, the readme for the module points to a number of upstream core issues that this module is essentially "shimming" and the permissions is one of them
12:59mstenta[m]git.drupalcode.org/project/entity/-/blob
13:00mstenta[m]www.drupal.org/node/2809177
13:00mstenta[m]so... if that lands in core, then this DOES become a core issue
13:01symbioquine[m]interesting
13:03symbioquine[m]I like that direction! It might take me a little while to get back to it though... I need to keep pushing Asset Link through to an Alpha release and get back to Greg on the farmOS-map stuff...
13:12mstenta[m]symbioquine: of course, if you just need this for asset link you could also put the hook in that module and punt on all this until you feel like it haha
13:13mstenta[m]and if anyone else runs into it we can expedite that
13:13symbioquine[m]:) I might do that
13:13symbioquine[m]One nice thing is that it can exist in multiple places without hurting anything AFAICT
13:13mstenta[m]i think that's true!
13:13symbioquine[m]it's so specific about what it's granting
13:53mstenta[m]Ah man... there may be more to the Drush update considerations: www.drupal.org/project/farm/issues/33087
13:54mstenta[m]> Drush does not support migrate plus config entities
13:56*uploaded an image: (86KiB) < libera.ems.host/_matrix/media/r0/downloa >
13:56symbioquine[m]**RotatingPony.alink.vue**... (full message at libera.ems.host/_matrix/media/r0/downloa)
17:03paul121[m]<mstenta[m]> "(i think... maybe paul121 can..." <- making a patch to entity seems to make sense. but I like your idea of including in farmOS core farm_api with a test. It would be really nice to just have that done ourselves
17:04paul121[m]if we were to contribute it to `entity` are there other things we need to consider when generalizing it?
17:05paul121[m]right now this logic would run for all entity types. maybe we should adjust the logic to only run for entity types that use the `entity` decorated access control handler. those would be the only entity types that have the bundle permissions
17:08mstenta[m]All good points!
17:10paul121[m]Generalizing is hard :-///

< 082022-09-09⋏10 >