From c7aca6feae86c5bdeca96beb0b1633e8df6c1099 Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Mon, 25 Feb 2013 13:12:52 -0400 Subject: [PATCH 1/2] modify manage permissions D7 --- islandora.info | 1 + islandora.module | 33 +++++------ tests/islandora_manage_permissions.test | 78 +++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 tests/islandora_manage_permissions.test diff --git a/islandora.info b/islandora.info index 9763819b..e44ec721 100644 --- a/islandora.info +++ b/islandora.info @@ -14,4 +14,5 @@ files[] = includes/object.entity_controller.inc files[] = tests/web_test_case.inc files[] = tests/authtokens.test files[] = tests/hooks.test +files[] = tests/islandora_manage_permissions.test php = 5.3 diff --git a/islandora.module b/islandora.module index b700807e..10cc1cb4 100644 --- a/islandora.module +++ b/islandora.module @@ -28,7 +28,6 @@ define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); // Permissions. define('FEDORA_VIEW_OBJECTS', 'view fedora repository objects'); -define('FEDORA_MANAGE_DATASTREAMS', 'view fedora repository datastreams'); define('FEDORA_METADATA_EDIT', 'edit fedora metadata'); define('FEDORA_ADD_DS', 'add fedora datastreams'); define('FEDORA_INGEST', 'ingest fedora objects'); @@ -38,6 +37,8 @@ define('FEDORA_MANAGE_PROPERTIES', 'manage object properties'); // Hooks. define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); +define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object'); define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); + // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); define('ISLANDORA_OBJECT_MODIFIED_HOOK', 'islandora_object_modified'); @@ -105,18 +106,17 @@ function islandora_menu() { ); $items['islandora/object/%islandora_object/manage'] = array( 'title' => 'Manage', - 'page callback' => 'islandora_edit_object', + 'page callback' => 'islandora_manage_overview_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_object_manage_access_callback', - 'access arguments' => array( - array(FEDORA_MANAGE_DATASTREAMS, FEDORA_MANAGE_PROPERTIES, FEDORA_ADD_DS), 2), - ); - $items['islandora/object/%islandora_object/manage/datastreams'] = array( - 'title' => 'Datastreams', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, + 'access arguments' => array(array(FEDORA_MANAGE_PROPERTIES, FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE), 2), ); + + $items['islandora/object/%islandora_object/manage/overview'] = array( 'title' => 'Overview', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); + + $items['islandora/object/%islandora_object/manage/datastreams'] = array( 'title' => 'Datastreams', 'type' => MENU_LOCAL_TASK, 'page callback' => 'islandora_edit_object', 'page arguments' => array(2), 'access callback' => 'islandora_object_manage_access_callback', 'access arguments' => array(array(FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE), 2), 'weight' => -10, ); + $items['islandora/object/%islandora_object/manage/properties'] = array( 'title' => 'Properties', 'page callback' => 'drupal_get_form', @@ -256,10 +256,6 @@ function islandora_permission() { 'title' => t('View repository objects'), 'description' => t('View objects in the repository. Note: Fedora XACML security policies may override this permission.'), ), - FEDORA_MANAGE_DATASTREAMS => array( - 'title' => t('Manage repository object datastreams'), - 'description' => t('Manage datastreams of objects in the repository. Note: Fedora XACML security policies may override this permission.'), - ), FEDORA_ADD_DS => array( 'title' => t('Add datastreams to repository objects'), 'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.'), @@ -405,13 +401,7 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { } /** - * Renders the given objects manage page. - * - * Its possible to modify the output of this function if 'ISLANDORA_EDIT_HOOK' - * is implemented in other modules. - * - * If no modules implement 'ISLANDORA_EDIT_HOOK' then this function returns the - * default manage view. + * Renders the given objects manage overview page. * * @param FedoraObject $object * The object to manage. @@ -419,6 +409,9 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { * @return string * The HTML repersentation of the manage object page. */ + +function islandora_manage_overview_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); $output = array(); //return $output; foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } } if (empty($output)) { // Add in the default, if we did not get any results. $output = islandora_default_islandora_manage_overview_object($object); } arsort($output); drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); return implode('', $output); } /** * Renders the default manage object page for the given object. * * @param FedoraObject $object * The object used to render the manage object page. * * @return array * The default rendering of the object manage page, indexed at * 'Default Edit output'. */ function islandora_default_islandora_manage_overview_object(FedoraObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); return array('Default overview output' => $output); } /** * Renders the given objects manage page. * * Its possible to modify the output of this function if 'ISLANDORA_EDIT_HOOK' * is implemented in other modules. * * If no modules implement 'ISLANDORA_EDIT_HOOK' then this function returns the * default manage view. * * @param FedoraObject $object * The object to manage. * * @return string * The HTML repersentation of the manage object page. */ + function islandora_edit_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/utilities'); diff --git a/tests/islandora_manage_permissions.test b/tests/islandora_manage_permissions.test new file mode 100644 index 00000000..76f43a6d --- /dev/null +++ b/tests/islandora_manage_permissions.test @@ -0,0 +1,78 @@ + 'Islandora Manage Permissions', + 'description' => 'Ensure the manage tab is shown based on the corrent permissions.', + 'group' => 'Islandora', + ); + } + + public function setUp() { + parent::setUp(array('islandora')); + } + + public function testManagePermissions() { + + + // permission FEDORA_VIEW_OBJECTS + // create a user with permission + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); + // log the user in + $this->drupalLogin($user); + $this->clickLink(t('Islandora Repository')); + $this->assertNoLink('Manage', 'Manage tab is not on current page.'); + + + // permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES)); + // log the user in + $this->drupalLogin($user); + $this->clickLink(t('Islandora Repository')); + $this->assertLink('Manage', 0, 'Manage tab is on current page.'); + $this->clickLink(t('Manage')); + $this->assertLink('Properties', 0, 'Properties tab is on current page.'); + $this->assertNoLink('Datastreams', 'Datastreams tab is not on current page.'); + $this->assertNoLink('Collection','Collection tab is not on current page.'); + + + // permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS)); + // log the user in + $this->drupalLogin($user); + $this->clickLink(t('Islandora Repository')); + $this->assertLink('Manage', 0, 'Manage tab is on current page.'); + $this->clickLink(t('Manage')); + $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); + $this->assertNoLink('Properties', 'Properties tab is not on current page.'); + $this->assertNoLink('Collection','Collection tab is not on current page.'); + + + // permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT)); + // log the user in + $this->drupalLogin($user); + $this->clickLink(t('Islandora Repository')); + $this->assertLink('Manage', 0, 'Manage tab is on current page.'); + $this->clickLink(t('Manage')); + $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); + $this->assertNoLink('Properties', 'Properties tab is not on current page.'); + $this->assertNoLink('Collection','Collection tab is not on current page.'); + + + // permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE)); + // log the user in + $this->drupalLogin($user); + $this->clickLink(t('Islandora Repository')); + $this->assertLink('Manage', 0, 'Manage tab is on current page.'); + $this->clickLink(t('Manage')); + $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); + $this->assertNoLink('Properties', 'Properties tab is not on current page.'); + $this->assertNoLink('Collection','Collection tab is not on current page.'); + + } + + } \ No newline at end of file From 47718e57ca6efa11ba2447380601c38a10274ca9 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 26 Feb 2013 10:29:44 +0100 Subject: [PATCH 2/2] Code Review * Removed Windows line endings (^M). * Applied Coding Standards. --- islandora.module | 92 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/islandora.module b/islandora.module index 10cc1cb4..d5287286 100644 --- a/islandora.module +++ b/islandora.module @@ -37,7 +37,11 @@ define('FEDORA_MANAGE_PROPERTIES', 'manage object properties'); // Hooks. define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); -define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object'); define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); +define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object'); +define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); +define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); +define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); +define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); @@ -110,13 +114,36 @@ function islandora_menu() { 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_object_manage_access_callback', - 'access arguments' => array(array(FEDORA_MANAGE_PROPERTIES, FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE), 2), + 'access arguments' => array( + array( + FEDORA_MANAGE_PROPERTIES, + FEDORA_METADATA_EDIT, + FEDORA_ADD_DS, + FEDORA_PURGE, + ), 2), ); - - $items['islandora/object/%islandora_object/manage/overview'] = array( 'title' => 'Overview', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); - - $items['islandora/object/%islandora_object/manage/datastreams'] = array( 'title' => 'Datastreams', 'type' => MENU_LOCAL_TASK, 'page callback' => 'islandora_edit_object', 'page arguments' => array(2), 'access callback' => 'islandora_object_manage_access_callback', 'access arguments' => array(array(FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE), 2), 'weight' => -10, ); - + + $items['islandora/object/%islandora_object/manage/overview'] = array( + 'title' => 'Overview', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -20, + ); + + $items['islandora/object/%islandora_object/manage/datastreams'] = array( + 'title' => 'Datastreams', + 'type' => MENU_LOCAL_TASK, + 'page callback' => 'islandora_edit_object', + 'page arguments' => array(2), + 'access callback' => 'islandora_object_manage_access_callback', + 'access arguments' => array( + array( + FEDORA_METADATA_EDIT, + FEDORA_ADD_DS, + FEDORA_PURGE, + ), 2), + 'weight' => -10, + ); + $items['islandora/object/%islandora_object/manage/properties'] = array( 'title' => 'Properties', 'page callback' => 'drupal_get_form', @@ -409,9 +436,54 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { * @return string * The HTML repersentation of the manage object page. */ - -function islandora_manage_overview_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); $output = array(); //return $output; foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } } if (empty($output)) { // Add in the default, if we did not get any results. $output = islandora_default_islandora_manage_overview_object($object); } arsort($output); drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); return implode('', $output); } /** * Renders the default manage object page for the given object. * * @param FedoraObject $object * The object used to render the manage object page. * * @return array * The default rendering of the object manage page, indexed at * 'Default Edit output'. */ function islandora_default_islandora_manage_overview_object(FedoraObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); return array('Default overview output' => $output); } /** * Renders the given objects manage page. * * Its possible to modify the output of this function if 'ISLANDORA_EDIT_HOOK' * is implemented in other modules. * * If no modules implement 'ISLANDORA_EDIT_HOOK' then this function returns the * default manage view. * * @param FedoraObject $object * The object to manage. * * @return string * The HTML repersentation of the manage object page. */ - +function islandora_manage_overview_object(FedoraObject $object) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $output = array(); + foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { + $temp = module_invoke_all($hook, $object); + if (!empty($temp)) { + $output = array_merge_recursive($output, $temp); + } + } + if (empty($output)) { + // Add in the default, if we did not get any results. + $output = islandora_default_islandora_manage_overview_object($object); + } + arsort($output); + drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); + return implode('', $output); +} + +/** + * Renders the default manage object page for the given object. + * + * @param FedoraObject $object + * The object used to render the manage object page. + * + * @return array + * The default rendering of the object manage page, indexed at + * 'Default Edit output'. + */ +function islandora_default_islandora_manage_overview_object(FedoraObject $object) { + $output = theme('islandora_default_overview', array('islandora_object' => $object)); + return array('Default overview output' => $output); +} + +/** + * Renders the given objects manage page. + * + * Its possible to modify the output of this function if 'ISLANDORA_EDIT_HOOK' + * is implemented in other modules. + * + * If no modules implement 'ISLANDORA_EDIT_HOOK' then this function returns the + * default manage view. + * + * @param FedoraObject $object + * The object to manage. + * + * @return string + * The HTML repersentation of the manage object page. + */ function islandora_edit_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/utilities');