mirror of https://github.com/MISP/MISP
new: [Tag] Allow Tag's numerical_values to be overriden by userSettings
parent
bb167029eb
commit
314d9fab71
|
@ -552,6 +552,7 @@ class AppController extends Controller
|
|||
if (!empty($homepage)) {
|
||||
$this->set('homepage', $homepage['UserSetting']['value']);
|
||||
}
|
||||
Configure::write('user_id', $this->Auth->user('id'));
|
||||
}
|
||||
|
||||
private function __rateLimitCheck()
|
||||
|
|
|
@ -319,7 +319,15 @@ class DecayingModel extends AppModel
|
|||
);
|
||||
}
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['Tag'] = $tags[strtoupper($tag_name)]['Tag'];
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['Tag']['numerical_value'] = $entry['numerical_value'];
|
||||
// Take care of numerical_value override
|
||||
if (isset($tags[strtoupper($tag_name)]['Tag']['original_numerical_value']) && is_numeric($tags[strtoupper($tag_name)]['Tag']['original_numerical_value'])) {
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['original_numerical_value'] = $tags[strtoupper($tag_name)]['Tag']['original_numerical_value'];
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['numerical_value'] = $tags[strtoupper($tag_name)]['Tag']['numerical_value'];
|
||||
}
|
||||
// In some cases, tags may not have a numerical_value. Make sure it has one.
|
||||
if (empty($taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['Tag']['numerical_value']) && !empty($entry['numerical_value'])) {
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'][$e]['Tag']['numerical_value'] = $entry['numerical_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'])) {
|
||||
|
@ -341,8 +349,17 @@ class DecayingModel extends AppModel
|
|||
'colour' => 'grey',
|
||||
);
|
||||
}
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['Tag']['numerical_value'] = $predicate['numerical_value'];
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['numerical_predicate'] = true;
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['Tag']['numerical_value'] = $predicate['numerical_value'];
|
||||
// Take care of numerical_value override
|
||||
if (isset($tags[strtoupper($tag_name)]['Tag']['original_numerical_value']) && is_numeric($tags[strtoupper($tag_name)]['Tag']['original_numerical_value'])) {
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['original_numerical_value'] = $tags[strtoupper($tag_name)]['Tag']['original_numerical_value'];
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['numerical_value'] = $tags[strtoupper($tag_name)]['Tag']['numerical_value'];
|
||||
}
|
||||
// In some cases, tags may not have a numerical_value. Make sure it has one.
|
||||
if (empty($taxonomies[$namespace]['TaxonomyPredicate'][$p]['Tag']['numerical_value']) && !empty($predicate['numerical_value'])) {
|
||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['Tag']['numerical_value'] = $predicate['numerical_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,7 +375,6 @@ class DecayingModel extends AppModel
|
|||
$excluded_taxonomies[$namespace] = array('taxonomy' => $taxonomies[$namespace], 'reason' => __('No predicate'));
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'taxonomies' => $taxonomies,
|
||||
'excluded_taxonomies' => $excluded_taxonomies,
|
||||
|
|
|
@ -69,6 +69,8 @@ class Tag extends AppModel
|
|||
)
|
||||
);
|
||||
|
||||
private $tagOverrides = false;
|
||||
|
||||
public function beforeValidate($options = array())
|
||||
{
|
||||
parent::beforeValidate();
|
||||
|
@ -133,6 +135,12 @@ class Tag extends AppModel
|
|||
}
|
||||
}
|
||||
|
||||
public function afterFind($results, $primary = false)
|
||||
{
|
||||
$results = $this->checkForOverride($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function validateColour($fields)
|
||||
{
|
||||
if (!preg_match('/^#[0-9a-f]{6}$/i', $fields['colour'])) {
|
||||
|
@ -413,6 +421,28 @@ class Tag extends AppModel
|
|||
return ($this->saveAll($tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover user_id from the session and override numerical_values from userSetting
|
||||
*/
|
||||
public function checkForOverride($tags)
|
||||
{
|
||||
$userId = Configure::read('user_id');
|
||||
$this->UserSetting = ClassRegistry::init('UserSetting');
|
||||
if ($this->tagOverrides === false && $userId > 0) {
|
||||
$this->tagOverrides = $this->UserSetting->getTagNumericalValueOverride($userId);
|
||||
}
|
||||
foreach ($tags as $k => $tag) {
|
||||
if (isset($tag['Tag']['name'])) {
|
||||
$tagName = $tag['Tag']['name'];
|
||||
if (isset($this->tagOverrides[$tagName]) && is_numeric($this->tagOverrides[$tagName])) {
|
||||
$tags[$k]['Tag']['original_numerical_value'] = $tags[$k]['Tag']['numerical_value'];
|
||||
$tags[$k]['Tag']['numerical_value'] = $this->tagOverrides[$tagName];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function getTagsByName($tag_names, $containTagConnectors = true)
|
||||
{
|
||||
$contain = array('EventTag', 'AttributeTag');
|
||||
|
|
|
@ -287,7 +287,17 @@ class Taxonomy extends AppModel
|
|||
$tags = $this->Tag->getTagsByName($tag_names, false);
|
||||
if (isset($taxonomy['entries'])) {
|
||||
foreach ($taxonomy['entries'] as $key => $temp) {
|
||||
$taxonomy['entries'][$key]['existing_tag'] = isset($tags[strtoupper($temp['tag'])]) ? $tags[strtoupper($temp['tag'])] : false;
|
||||
if (isset($tags[strtoupper($temp['tag'])])) {
|
||||
$existingTag = $tags[strtoupper($temp['tag'])];
|
||||
$taxonomy['entries'][$key]['existing_tag'] = $existingTag;
|
||||
// numerical_value is overriden at tag level. Propagate the override further up
|
||||
if (isset($existingTag['Tag']['original_numerical_value'])) {
|
||||
$taxonomy['entries'][$key]['original_numerical_value'] = $existingTag['Tag']['original_numerical_value'];
|
||||
$taxonomy['entries'][$key]['numerical_value'] = $existingTag['Tag']['numerical_value'];
|
||||
}
|
||||
} else {
|
||||
$taxonomy['entries'][$key]['existing_tag'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,11 @@ class UserSetting extends AppModel
|
|||
)
|
||||
)
|
||||
),
|
||||
'tag_numerical_value_override' => array(
|
||||
'placeholder' => array(
|
||||
'false-positive:risk="medium"' => 99
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
// massage the data before we send it off for validation before saving anything
|
||||
|
@ -210,6 +215,22 @@ class UserSetting extends AppModel
|
|||
return $parameters;
|
||||
}
|
||||
|
||||
public function getTagNumericalValueOverride($userId)
|
||||
{
|
||||
$setting = $this->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array(
|
||||
'UserSetting.user_id' => $userId,
|
||||
'UserSetting.setting' => 'tag_numerical_value_override'
|
||||
)
|
||||
));
|
||||
$parameters = array();
|
||||
if (!empty($setting)) {
|
||||
$parameters = $setting['UserSetting']['value'];
|
||||
}
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the event is something the user is interested (to be alerted on)
|
||||
*
|
||||
|
|
|
@ -38,10 +38,19 @@
|
|||
<li>
|
||||
<a style="position: relative; padding: 3px 5px;">
|
||||
<span class="tagComplete"
|
||||
style="margin-right: 35px;background-color: <?php echo h($entry['Tag']['colour']); ?>;color:<?php echo h($this->TextColour->getTextColour($entry['Tag']['colour']));?>"
|
||||
style="margin-right:50px;background-color: <?php echo h($entry['Tag']['colour']); ?>;color:<?php echo h($this->TextColour->getTextColour($entry['Tag']['colour']));?>"
|
||||
title="<?php echo sprintf('%s: %s', h($entry['expanded']), h($entry['description'])) ?>"><?php echo h($entry['Tag']['name']); ?>
|
||||
</span>
|
||||
<span class="label label-inverse numerical-value-label"><?php echo h($entry['numerical_value']) ?></span>
|
||||
<span class="label label-inverse numerical-value-label">
|
||||
<?php echo h($entry['numerical_value']) ?>
|
||||
<?php if(isset($entry['original_numerical_value'])): ?>
|
||||
<i
|
||||
class="<?= $this->FontAwesome->getClass('exclamation-triangle') ?> fa-exclamation-triangle"
|
||||
title="<?= __('Numerical value overriden by userSetting. Original numerical_value = %s', h($entry['original_numerical_value'])) ?>"
|
||||
data-value-overriden="1"
|
||||
></i>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
@ -97,7 +97,16 @@
|
|||
<?php endif; ?>
|
||||
<td id="tag_<?php echo h($k); ?>" class="short"><?php echo h($item['tag']); ?></td>
|
||||
<td><?php echo h($item['expanded']); ?> </td>
|
||||
<td class="short"><?php echo isset($item['numerical_value']) ? h($item['numerical_value']) : ''; ?> </td>
|
||||
<td class="short">
|
||||
<?php echo isset($item['numerical_value']) ? h($item['numerical_value']) : ''; ?>
|
||||
<?php if(isset($item['original_numerical_value'])): ?>
|
||||
<i
|
||||
class="<?= $this->FontAwesome->getClass('exclamation-triangle') ?> fa-exclamation-triangle"
|
||||
title="<?= __('Numerical value overriden by userSetting. Original numerical_value = %s', h($item['original_numerical_value'])) ?>"
|
||||
data-value-overriden="1"
|
||||
></i>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="short">
|
||||
<?php
|
||||
if ($item['existing_tag']) {
|
||||
|
@ -193,6 +202,7 @@
|
|||
$('.select_taxonomy, .select_all').click(function(){
|
||||
taxonomyListAnyCheckBoxesChecked();
|
||||
});
|
||||
$('[data-value-overriden="1"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue