Drupal模块权限

时间:2012-08-29 04:29:13

标签: ajax drupal-7 user-permissions

当我使用admin用户运行代码时,模块会返回它应该的内容。但是,当我用普通用户运行它时,我收到403错误。该模块从AJAX调用返回数据。我已经尝试添加'访问回调'=> 'user_access'); 排到 exoticlang_chat_logger_menu()函数。我很感激你可能有的任何指示。

感谢您的帮助

AJAX电话:

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

模块代码:

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();
}

1 个答案:

答案 0 :(得分:2)

access arguments需要是一个数组:

$items['chatlog'] = array(
  'type'             => MENU_CALLBACK,
  'page callback'    => 'exoticlang_chat_log_ajax',
  'access arguments' => array('Save chat data')
);