I currently am using Workbench and the WebForm module. While any workbench member can edit the WebForm, Workbench does not control access to the Results of the Webform. I wrote this module address this issue, however I am really new to Drupal and PHP (in fact this may be my first post) so I was hoping to get some feedback, I hope this is the right place to submit this.
/**
* Implementation of hook_webform_results_access().
* This hook determines if Results tab should be shown on WebForm
*/
function workbench_webform_access_webform_results_access($node, $account = NULL) {
return workbench_webform_access_webform_access($node,$account);
}
/**
* Implementation of hook_webform_submission_access().
* This hook determines if user can actually view submissions
*/
function workbench_webform_access_webform_submission_access($node, $submission, $op = 'view', $account = NULL) {
return workbench_webform_access_webform_access($node,$account);
}
/**
* Returns true if account has workbench access to this webform
*
* @param object $node
* The webform node.
* @param object $account
* The user account, optional. Defaults to current user.
*
* @return bool
* Returns true if user is listed, false otherwise.
*/
function workbench_webform_access_webform_access ($node, $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
$access = false;
//if node and user have workbench access settings, run through both and see if match occurs
if (isset($node->workbench_access) && isset($user->workbench_access)) {
foreach ($node->workbench_access as $i => $node_bench)
{
foreach($account->workbench_access as $a => $user_bench)
{
if($node_bench == $a){
$access=true;
}
}
}
}
//if user doesn't have workbench access settings loaded (occurs on results form in overlay)
//load the users tree and check
else if(isset($node->workbench_access))
{
$user_tree = workbench_access_get_access_tree();
foreach ($node->workbench_access as $i => $node_bench)
{
foreach($user_tree as $key => $value)
{
if($node_bench == $key){
$access=true;
}
}
}
}
return $access;
}
Comments
Comment #1
metzlerd commentedThis code is now being hosted as its own project. Am moving this issue to that project.
@thicknrich - Thanks for the contribution. If you'd like to come on board as a comaintainer let me know and I'll set it up and get you oriented.