From 833286e8b8ec887580c44d3afb85012f75e6f2ca Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Mon, 4 Feb 2013 13:37:20 -0400 Subject: [PATCH 1/8] Manage Permissions tab changes --- islandora.info | 1 + islandora.module | 71 +++++++++++++++++++--- tests/islandora_manage_permissions.test | 78 +++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 tests/islandora_manage_permissions.test diff --git a/islandora.info b/islandora.info index d883aa49..419f633b 100644 --- a/islandora.info +++ b/islandora.info @@ -12,4 +12,5 @@ files[] = includes/IslandoraTuque.inc files[] = includes/IslandoraTuqueWrapper.inc files[] = tests/islandora_web_test_case.inc files[] = tests/islandora_authtokens.test +files[] = tests/islandora_manage_permissions.test php = 5.3 diff --git a/islandora.module b/islandora.module index 05b55cc8..2ddccc77 100644 --- a/islandora.module +++ b/islandora.module @@ -27,7 +27,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'); @@ -37,6 +36,7 @@ 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'); @@ -104,15 +104,25 @@ function islandora_menu() { ); $items['islandora/object/%islandora_object/manage'] = array( 'title' => 'Manage', - 'page callback' => 'islandora_edit_object', + 'page callback' => 'islandora_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), + '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_DEFAULT_LOCAL_TASK, + '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( @@ -254,10 +264,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.') @@ -414,6 +420,55 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { return $has_access && is_object($object) && islandora_namespace_accessible($object->id); } +/** + * 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_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_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_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. * 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 17aa18157f7ec4aa3d9286e9fd645fce02b0a990 Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Thu, 7 Feb 2013 09:38:47 -0400 Subject: [PATCH 2/8] made changes to manage permissions from codereview ticket 853 --- .gitignore | 20 ++++++++++++++++++++ islandora.module | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1133add7..c432e384 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,22 @@ cache.properties .DS_Store + +islandora.info~ + +includes/solution_packs.inc~ + +islandora.module~ + +tests/islandora_authtokens.test~ + +tests/islandora_basic_collection_manage_permissions.test~ + +tests/islandora_manage_perm.test~ + +tests/islandora_manage_permissions.test~ + +tests/islandora_web_test_case.inc~ + +theme/islandora-object.tpl.php~ + +theme/islandora.theme.inc~ diff --git a/islandora.module b/islandora.module index 2ddccc77..421994ae 100644 --- a/islandora.module +++ b/islandora.module @@ -104,7 +104,7 @@ function islandora_menu() { ); $items['islandora/object/%islandora_object/manage'] = array( 'title' => 'Manage', - 'page callback' => 'islandora_overview_object', + 'page callback' => 'islandora_manage_overview_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_object_manage_access_callback', @@ -435,7 +435,7 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { * @return string * The HTML repersentation of the manage object page. */ -function islandora_overview_object(FedoraObject $object) { +function islandora_manage_overview_object(FedoraObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); $output = array(); //return $output; @@ -447,7 +447,7 @@ function islandora_overview_object(FedoraObject $object) { } if (empty($output)) { // Add in the default, if we did not get any results. - $output = islandora_default_islandora_overview_object($object); + $output = islandora_default_islandora_manage_overview_object($object); } arsort($output); drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); @@ -464,7 +464,7 @@ function islandora_overview_object(FedoraObject $object) { * The default rendering of the object manage page, indexed at * 'Default Edit output'. */ -function islandora_default_islandora_overview_object(FedoraObject $object) { +function islandora_default_islandora_manage_overview_object(FedoraObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); return array('Default overview output' => $output); } From 755981bd4dbf5f7da75ff2dec3581701cb65799a Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Sat, 16 Feb 2013 15:51:22 -0400 Subject: [PATCH 3/8] forgot another conflict --- islandora.module | 7 ------- 1 file changed, 7 deletions(-) diff --git a/islandora.module b/islandora.module index 12797e2a..70c51598 100644 --- a/islandora.module +++ b/islandora.module @@ -270,13 +270,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.'), ), -<<<<<<< HEAD -======= - 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.'), - ), ->>>>>>> e3ca25cd3329b4a1c7025947a5d88dadeb36b9e8 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.'), From a16257e42348a48841c392366e398969774ce060 Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Wed, 20 Feb 2013 10:48:42 -0400 Subject: [PATCH 4/8] removing .gitignore --- .gitignore | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 9b07bbb0..00000000 --- a/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -cache.properties -.DS_Store - -islandora.info~ - -includes/solution_packs.inc~ - -islandora.module~ - -tests/islandora_authtokens.test~ - -tests/islandora_basic_collection_manage_permissions.test~ - -tests/islandora_manage_perm.test~ - -tests/islandora_manage_permissions.test~ - -tests/islandora_web_test_case.inc~ - -theme/islandora-object.tpl.php~ - -theme/islandora.theme.inc~ - -tests/test_config.ini - From dfe3f8598ec395fd5dd082e3c0c1555f689e8f2d Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Wed, 20 Feb 2013 11:09:42 -0400 Subject: [PATCH 5/8] Revert "removing .gitignore" This reverts commit a16257e42348a48841c392366e398969774ce060. --- .gitignore | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9b07bbb0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +cache.properties +.DS_Store + +islandora.info~ + +includes/solution_packs.inc~ + +islandora.module~ + +tests/islandora_authtokens.test~ + +tests/islandora_basic_collection_manage_permissions.test~ + +tests/islandora_manage_perm.test~ + +tests/islandora_manage_permissions.test~ + +tests/islandora_web_test_case.inc~ + +theme/islandora-object.tpl.php~ + +theme/islandora.theme.inc~ + +tests/test_config.ini + From 0696ddfe39d22c94db064fc0a94d0f8fc59cdaea Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Wed, 20 Feb 2013 12:41:13 -0400 Subject: [PATCH 6/8] added in files[] = tests/islandora_authtokens.test --- islandora.info | 1 + 1 file changed, 1 insertion(+) diff --git a/islandora.info b/islandora.info index 70df8232..d4b4887f 100644 --- a/islandora.info +++ b/islandora.info @@ -15,4 +15,5 @@ files[] = tests/islandora_web_test_case.inc files[] = tests/islandora_authtokens.test files[] = tests/islandora_manage_permissions.test files[] = tests/hooks.test +files[] = tests/islandora_authtokens.test php = 5.3 From 4b182ff16ce712bfbd1291aec723303142db095f Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Wed, 20 Feb 2013 13:18:42 -0400 Subject: [PATCH 7/8] fixing thev authtokens test --- islandora.info | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/islandora.info b/islandora.info index d4b4887f..5f8601fc 100644 --- a/islandora.info +++ b/islandora.info @@ -12,8 +12,7 @@ files[] = includes/islandora_tuque.inc files[] = includes/islandora_tuque_wrapper.inc files[] = includes/islandora_object.entity_controller.inc files[] = tests/islandora_web_test_case.inc -files[] = tests/islandora_authtokens.test files[] = tests/islandora_manage_permissions.test files[] = tests/hooks.test -files[] = tests/islandora_authtokens.test +files[] = tests/authtokens.test php = 5.3 From e7bdfc3d108c064245848416fd09db862ae1099e Mon Sep 17 00:00:00 2001 From: Phil Soga Date: Thu, 21 Feb 2013 13:42:20 -0400 Subject: [PATCH 8/8] there were problems with the naming convention --- islandora.info | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/islandora.info b/islandora.info index 5f8601fc..2eb5742b 100644 --- a/islandora.info +++ b/islandora.info @@ -8,11 +8,11 @@ stylesheets[all][] = css/islandora.base.css stylesheets[all][] = css/islandora.theme.css files[] = includes/mime_detect.inc files[] = includes/dublin_core.inc -files[] = includes/islandora_tuque.inc -files[] = includes/islandora_tuque_wrapper.inc -files[] = includes/islandora_object.entity_controller.inc -files[] = tests/islandora_web_test_case.inc +files[] = includes/tuque.inc +files[] = includes/tuque_wrapper.inc +files[] = includes/object.entity_controller.inc +files[] = tests/web_test_case.inc +files[] = tests/authtokens.test files[] = tests/islandora_manage_permissions.test files[] = tests/hooks.test -files[] = tests/authtokens.test php = 5.3