Skip to content

Commit

Permalink
#59 Add ctolls/page manager support for access checks
Browse files Browse the repository at this point in the history
  • Loading branch information
BBGuy committed Jan 29, 2015
1 parent 197f480 commit 304de86
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @file
* Plugin to provide access control
*/

/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => 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));
}
5 changes: 4 additions & 1 deletion sites/all/modules/custom/kendra_user/kendra_user.info
Original file line number Diff line number Diff line change
Expand Up @@ -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
files[] = includes/plugins/kendra_user_views_plugin_access.inc
; Ctools plugins
files[] = includes/plugins/access/kendra_user_access_ctools.inc
17 changes: 15 additions & 2 deletions sites/all/modules/custom/kendra_user/kendra_user.module
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -130,4 +143,4 @@ function kendra_user_can_specified_user_edit_specified_asset($user, $node) {
return FALSE;
break;
}
}
}

0 comments on commit 304de86

Please sign in to comment.