diff --git a/includes/media.pages.inc b/includes/media.pages.inc index 07d038a..28a6d7e 100644 --- a/includes/media.pages.inc +++ b/includes/media.pages.inc @@ -45,9 +45,17 @@ function media_file_page_edit_multiple($files) { $form['buttons']['cancel'] = array( '#type' => 'link', '#title' => t('Cancel'), - '#href' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/content/file', '#weight' => 50, ); + if (isset($_GET['destination'])) { + $form['buttons']['cancel']['#href'] = $_GET['destination']; + } + else if (user_access('administer files')) { + $form['buttons']['cancel']['#href'] = 'admin/content/file'; + } + else { + $form['buttons']['cancel']['#href'] = ''; + } // Override the page title since each file form sets a title. drupal_set_title(t('Edit multiple files')); diff --git a/media.module b/media.module index ade1169..8392ec9 100644 --- a/media.module +++ b/media.module @@ -184,7 +184,8 @@ function media_menu() { 'title' => 'Edit multiple files', 'page callback' => 'media_file_page_edit_multiple', 'page arguments' => array(4), - 'access arguments' => array('edit any files'), + 'access callback' => '_media_file_entity_access_recursive', + 'access arguments' => array(4, 'update'), 'file' => 'includes/media.pages.inc', ); } @@ -570,6 +571,29 @@ function media_file_download_access($field, $entity_type, $entity) { } } +/** + * Access callback for the media-multi form. + * + * @param $files + * An array of files being editing on the multiform. + * @param $op + * A string containing the operation requested, such as 'update'. + * @return + * TRUE if the current user has access to edit all of the files, otherwise FALSE. + */ +function _media_file_entity_access_recursive($files, $op) { + // Check that the current user can access each file. + if (!empty($files)) { + foreach ($files as $file) { + if (!file_entity_access($op, $file)) { + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + /* ***************************************** */ /* API FUNCTIONS */ /* ***************************************** */