chg: [internal] AppController code cleanup

pull/7769/head
Jakub Onderka 2021-09-26 13:21:55 +02:00
parent 6c223a62e6
commit 1262b6124c
1 changed files with 10 additions and 17 deletions

View File

@ -129,9 +129,9 @@ class AppController extends Controller
$this->sql_dump = intval($this->request->params['named']['sql']);
}
$this->_setupDebugMode();
$this->_setupDatabaseConnection();
$this->set('debugMode', Configure::read('debug') >= 1 ? 'debugOn' : 'debugOff');
$this->set('ajax', $this->request->is('ajax'));
$this->set('queryVersion', $this->__queryVersion);
$this->User = ClassRegistry::init('User');
@ -623,7 +623,7 @@ class AppController extends Controller
if (!isset($actionsToCheck[$controller])) {
return false;
}
return in_array($this->request->action, $actionsToCheck[$controller], true);
return in_array($this->request->params['action'], $actionsToCheck[$controller], true);
}
/**
@ -644,7 +644,7 @@ class AppController extends Controller
$remoteAddress = $this->_remoteIp();
$pipe = $redis->multi(Redis::PIPELINE);
$pipe = $redis->pipeline();
// keep for 30 days
$pipe->setex('misp:ip_user:' . $remoteAddress, 60 * 60 * 24 * 30, $user['id']);
$pipe->sadd('misp:user_ip:' . $user['id'], $remoteAddress);
@ -801,18 +801,12 @@ class AppController extends Controller
return $this->RestResponse->viewData($this->ACL->$debugType($content), 'json');
}
/*
* Configure the debugMode view parameter
*/
protected function _setupDebugMode() {
$this->set('debugMode', (Configure::read('debug') >= 1) ? 'debugOn' : 'debugOff');
}
/*
* Setup & validate the database connection configuration
* @throws Exception if the configured database is not supported.
*/
protected function _setupDatabaseConnection() {
protected function _setupDatabaseConnection()
{
// check for a supported datasource configuration
$dataSourceConfig = ConnectionManager::getDataSource('default')->config;
if (!isset($dataSourceConfig['encoding'])) {
@ -1236,15 +1230,14 @@ class AppController extends Controller
}
if (isset($filters['returnFormat'])) {
$returnFormat = $filters['returnFormat'];
if ($returnFormat === 'download') {
$returnFormat = 'json';
} else if ($returnFormat === 'stix' && $this->IndexFilter->isJson()) {
$returnFormat = 'stix-json';
}
} else {
$returnFormat = 'json';
}
if ($returnFormat === 'download') {
$returnFormat = 'json';
}
if ($returnFormat === 'stix' && $this->IndexFilter->isJson()) {
$returnFormat = 'stix-json';
}
$elementCounter = 0;
$renderView = false;
$responseType = empty($model->validFormats[$returnFormat][0]) ? 'json' : $model->validFormats[$returnFormat][0];