Only generate permissions for media types with role based access enabled

Created on 13 April 2023, over 1 year ago
Updated 19 April 2023, over 1 year ago

Problem/Motivation

Currently the role matrix contains rows for all media types. Instead it would be better, if only rows are added for media types with "Role based access" enabled. Otherwise this might be confusing.

If this isn't possible technically, the role description should explain, that the permissions are only applied, if this access model is selected on the settings page.

Steps to reproduce

Only enable Role based access for one media type on /admin/config/media/media-private-access but see all roles listed on /admin/people/permissions#module-media_private_access

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    Shouldn't this be possible here, based on the config settings?

      /**
       * Returns an array of additional media type permissions.
       *
       * @return array
       *   The media type permissions.
       *
       * @see \Drupal\user\PermissionHandlerInterface::getPermissions()
       * @see \Drupal\media\MediaPermissions::mediaTypePermissions()
       */
      public function mediaTypePermissions() {
        $perms = [];
        // Generate additional media permissions for all media types.
        $media_types = $this->entityTypeManager
          ->getStorage('media_type')->loadMultiple();
        /** @var \Drupal\media\MediaTypeInterface $type */
        foreach ($media_types as $type) {
          $perms += $this->buildPermissions($type);
        }
        return $perms;
      }
    
      /**
       * Returns a list of media permissions for a given media type.
       *
       * @param \Drupal\media\MediaTypeInterface $type
       *   The media type.
       *
       * @return array
       *   An associative array of permission names and descriptions.
       */
      protected function buildPermissions(MediaTypeInterface $type) {
        $type_id = $type->id();
        $type_params = ['%type_name' => $type->label()];
    
        return [
          "view $type_id media" => [
            'title' => $this->t('%type_name: View media', $type_params),
          ],
        ];
      }
    

    (/src/MediaPrivateAccessPermissions.php)

  • 🇩🇪Germany Anybody Porta Westfalica

    Just came across this again and I think this is really important for UX. Changing this from bug - as it's not a clear bug - to a major feature request.

    In the current situation it's not clear that these permissions simply have NO effect however they are configured. That makes no sense and leads to confusion.

  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.71.5 2024