0
当我用admin用户运行代码时,模块返回它应该的内容。但是,当我用普通用户运行它时,出现403错误。该模块从AJAX调用返回数据。我已经尝试添加'访问回调'=>'user_access');行exoticlang_chat_logger_menu()函数。我会很感激你可能有的任何指针。Drupal模块权限
感谢您的帮助
的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();
}
那是问题!万分感谢。但有一个问题 - 如果访问参数使用了错误的语法,为什么它对管理员用户有效? –
默认的访问回调是'user_access()',它给了管理员用户一个免费的通行证......基本上没有为该用户进行访问检查 – Clive