From 304de866da664492d918559445219c3556ba51fd Mon Sep 17 00:00:00 2001 From: guy_schneerson Date: Thu, 29 Jan 2015 16:05:10 +0000 Subject: [PATCH] #59 Add ctolls/page manager support for access checks --- .../access/kendra_user_access_ctools.inc | 65 +++++++++++++++++++ .../custom/kendra_user/kendra_user.info | 5 +- .../custom/kendra_user/kendra_user.module | 17 ++++- 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 sites/all/modules/custom/kendra_user/includes/plugins/access/kendra_user_access_ctools.inc diff --git a/sites/all/modules/custom/kendra_user/includes/plugins/access/kendra_user_access_ctools.inc b/sites/all/modules/custom/kendra_user/includes/plugins/access/kendra_user_access_ctools.inc new file mode 100644 index 00000000..0ba6d173 --- /dev/null +++ b/sites/all/modules/custom/kendra_user/includes/plugins/access/kendra_user_access_ctools.inc @@ -0,0 +1,65 @@ + t('Kendra Access Asset'), + 'description' => t('Control access according Asset or its related types.'), + 'callback' => 'kendra_user_ctools_access_check', + 'default' => array('name' => ''), + 'settings form' => 'kendra_user_access_ctools_access_settings', + 'settings form submit' => 'kendra_user_access_ctools_access_settings_submit', + 'summary' => 'kendra_user_ctools_access_summary', + 'all contexts' => TRUE, +); + +/** + * Settings form for the path_access access plugin + */ +function kendra_user_access_ctools_access_settings($form, &$form_state, $conf) { + $form['settings']['name'] = array( + '#title' => t('name'), + '#type' => 'textfield', + '#description' => t('name'), + '#default_value' => $conf['name'], + ); + return $form; +} + +/** + * Validation for the settings form for the access plugin + */ +function kendra_user_access_ctools_access_settings_validate($form, &$form_state, $conf) { + if (url_is_external($form_state['values']['name'])) { + form_set_error('name', t('Please supply aname')); + } +} + +/** + * Check for access. + */ +function kendra_user_ctools_access_check($conf, $context) { + global $user; + return kendra_user_can_specified_user_edit_asset($user); +} + + +/** + * Provide a summary description based upon the checked path_accesss. + */ +function kendra_user_ctools_access_summary($conf, $context) { + if (!empty($conf['name'])) { + $text = $conf['name']; + } + else { + $text = ''; + } + + return t('Logged in user has access to !text', array('!text' => $text)); +} diff --git a/sites/all/modules/custom/kendra_user/kendra_user.info b/sites/all/modules/custom/kendra_user/kendra_user.info index 27c3474d..b479e1ab 100644 --- a/sites/all/modules/custom/kendra_user/kendra_user.info +++ b/sites/all/modules/custom/kendra_user/kendra_user.info @@ -3,6 +3,9 @@ description = Provide User access control and other functionality. package = Kendra core = 7.x dependencies[] = rules +dependencies[] = ctools ; Views plugin -files[] = includes/plugins/kendra_user_views_plugin_access.inc \ No newline at end of file +files[] = includes/plugins/kendra_user_views_plugin_access.inc +; Ctools plugins +files[] = includes/plugins/access/kendra_user_access_ctools.inc diff --git a/sites/all/modules/custom/kendra_user/kendra_user.module b/sites/all/modules/custom/kendra_user/kendra_user.module index 43c3c3d4..3879bf33 100644 --- a/sites/all/modules/custom/kendra_user/kendra_user.module +++ b/sites/all/modules/custom/kendra_user/kendra_user.module @@ -16,6 +16,15 @@ function kendra_user_views_api() { ); } +/** + * Implements hook_ctools_plugin_directory() to let the system know + * where our task and task_handler plugins are. + */ +function kendra_user_ctools_plugin_directory($owner, $plugin_type) { + if ($owner == 'ctools' && $plugin_type == 'access') { + return 'includes/plugins/access'; + } +} /** * Checks if the curent user allowed to edit the asset. @@ -92,12 +101,16 @@ function kendra_user_can_specified_user_edit_specified_asset($user, $node) { } break; - case 'sync-request': + case 'sync_request': // If a kendra admin. if (in_array('kendra', $user->roles)) { // Then he can edit the asset. return TRUE; } + // Request owner + if ($node->uid == $user->uid) { + return TRUE; + } // If user has an asset author role. if (in_array('Asset Author', $user->roles)) { // We will get the asset node from the contribution. @@ -130,4 +143,4 @@ function kendra_user_can_specified_user_edit_specified_asset($user, $node) { return FALSE; break; } -} \ No newline at end of file +}