From 91a379067af751e495411dac900e9731dd94704e Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 14 Jan 2014 17:40:17 +0000 Subject: [PATCH 1/4] Only render the regenerate under certain conditions. --- theme/theme.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme/theme.inc b/theme/theme.inc index 0e62f0d7..2675ab7a 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -447,7 +447,7 @@ function theme_islandora_datastream_regenerate_link(array $vars) { $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) { + if (isset($hook['source_dsid']) && isset($object[$hook['source_dsid']]) && $hook['destination_dsid'] == $datastream->id) { return l(t('regenerate'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/regenerate"); } } From 9a76642364e4977664f05cc4b0948c9b31ebb5bf Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 14 Jan 2014 19:00:06 +0000 Subject: [PATCH 2/4] Make the rendering of the regenerate link respect things. --- islandora.module | 17 +++++++++++++++++ theme/theme.inc | 36 ++++++++++++++---------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/islandora.module b/islandora.module index fb165f1e..6537ef21 100644 --- a/islandora.module +++ b/islandora.module @@ -1829,3 +1829,20 @@ function islandora_islandora_metadata_display_info() { ), ); } + +/** + * Implements hook_islandora_datastream_access(). + */ +function islandora_islandora_datastream_access($op, AbstractDatastream $datastream, $user) { + if ($op == ISLANDORA_REGENERATE_DERIVATIVES) { + $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))) { + return TRUE; + } + } + return FALSE; + } + return NULL; +} diff --git a/theme/theme.inc b/theme/theme.inc index 2675ab7a..2d3fe898 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -53,14 +53,12 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { 'class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds), ); - if (islandora_datastream_access(ISLANDORA_VIEW_DATASTREAM_HISTORY, $ds)) { - $row[] = array( - 'class' => 'datastream-versions', - 'data' => theme('islandora_datastream_version_link', array( - 'datastream' => $ds, - )), - ); - } + $row[] = array( + 'class' => 'datastream-versions', + 'data' => theme('islandora_datastream_version_link', array( + 'datastream' => $ds, + )), + ); $row[] = array( 'class' => 'datastream-download', 'data' => theme('islandora_datastream_download_link', array( @@ -79,14 +77,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 +440,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 (isset($hook['source_dsid']) && isset($object[$hook['source_dsid']]) && $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"); } } From 12620a4bf6bdc98b17532418adf9158225a58c57 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 14 Jan 2014 19:14:24 +0000 Subject: [PATCH 3/4] Make our datastream_access call work and revert change to themeing of version links. --- islandora.module | 2 +- theme/theme.inc | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/islandora.module b/islandora.module index 6537ef21..9c1ae7d9 100644 --- a/islandora.module +++ b/islandora.module @@ -1839,7 +1839,7 @@ function islandora_islandora_datastream_access($op, AbstractDatastream $datastre $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))) { - return TRUE; + return user_access(ISLANDORA_REGENERATE_DERIVATIVES); } } return FALSE; diff --git a/theme/theme.inc b/theme/theme.inc index 2d3fe898..b783cfa8 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -53,12 +53,14 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { 'class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds), ); - $row[] = array( - 'class' => 'datastream-versions', - 'data' => theme('islandora_datastream_version_link', array( - 'datastream' => $ds, - )), - ); + if (islandora_datastream_access(ISLANDORA_VIEW_DATASTREAM_HISTORY, $ds)) { + $row[] = array( + 'class' => 'datastream-versions', + 'data' => theme('islandora_datastream_version_link', array( + 'datastream' => $ds, + )), + ); + } $row[] = array( 'class' => 'datastream-download', 'data' => theme('islandora_datastream_download_link', array( From 587c4e22aee5ac40c496ba159ede812201bf9d33 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 14 Jan 2014 19:24:17 +0000 Subject: [PATCH 4/4] Fix a bug where user_access/namespaces were not getting checked for datastreams. --- islandora.module | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/islandora.module b/islandora.module index 9c1ae7d9..8173df52 100644 --- a/islandora.module +++ b/islandora.module @@ -1834,15 +1834,22 @@ function islandora_islandora_metadata_display_info() { * Implements hook_islandora_datastream_access(). */ function islandora_islandora_datastream_access($op, AbstractDatastream $datastream, $user) { - if ($op == ISLANDORA_REGENERATE_DERIVATIVES) { + 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))) { - return user_access(ISLANDORA_REGENERATE_DERIVATIVES); + $applicable_hook = TRUE; + break; } } - return FALSE; + if (!$applicable_hook) { + $result = FALSE; + } } - return NULL; + return $result; }