Add possibility to hide existing media library items when adding new items (e.g. to a field)

Created on 11 August 2020, over 4 years ago
Updated 16 February 2024, 10 months ago

Problem/Motivation

In order to add new media items to a node via media library users are always able to see and use existing media items. If we want to let unprivileged users add media items without them being able to see and use other existing media, we're out of luck.

Steps to reproduce

What I tried

  1. Select media library as field widget
  2. As user without "View media" permission add media item to field
  3. See ajax/log error (below) "The 'view media' permission is required." with the "Add files" dialog does not proceed to save the file

Technically of course I would want that the media library only shows the just uploaded file instead of disallowing access altogether.

Proposed resolution

Not sure. Either allow adding media items without having access to the media library or add another permission check for seeing media library items.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Error from steps to reproduce step 3

Path: /en/media-library?media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bmedia_image%5D=media_image&media_library_selected_type=media_image&media_library_remaining=-1&media_library_opener_parameters%5Bfield_widget_id%5D=field_h4c_multi_media&media_library_opener_parameters%5Bentity_type_id%5D=node&media_library_opener_parameters%5Bbundle%5D=organisation&media_library_opener_parameters%5Bfield_name%5D=field_h4c_multi_media&media_library_opener_parameters%5Bentity_id%5D=185&hash=0eMIP6B1oA59Q_f4yxfAnvuUThTiR47MpEn8BpARoDY&ajax_form=1&_wrapper_format=drupal_ajax. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: The 'view media' permission is required. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 120 of /var/www/html/web/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany anruether Bonn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia sime Melbourne

    @pameeela except I've found the core one to be the best for bulk upload.

    I'm going to solve this as a permissions thing, but in the meantime I have added a "Media created in the last 2 hours" filter to the media library views displays so that at least it's not the whole library they see.

  • πŸ‡©πŸ‡ͺGermany anruether Bonn
  • First commit to issue fork.
  • πŸ‡¦πŸ‡ΊAustralia sime Melbourne

    Perhaps a workaround. I am adding a contextual filter to limit items to those owned by the current user, but it needs a patch from https://www.drupal.org/node/3401726 β†’

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    Just went through this with @mlncn

    If you go to the media library settings at /admin/config/media/media-library
    then you can enable the advanced UI. Enabling this adds a button to your media selection interface that says "Save and insert"

    Otherwise, just make sure the required permission on your media library views is set to "Access media overview" instead of the default "View media"

    More of an aside, but one other gotcha is that your user has to have permission to add media of the types in the field.

    Once all of this is set up, you can use the media library widget to add media without having access to view the media library.

    While this is great, it is all still very confusing to set up, and even still it would be great if the advanced UI was more configurable so that, for example, I could hide the "Save and select button" that doesn't do anything when your site is configured like this.

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    A small module for hiding the "Save and select" button: https://www.drupal.org/project/simplify_media_ui β†’

Production build 0.71.5 2024