It would be really useful to allow administrators to change permissions on folders by role.

This way you could allow *ROLE1* to read *FOLDER3* but read/write *FOLDER6*.

Thoughts/Ideas?

Comments

Sebastian.Buesing’s picture

Hi,

the current version does have an access control approach:

function media_browser_plus_media_access($media_entity) {
  if(media_browser_plus_access('administer media'))
    return true;
  // start with ACCESS_ALLOW - by default media items are fully accessible
  $access = MEDIA_ENTITY_ACCESS_ALLOW;
  // collect all modules implementing hook_media_entity_access
  foreach (module_implements('media_entity_access') as $module) {
    // and invoke the hook
    $return = module_invoke($module, 'media_entity_access', $media_entity);
    // if no ALLOW or DENY was returned we assume IGNORE and check the next
    if($return != MEDIA_ENTITY_ACCESS_ALLOW && $return != MEDIA_ENTITY_ACCESS_DENY)
      continue;
    // if we have a DENY we can return a complete false here
    if($return === MEDIA_ENTITY_ACCESS_DENY)
      return false;
    // otherwise it is an ALLOW and we save it
    $access = MEDIA_ENTITY_ACCESS_ALLOW;
  }
  // check if we had one allow
  return ($access === MEDIA_ENTITY_ACCESS_ALLOW);
}

This allows you to create a seperate module which can allow access to media or deny it and do all sorts of stuff. However a the moment this function is only called when you switch to private files and access the original media item. (media/3/view for instance). Anything more complex would have to be done with the help of the media module guys, because you would need to patch that module too.

Like this (which I have done for a client):

media.module:

function media_load($fid) {
  if ($files = entity_load('media', array($fid))) {
    $media = array_shift($files);
    // use media_browser_plus access restrictions if module exists
    if(module_exists('media_browser_plus')) {
      if(!media_browser_plus_media_access($media))
        return FALSE;
    }
    return $media;
  }
  return FALSE;
}
...
function media_load_multiple($fids = array(), $conditions = array(), $reset = FALSE) {
  $items = entity_load('media', $fids, $conditions, $reset);
  // use media_browser_plus access restrictions if module exists
  if(module_exists('media_browser_plus')) {
    $result = array();
    foreach($items as $key => $media) {
      if(media_browser_plus_media_access($media))
        $result[$key] = $media;
    }
    $items = $result;
  }
  return $items;
}
brayo4’s picture

this would be a great feature thank you.

saahbaa’s picture

do we have any patch for this code?

bezlash@gmail.com’s picture

Issue summary: View changes

Hi,

Does anyone have a solution for this for version 7.x-3.0-beta4?

Thanks,
Bez