Drupal module permissions

Posted by Trevor Newhook on Stack Overflow See other posts from Stack Overflow or by Trevor Newhook
Published on 2012-08-29T04:29:12Z Indexed on 2012/08/29 21:38 UTC
Read the original article Hit count: 255

Filed under:
|
|

When I run the code with an admin user, the module returns what it should. However, when I run it with a normal user, I get a 403 error. The module returns data from an AJAX call. I've already tried adding a 'access callback' => 'user_access'); line to the exoticlang_chat_logger_menu() function. I'd appreciate any pointers you might have.

Thanks for the help

The AJAX call:

jQuery.ajax({
    type: 'POST',
    url: '/chatlog',
    success: exoticlangAjaxCompleted,
    data:'messageLog=' + privateMessageLogJson,
    dataType: 'json'
});

The module code:

function exoticlang_chat_logger_init(){
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system', 'drupal.ajax');
}

function exoticlang_chat_logger_permission() {
  return array(
    'Save chat data' => array(
      'title' => t('Save ExoticLang Chat Data'),
      'description' => t('Send private message on chat close')
    ),
  );
}

/**
 * Implementation of hook_menu().
 */

function exoticlang_chat_logger_menu() {
    $items = array();
    $items['chatlog'] = array(
    'type'             => MENU_CALLBACK,
    'page callback'    => 'exoticlang_chat_log_ajax',
    'access arguments' => 'Save chat data');
    //'access callback' => 'user_access');
    return $items;
}

function exoticlang_chat_logger_ajax(){
    $messageLog=stripslashes($_POST['messageLog']);

    $chatLog= 'Drupal has processed this. Message log is: '.$messageLog;
    $chatLog=str_replace('":"{[{','":[{',$chatLog);
    $chatLog=str_replace(',,',',',$chatLog);
    $chatLog=str_replace('"}"','"}',$chatLog);
    $chatLog=str_replace('"}]}"','"}]',$chatLog);

     echo json_encode(array('messageLog' => $chatLog));
//    echo $chatLog;

    echo print_r(privatemsg_new_thread(array(user_load(1)), 'The subject', 'The body text'));
    drupal_exit();
}

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about drupal-7