diff --git a/islandora.module b/islandora.module index fb165f1e..8173df52 100644 --- a/islandora.module +++ b/islandora.module @@ -1829,3 +1829,27 @@ function islandora_islandora_metadata_display_info() { ), ); } + +/** + * Implements hook_islandora_datastream_access(). + */ +function islandora_islandora_datastream_access($op, AbstractDatastream $datastream, $user) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $result = islandora_namespace_accessible($datastream->parent->id) && user_access($op, $user); + + if ($result && $op == ISLANDORA_REGENERATE_DERIVATIVES) { + $applicable_hook = FALSE; + $object = $datastream->parent; + $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); + foreach ($hooks as $hook) { + if ($hook['destination_dsid'] == $datastream->id && ((isset($hook['source_dsid']) && isset($object[$hook['source_dsid']]) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[$hook['source_dsid']], $user)) || (array_key_exists('source_dsid', $hook) && $hook['source_dsid'] == NULL))) { + $applicable_hook = TRUE; + break; + } + } + if (!$applicable_hook) { + $result = FALSE; + } + } + return $result; +} diff --git a/theme/theme.inc b/theme/theme.inc index 0e62f0d7..b783cfa8 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -79,14 +79,12 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { 'datastream' => $ds, )), ); - if (islandora_datastream_access(ISLANDORA_REGENERATE_DERIVATIVES, $ds)) { - $row[] = array( - 'class' => 'datastream-regenerate', - 'data' => theme('islandora_datastream_regenerate_link', array( - 'datastream' => $ds, - )), - ); - } + $row[] = array( + 'class' => 'datastream-regenerate', + 'data' => theme('islandora_datastream_regenerate_link', array( + 'datastream' => $ds, + )), + ); $rows[] = $row; } $caption = filter_xss($islandora_object->label) . ' - ' . $islandora_object->id; @@ -444,12 +442,8 @@ function theme_islandora_datastream_version_link(array $vars) { */ function theme_islandora_datastream_regenerate_link(array $vars) { $datastream = $vars['datastream']; - $object = $datastream->parent; - $hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object)); - foreach ($hooks as $hook) { - if ($hook['destination_dsid'] == $datastream->id) { - return l(t('regenerate'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/regenerate"); - } + if (islandora_datastream_access(ISLANDORA_REGENERATE_DERIVATIVES, $datastream)) { + return l(t('regenerate'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/regenerate"); } }