mirror of https://github.com/MISP/MISP
new: [user:periodicReporting] Allow setting the number of days to look back (UI only)
parent
c6649da139
commit
664504f7f6
|
@ -2984,7 +2984,8 @@ class UsersController extends AppController
|
|||
public function viewPeriodicSummary(string $period)
|
||||
{
|
||||
$userId = $this->Auth->user('id');
|
||||
$summary = $this->User->generatePeriodicSummary($userId, $period);
|
||||
$lastdays = $this->request->params['named']['lastdays'] ?? false;
|
||||
$summary = $this->User->generatePeriodicSummary($userId, $period, true, $lastdays);
|
||||
$periodicSettings = $this->User->fetchPeriodicSettingForUser($userId);
|
||||
$this->set('periodic_settings', $periodicSettings);
|
||||
$this->set('summary', $summary);
|
||||
|
|
|
@ -1716,10 +1716,10 @@ class User extends AppModel
|
|||
* @param string $period
|
||||
* @return array
|
||||
*/
|
||||
private function getUsablePeriodicSettingForUser(array $period_filters, $period='daily'): array
|
||||
private function getUsablePeriodicSettingForUser(array $period_filters, $period='daily', $lastdays=7): array
|
||||
{
|
||||
$filters = [
|
||||
'last' => $this->__genTimerangeFilter($period),
|
||||
'last' => $this->__genTimerangeFilter($period, $lastdays),
|
||||
'published' => true,
|
||||
];
|
||||
if (!empty($period_filters['orgc_id'])) {
|
||||
|
@ -1812,11 +1812,12 @@ class User extends AppModel
|
|||
* @throws InvalidArgumentException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function generatePeriodicSummary(int $userId, string $period, $rendered = true)
|
||||
public function generatePeriodicSummary(int $userId, string $period, $rendered = true, $lastdays=7)
|
||||
{
|
||||
$allowedPeriods = array_map(function($period) {
|
||||
return substr($period, strlen('notification_'));
|
||||
}, self::PERIODIC_NOTIFICATIONS);
|
||||
$allowedPeriods[] = 'custom';
|
||||
if (!in_array($period, $allowedPeriods, true)) {
|
||||
throw new InvalidArgumentException(__('Invalid period. Must be one of %s', JsonTool::encode(self::PERIODIC_NOTIFICATIONS)));
|
||||
}
|
||||
|
@ -1824,7 +1825,7 @@ class User extends AppModel
|
|||
$user = $this->getAuthUser($userId);
|
||||
App::import('Tools', 'SendEmail');
|
||||
$periodicSettings = $this->fetchPeriodicSettingForUser($userId, true);
|
||||
$filters = $this->getUsablePeriodicSettingForUser($periodicSettings, $period);
|
||||
$filters = $this->getUsablePeriodicSettingForUser($periodicSettings, $period, $lastdays);
|
||||
$filtersForRestSearch = $filters; // filters for restSearch are slightly different than fetchEvent
|
||||
$filters['last'] = $this->resolveTimeDelta($filters['last']);
|
||||
$filters['sgReferenceOnly'] = true;
|
||||
|
@ -1854,7 +1855,7 @@ class User extends AppModel
|
|||
$finalContext = JsonTool::decode($finalContext->intoString());
|
||||
$aggregated_context = $this->__renderAggregatedContext($finalContext);
|
||||
$rollingWindows = $periodicSettings['trending_period_amount'] ?: 2;
|
||||
$trendAnalysis = $this->Event->getTrendsForTagsFromEvents($events, $this->periodToDays($period), $rollingWindows, $periodicSettings['trending_for_tags']);
|
||||
$trendAnalysis = $this->Event->getTrendsForTagsFromEvents($events, $this->periodToDays($period, $lastdays), $rollingWindows, $periodicSettings['trending_for_tags']);
|
||||
$tagFilterPrefixes = $periodicSettings['trending_for_tags'] ?: array_keys($trendAnalysis['all_tags']);
|
||||
$trendData = [
|
||||
'trendAnalysis' => $trendAnalysis,
|
||||
|
@ -1866,12 +1867,13 @@ class User extends AppModel
|
|||
];
|
||||
$security_recommendations = $this->__renderSecurityRecommendations($securityRecommendationsData);
|
||||
|
||||
$emailTemplate = $this->prepareEmailTemplate($period);
|
||||
$templateName = $period == 'custom' ? 'daily' : $period;
|
||||
$emailTemplate = $this->prepareEmailTemplate($templateName);
|
||||
$emailTemplate->set('baseurl', $this->Event->__getAnnounceBaseurl());
|
||||
$emailTemplate->set('events', $events);
|
||||
$emailTemplate->set('filters', $filters);
|
||||
$emailTemplate->set('periodicSettings', $periodicSettings);
|
||||
$emailTemplate->set('period_days', $this->periodToDays($period));
|
||||
$emailTemplate->set('period_days', $this->periodToDays($period, $lastdays));
|
||||
$emailTemplate->set('period', $period);
|
||||
$emailTemplate->set('aggregated_context', $aggregated_context);
|
||||
$emailTemplate->set('trending_summary', $trending_summary);
|
||||
|
@ -1937,13 +1939,19 @@ class User extends AppModel
|
|||
}
|
||||
return $filters;
|
||||
}
|
||||
private function __genTimerangeFilter(string $period='daily'): string
|
||||
private function __genTimerangeFilter(string $period='daily', $lastdays = 7): string
|
||||
{
|
||||
if ($period == 'custom') {
|
||||
return strval($lastdays) . 'd';
|
||||
}
|
||||
return $this->periodToDays($period) . 'd';
|
||||
}
|
||||
|
||||
private function periodToDays(string $period='daily'): int
|
||||
private function periodToDays(string $period='daily', $lastdays = false): int
|
||||
{
|
||||
if ($lastdays !== false) {
|
||||
return $lastdays;
|
||||
}
|
||||
if ($period === 'daily') {
|
||||
return 1;
|
||||
} else if ($period === 'weekly') {
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
<a class="btn <?= $period === 'weekly' ? 'btn-primary' : 'btn-inverse' ?>" href="<?= $baseurl . '/users/viewPeriodicSummary/weekly' ?>"><?= __('Weekly') ?></a>
|
||||
<a class="btn <?= $period === 'monthly' ? 'btn-primary' : 'btn-inverse' ?>" href="<?= $baseurl . '/users/viewPeriodicSummary/monthly' ?>"><?= __('Monthly') ?></a>
|
||||
</div>
|
||||
<div class="input-append" style="margin-bottom: 0;">
|
||||
<input class="span2" id="appendedInputButton" type="number" min="1" step="1" placeholder="<?= __('Number of days from today') ?>">
|
||||
<a class="btn <?= $period === 'custom' ? 'btn-primary' : 'btn-inverse' ?>" href="<?= $baseurl . '/users/viewPeriodicSummary/custom/lastdays:5' ?>"><?= __('Custom') ?></a>
|
||||
</div>
|
||||
|
||||
<h2><?= __('MISP %s summary', h($period)); ?></h2>
|
||||
|
||||
|
|
Loading…
Reference in New Issue