| 02:57 | * | uploaded an image: (368KiB) < libera.ems.host/_matrix/media/r0/downloa > |
| 03:13 | paul121[m] | Nice!! |
| 03:13 | paul121[m] | Next up, the cost of food being parsed from the receipt image? ;-) |
| 03:15 | paul121[m] | Still haven't tried out asset link myself :-( but I'm very eager to |
| 15:53 | mstenta[m] | @room farmOS dev call in ~6 minutes: meet.jit.si/farmos-dev |
| 18:53 | symbioquine[m] | I seem to be running into an issue where normal "Manager" users don't have permission to do file uploads via the API... is that expected? |
| 18:54 | symbioquine[m] | My code is similar to [flow #2](www.drupal.org/node/3024331). |
| 18:54 | symbioquine[m] | It works as the administrator user though. |
| 18:55 | symbioquine[m] | Error is... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 19:05 | mstenta[m] | Huh no that is not expected |
| 19:05 | symbioquine[m] | Looks like other folks might have run into something similar: drupal.stackexchange.com/questions/30111 |
| 19:07 | symbioquine[m] | Unfortunately, it would be pretty limiting to use [flow #1](www.drupal.org/node/3024331) because it wouldn't work as part of entity creation (only updates) |
| 19:16 | paul121[m] | oh dang. do we not grant the `create asset` permission via managed roles? Instead we only grant the granular `create {type} asset` ? |
| 19:16 | symbioquine[m] | paul121[m]: I think that's correct |
| 19:16 | symbioquine[m] | Actually `create asset` doesn't even show up in the list of permissions for some reason... |
| 19:19 | mstenta[m] | Wait what would `create asset` perm be for? |
| 19:20 | * | uploaded an image: (4KiB) < libera.ems.host/_matrix/media/r0/downloa > |
| 19:20 | paul121[m] | It would be more like `create any asset`, but yeah that doesn't seem to exist |
| 19:20 | mstenta[m] | (Sorry on my phone waiting to pick up kids) |
| 19:20 | symbioquine[m] | np 😁 |
| 19:20 | mstenta[m] | But why? |
| 19:20 | mstenta[m] | Isnt it a file you want to create? |
| 19:21 | paul121[m] | > POST /jsonapi/node/article/field_image |
| 19:21 | paul121[m] | So they should be able to get the bundle *I think*... the POST includes entity type and bundle |
| 19:22 | symbioquine[m] | mstenta[m]: Yeah, it seems odd |
| 19:22 | paul121[m] | mstenta[m]: it's a file you want to create, but iirc each file field has the storage location configured to it. This could be different per bundle. So it kinda makes sense there is a permission check here |
| 19:23 | paul121[m] | otherwise people could create files in the private/public directory structure where you don't want them to? maybe? |
| 19:23 | mstenta[m] | Yea but wouldnt that check be for "updating own asset"? |
| 19:23 | mstenta[m] | (In addition to allowing file creation I imagine) |
| 19:24 | mstenta[m] | (Sorry maybe you're talking about creating an asset not updating one) |
| 19:24 | symbioquine[m] | Either one |
| 19:26 | symbioquine[m] | The nice thing about flow #2 is that you post to `/api/asset/animal/image` without needing to specify the animal asset that the file will get related to |
| 19:26 | symbioquine[m] | Then make a second request with the resulting `file--file` id to add the relationship to an existing `asset--animal` record, or include it in a new `asset-animal` record. |
| 19:27 | symbioquine[m] | The first request doesn't know how the resulting file will be used other than that it will be used in the specified relationship field. |
| 19:31 | paul121[m] | hmm. well I think this is the relevant source: |
| 19:31 | paul121[m] | git.drupalcode.org/project/drupal/-/blob |
| 19:31 | paul121[m] | git.drupalcode.org/project/drupal/-/blob |
| 19:31 | paul121[m] | it seems odd that the error says "permissions are required: .... OR ..." ... this line seems to do a `$access_result->andIf()` check, which isn't OR? |
| 19:31 | paul121[m] | git.drupalcode.org/project/drupal/-/blob |
| 19:33 | paul121[m] | I believe the `fieldAccess('edit'..)` call is what gets the `administer assets` permission. Not 100% sure tho... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 19:34 | symbioquine[m] | It seems like that code is trying to do a bundle-specific check: git.drupalcode.org/project/drupal/-/blob |
| 19:34 | symbioquine[m] | I guess I should add some logging in there and see what some of those values are... |
| 19:38 | paul121[m] | ah yes. but this is a base field! not a bundle field |
| 19:38 | paul121[m] | > // Base fields do not have target bundles. |
| 19:38 | paul121[m] | maybe that is part of the issue? hmm |
| 19:52 | paul121[m] | * I believe the `fieldAccess('edit'..)` call is what gets the `administer assets` permission. Not 100% sure tho... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 19:52 | paul121[m] | * ~I believe the `fieldAccess('edit'..)` call is what gets the `administer assets` permission. Not 100% sure tho~... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 19:52 | symbioquine[m] | `$entity` and `$bundle` are both `NULL`. |
| 19:52 | symbioquine[m] | `$field_definition` is `Drupal\Core\Field\BaseFieldDefinition Object ( [type:protected] => image [propertyDefinitions:protected] => [schema:protected] => [indexes:protected] => Array ( ) [itemDefinition:protected] => Drupal\Core\Field\TypedData\FieldItemDataDefinition Object ( [fieldDefinition:protected] => Drupal\... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 19:54 | paul121[m] | This looks suspicious in the `drupal/entity` module. It has the `or` for both `administer {type}` and `create {type}` permissions: |
| 19:54 | paul121[m] | git.drupalcode.org/project/entity/-/blob |
| 19:54 | paul121[m] | this might be a wild chase of entity access control handlers... which can be implemented in different classes, react to hooks, and alter hooks. so debugger will be necessary :-) |
| 19:55 | paul121[m] | give the the `$bundle` is `NULL`... this might be the issue? |
| 19:56 | symbioquine[m] | Yeah, I think `$bundle` being `NULL` just validates what you said about the image being a base field. |
| 19:56 | paul121[m] | If you turn on field_ui and make a bundle file field I bet it will work! |
| 19:57 | symbioquine[m] | Hmmm, I'm skeptical... |
| 19:57 | symbioquine[m] | Wouldn't I also have to add an extra permission in that case too? |
| 19:57 | symbioquine[m] | oh |
| 19:57 | symbioquine[m] | I see |
| 19:58 | symbioquine[m] | You're hoping to cause it to line up with the existing `create animal asset` permissions that we already grant? |
| 19:58 | symbioquine[m] | (as part of the `farm_manager` role that is) |
| 19:59 | paul121[m] | yep! |
| 20:04 | * | sandrajude[m] has joined |
| 20:16 | symbioquine[m] | I agree that would probably make it work, but I'm not sure it's that important of a hypothesis to test since we're not actually contemplating making the image/file fields into bundle fields right? |
| 20:17 | symbioquine[m] | I guess I'm more interested in what a reasonable path forward for the fields we actually have is... |
| 20:17 | symbioquine[m] | It seems like that access check is probably pretty reasonable as a default for Drupal core. |
| 20:18 | symbioquine[m] | farmOS is doing something special beyond that by breaking down the create/update/delete permissions by asset/log bundle right? |
| 20:19 | paul121[m] | Yeah I agree. The thing is Drupal core doesn't really have the "bundle permissions" itself... that's via the `entity` module :-/ |
| 20:19 | paul121[m] | yeah right |
| 20:19 | symbioquine[m] | So naively, that makes me think we need a access control handler which says "oh right, you have permission to create animal assets, so you should be allowed to create file/image entities related to them" |
| 20:22 | paul121[m] | Yeah |
| 20:23 | paul121[m] | only a matter of how... :D |
| 20:28 | paul121[m] | `$entity_access_control_handler->createAccess();` accepts a `$context` array, but nothing is provided here. Maybe that could be used. |
| 20:28 | paul121[m] | git.drupalcode.org/project/drupal/-/blob |
| 20:30 | sandrajude[m] | t.me/Etxcapital1 |
| 20:30 | sandrajude[m] | I'll 20 people on how to earn $10,000 or more in just 3day's from the crypto market.but you will pay me 10% commission when you receive your profit. if interested send me a direct message, for more information... Contact via telegram |
| 20:30 | sandrajude[m] | t.me/Etxcapital1 |
| 20:32 | symbioquine[m] | ^ Reported as spam |
| 20:32 | * | sandrajude[m] has left |
| 20:32 | mstenta[m] | banned! |
| 20:32 | symbioquine[m] | Yeah, I think both are helpful |
| 20:36 | symbioquine[m] | Fortunately, `$field_access_result` is getting set to `Drupal\Core\Access\AccessResultAllowed` |
| 20:37 | symbioquine[m] | So we only need to figure out how to get that `$entity_access_result` to pass |
| 20:37 | symbioquine[m] | Right now it's `Drupal\Core\Access\AccessResultNeutral Object ( [reason:protected] => The following permissions are required: 'administer assets' OR 'create asset'. [cacheContexts:protected] => Array ( [0] => user.permissions ) [cacheTags:protected] => Array ( ) [cacheMaxAge:protected] => -1 )` |
| 20:46 | paul121[m] | hmm. I wonder if it would be okay to return TRUE if the user has any `create {bundle} asset` ?? 🤔 |
| 20:46 | symbioquine[m] | Couldn't we change [this](github.com/farmOS/farmOS/blob/b495cdb840) to use a decorated access handler? |
| 20:47 | paul121[m] | if they don't, then it would be FALSE. And the `create asset` permission really shouldn't be used anywhere, this is quite the edge case where that permission string is being generated |
| 20:47 | paul121[m] | symbioquine[m]: yes exactly! |
| 20:49 | paul121[m] | $permissions = array_map(function ($bundle) { |
| 20:49 | paul121[m] | return "create $bundle asset"; |
| 20:49 | paul121[m] | }, $asset_bundles); |
| 20:49 | paul121[m] | $result = AccessResult::allowedIfHasPermissions($account, $permissions, 'OR'); |
| 20:49 | paul121[m] | * maybe this?... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 21:02 | symbioquine[m] | Having some network trouble right now... Once it comes back I'll see if I can get something like that working. |
| 21:18 | symbioquine[m] | Alternatively, I think it might be possible to implement [`hook_entity_create_access`](github.com/drupal/drupal/blob/ecbe3ad37c) and use the [`'entity_type_id'` field](github.com/drupal/drupal/blob/ecbe3ad37c) of the context... |
| 21:21 | paul121[m] | ah nice, implementing the hook might be better anyways! |
| 21:58 | symbioquine[m] | <paul121[m]> "ah nice, implementing the hook..." <- I realized the entity bundle is the part that's missing there... |
| 21:58 | symbioquine[m] | It could be hacked up something like this; |
| 21:58 | * | sent a php code block: libera.ems.host/_matrix/media/r0/downloa |
| 21:59 | symbioquine[m] | Which seems to work, but there might be a better strategy than getting the bundle from the URL... |
| 22:00 | symbioquine[m] | * ```php... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 22:14 | paul121[m] | nice. yes, are you familiar with Route Parameters? |
| 22:15 | paul121[m] | you should be able to get the route parameters object from Drupal::request() |
| 22:15 | paul121[m] | I think these jsonapi file routes are created here: git.drupalcode.org/project/drupal/-/blob |
| 22:16 | paul121[m] | and the "resource type" route param: git.drupalcode.org/project/drupal/-/blob |
| 22:18 | paul121[m] | not sure the best way to identify the "file upload routes" though... maybeee there is some other metadata about these routes you could use? |
| 22:18 | paul121[m] | if not just your regex! |
| 22:22 | symbioquine[m] | <paul121[m]> "nice. yes, are you familiar with..." <- Sounds similar to getting parameters from the route match interface. e.g. github.com/farmOS/farmOS/blob/04bf771d91 |
| 22:22 | paul121[m] | yes I think so! |
| 23:02 | symbioquine[m] | This one's a bit stricter/cleaner;... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 23:03 | symbioquine[m] | * if (empty($entity_type_id) || empty($entity_bundle) || empty($route_match)) { |
| 23:04 | symbioquine[m] | * This one's a bit stricter/cleaner;... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 23:06 | symbioquine[m] | * This one's a bit stricter/cleaner;... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 23:08 | symbioquine[m] | * This one's a bit stricter/cleaner;... (full message at libera.ems.host/_matrix/media/r0/downloa) |
| 23:26 | paul121[m] | That looks great. Assuming it works too? |