chg: [internal] Fix session closing for dashboard widget

pull/7986/head
Jakub Onderka 2021-11-25 12:13:58 +01:00
parent cb41232777
commit 832f82933a
2 changed files with 4 additions and 4 deletions

View File

@ -154,6 +154,7 @@ class DashboardsController extends AppController
throw new MethodNotAllowedException(__('This endpoint can only be reached via POST requests.'));
}
$user = $this->Auth->user();
@session_write_close(); // allow concurrent AJAX requests (session hold lock by default)
if (empty($this->request->data['data'])) {
@ -164,10 +165,10 @@ class DashboardsController extends AppController
}
$value = $this->request->data['data'];
$valueConfig = json_decode($value['config'], true);
$dashboardWidget = $this->Dashboard->loadWidget($this->Auth->user(), $value['widget']);
$dashboardWidget = $this->Dashboard->loadWidget($user, $value['widget']);
$redis = $this->Dashboard->setupRedis();
$org_scope = $this->_isSiteAdmin() ? 0 : $this->Auth->user('org_id');
$org_scope = $this->_isSiteAdmin() ? 0 : $user['org_id'];
$lookup_hash = hash('sha256', $value['widget'] . $value['config']);
$cacheKey = 'misp:dashboard:' . $org_scope . ':' . $lookup_hash;
$data = $redis->get($cacheKey);
@ -175,7 +176,7 @@ class DashboardsController extends AppController
$dashboardWidget->cacheLifetime = false;
}
if (empty($dashboardWidget->cacheLifetime) || empty($data)) {
$data = $dashboardWidget->handler($this->Auth->user(), $valueConfig);
$data = $dashboardWidget->handler($user, $valueConfig);
if (!empty($dashboardWidget->cacheLifetime)) {
$redis->setex($cacheKey, $dashboardWidget->cacheLifetime, json_encode(array('data' => $data)));
}

View File

@ -41,7 +41,6 @@ class Dashboard extends AppModel
$subDirectories = $customdir->read();
$found = false;
foreach ($subDirectories[0] as $subDir) {
$currentDir = new Folder(APP . 'Lib/Dashboard/' . $subDir);
if (file_exists(APP . 'Lib/Dashboard/Custom/' . $subDir . '/' . $name . '.php')) {
App::uses($name, 'Dashboard/Custom/' . $subDir);
$found = true;