fix: conflics and update db_schema.json

pull/8794/head
Luciano Righetti 2022-11-30 16:00:17 +01:00
parent f0d784d612
commit 2e7d1d30c1
No known key found for this signature in database
GPG Key ID: CB91F2A37C557248
10 changed files with 172 additions and 98 deletions

View File

@ -674,6 +674,7 @@ class ACLComponent extends Component
'taxonomyMassHide' => array('perm_tagger'),
'taxonomyMassUnhide' => array('perm_tagger'),
'toggleRequired' => array(),
'toggleHighlighted' => array(),
'update' => array(),
'import' => [],
'export' => ['*'],

View File

@ -1805,6 +1805,8 @@ class EventsController extends AppController
$this->set('includeRelatedTags', (!empty($namedParams['includeRelatedTags'])) ? 1 : 0);
$this->set('includeDecayScore', (!empty($namedParams['includeDecayScore'])) ? 1 : 0);
$this->__setHighlightedTags($event);
if ($this->_isSiteAdmin() && $event['Event']['orgc_id'] !== $this->Auth->user('org_id')) {
$this->Flash->info(__('You are currently logged in as a site administrator and about to edit an event not belonging to your organisation. This goes against the sharing model of MISP. Use a normal user account for day to day work.'));
}
@ -6217,4 +6219,15 @@ class EventsController extends AppController
$this->render('/genericTemplates/confirm');
}
}
/**
* @param array $event
* @return void
*/
private function __setHighlightedTags($event)
{
$this->loadModel('Taxonomy');
$highlightedTags = $this->Taxonomy->getHighlightedTags($event['EventTag']);
$this->set('highlightedTaxonomies', $highlightedTags);
}
}

View File

@ -367,6 +367,9 @@ class TagsController extends AppController
// Remove galaxy tags
$event = $this->Tag->removeGalaxyClusterTags($user, $event);
$highlightedTags = $this->Taxonomy->getHighlightedTags($event['EventTag']);
$this->set('highlightedTaxonomies', $highlightedTags);
$this->set('tags', $event['EventTag']);
$this->set('missingTaxonomies', $this->Tag->EventTag->Event->missingTaxonomies($event));
$tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($event['EventTag']);

View File

@ -498,6 +498,32 @@ class TaxonomiesController extends AppController
$this->render('ajax/toggle_required');
}
public function toggleHighlighted($id)
{
$taxonomy = $this->Taxonomy->find('first', array(
'recursive' => -1,
'conditions' => array('Taxonomy.id' => $id)
));
if (empty($taxonomy)) {
return $this->RestResponse->saveFailResponse('Taxonomy', 'toggleHighlighted', $id, 'Invalid Taxonomy', $this->response->type());
}
if ($this->request->is('post')) {
$taxonomy['Taxonomy']['highlighted'] = $this->request->data['Taxonomy']['highlighted'];
$result = $this->Taxonomy->save($taxonomy);
if ($result) {
return $this->RestResponse->saveSuccessResponse('Taxonomy', 'toggleHighlighted', $id, $this->response->type());
} else {
return $this->RestResponse->saveFailResponse('Taxonomy', 'toggleHighlighted', $id, $this->validationError, $this->response->type());
}
}
$this->set('highlighted', !$taxonomy['Taxonomy']['highlighted']);
$this->set('id', $id);
$this->autoRender = false;
$this->layout = false;
$this->render('ajax/toggle_highlighted');
}
/**
* @param string $action
* @param int $modelId

View File

@ -83,7 +83,7 @@ class AppModel extends Model
81 => false, 82 => false, 83 => false, 84 => false, 85 => false, 86 => false,
87 => false, 88 => false, 89 => false, 90 => false, 91 => false, 92 => false,
93 => false, 94 => false, 95 => true, 96 => false, 97 => true, 98 => false,
99 => false, 100 => false, 101 => false
99 => false, 100 => false, 101 => false, 102 => false
);
const ADVANCED_UPDATES_DESCRIPTION = array(
@ -1920,6 +1920,9 @@ class AppModel extends Model
INDEX `baseurl` (`baseurl`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
break;
case 102:
$sqlArray[] = "ALTER TABLE `taxonomies` ADD `highlighted` tinyint(1) DEFAULT 0;";
break;
case 'fixNonEmptySharingGroupID':
$sqlArray[] = 'UPDATE `events` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';
$sqlArray[] = 'UPDATE `attributes` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';

View File

@ -118,7 +118,7 @@ class Taxonomy extends AppModel
$current = $this->find('first', array(
'conditions' => array('namespace' => $vocab['namespace']),
'recursive' => -1,
'fields' => array('version', 'enabled', 'namespace')
'fields' => array('version', 'enabled', 'namespace', 'highlighted')
));
$current = empty($current) ? [] : $current['Taxonomy'];
$result = $this->__updateVocab($vocab, $current);
@ -147,6 +147,7 @@ class Taxonomy extends AppModel
'version' => $vocab['version'],
'exclusive' => !empty($vocab['exclusive']),
'enabled' => $enabled,
'highlighted' => !empty($vocab['highlighted']),
]];
$predicateLookup = array();
foreach ($vocab['predicates'] as $k => $predicate) {
@ -877,4 +878,39 @@ class Taxonomy extends AppModel
{
return $this->Tag->mergeTag($source_id, $target_id);
}
/**
*
* @param array $tags
* @return array
*/
public function getHighlightedTags($tags)
{
$highlitedTaxonomies = $this->find('all', [
'conditions' => [
'highlighted' => 1,
]
]);
$highlightedTags = [];
if (is_array($highlitedTaxonomies) && !empty($highlitedTaxonomies)) {
foreach ($highlitedTaxonomies as $k => $taxonomy) {
$highlightedTags[$k] = [
'taxonomy' => $taxonomy,
'tags' => []
];
foreach ($tags as $tag) {
$splits = $this->splitTagToComponents($tag['Tag']['name']);
if (!empty($splits) && $splits['namespace'] === $taxonomy['Taxonomy']['namespace']) {
$highlightedTags[$k]['tags'][] = $tag;
}
}
}
return $highlightedTags;
}
return $highlightedTags;
}
}

View File

@ -24,100 +24,8 @@
$full = $isAclTagger && $tagAccess && empty($static_tags_only);
$fullLocal = $isAclTagger && $localTagAccess && empty($static_tags_only);
$tagData = "";
foreach ($tags as $tag) {
if (empty($tag['Tag'])) {
$tag['Tag'] = $tag;
}
if (empty($tag['Tag']['colour'])) {
$tag['Tag']['colour'] = '#0088cc';
}
$aStyle = 'background-color:' . h($tag['Tag']['colour']) . ';color:' . $this->TextColour->getTextColour($tag['Tag']['colour']);
$aClass = 'tag nowrap';
$aText = trim($tag['Tag']['name']);
$aTextModified = null;
if (isset($tag_display_style)) {
if ($tag_display_style == 1) {
// default behaviour, do nothing for now
} else if ($tag_display_style == 2) {
$separator_pos = strpos($aText, ':');
if ($separator_pos !== false) {
$aTextModified = substr($aText, $separator_pos + 1);
$value_pos = strpos($aTextModified, '=');
if ($value_pos !== false) {
$aTextModified = substr($aTextModified, $value_pos + 1);
$aTextModified = trim($aTextModified, '"');
}
$aTextModified = h($aTextModified);
}
} else if ($tag_display_style === 0 || $tag_display_style === '0') {
$aTextModified = ' ';
}
}
$aText = h($aText);
$span_scope = !empty($hide_global_scope) ? '' : sprintf(
'<span class="%s" title="%s" aria-label="%s"><i class="fas fa-%s"></i></span>',
'black-white tag',
!empty($tag['local']) ? __('Local tag') : __('Global tag'),
!empty($tag['local']) ? __('Local tag') : __('Global tag'),
!empty($tag['local']) ? 'user' : 'globe-americas'
);
$span_relationship_type = empty($tag['relationship_type']) ? '' : sprintf(
'<span class="tag nowrap white" style="background-color:black" title="%s" aria-label="%s">%s:</span>',
h($tag['relationship_type']),
h($tag['relationship_type']),
h($tag['relationship_type'])
);
if (!empty($tag['Tag']['id'])) {
$span_tag = sprintf(
'<a href="%s" style="%s" class="%s"%s data-tag-id="%s">%s</a>',
$baseurl . $searchUrl . intval($tag['Tag']['id']),
$aStyle,
$aClass,
isset($aTextModified) ? ' title="' . $aText . '"' : '',
intval($tag['Tag']['id']),
isset($aTextModified) ? $aTextModified : $aText
);
} else {
$span_tag = sprintf(
'<span style="%s" class="%s">%s</span>',
$aStyle,
$aClass,
$aText
);
}
$span_delete = '';
$span_relationship = '';
if ($full || ($fullLocal && $tag['Tag']['local'])) {
$span_relationship = sprintf(
'<a class="%s" title="%s" role="button" tabindex="0" aria-label="%s" href="%s"><i class="fas fa-project-diagram"></i></a>',
'black-white tag noPrint modal-open',
__('Modify Tag Relationship'),
__('Modify relationship for tag %s', h($tag['Tag']['name'])),
sprintf(
'%s/tags/modifyTagRelationship/%s/%s',
$baseurl,
h($scope),
h($tag['id'])
)
);
$span_delete = sprintf(
'<span class="%s" title="%s" role="%s" tabindex="%s" aria-label="%s" onclick="%s">x</span>',
'black-white tag useCursorPointer noPrint',
__('Remove tag'),
"button",
"0",
__('Remove tag %s', h($tag['Tag']['name'])),
sprintf(
"removeObjectTagPopup(this, '%s', %s, %s)",
$scope,
$id,
intval($tag['Tag']['id'])
)
);
}
$tagData .= '<span class="tag-container nowrap">' . $span_scope . $span_relationship_type . $span_tag . $span_relationship . $span_delete . '</span> ';
}
$buttonData = array();
$buttonData = [];
if ($full) {
$buttonData[] = sprintf(
'<button title="%s" role="button" tabindex="0" aria-label="%s" class="%s" data-popover-popup="%s">%s</button>',
@ -138,6 +46,62 @@
'<i class="fas fa-user"></i> <i class="fas fa-plus"></i>'
);
}
$highlitedTags = "";
if (isset($highlightedTaxonomies) && $scope == 'event') {
foreach ($highlightedTaxonomies as $hTaxonomy) {
$hButtonData = [];
if ($full) {
$hButtonData[] = sprintf(
'<button title="%s" role="button" tabindex="0" aria-label="%s" class="%s" data-popover-popup="%s">%s</button>',
__('Add a tag'),
__('Add a tag'),
'addTagButton addButton btn btn-inverse noPrint',
sprintf($baseurl . '/tags/selectTag/%u/%u/event', $id, $hTaxonomy['taxonomy']['Taxonomy']['id']),
'<i class="fas fa-globe-americas"></i> <i class="fas fa-plus"></i>'
);
}
$hTags = "";
foreach($hTaxonomy['tags'] as $hTag){
$hTags .= $this->element('rich_tag', [
'tag' => $hTag,
'tagAccess' => $tagAccess,
'localTagAccess' => $localTagAccess,
'searchUrl' => $searchUrl,
'scope' => $scope,
'id' => $id,
]);
}
$highlitedTags .= sprintf(
'<tr><td style="font-weight: bold;text-transform: uppercase;">%s</td></td><td>%s</td><td>%s</td></tr>',
$hTaxonomy['taxonomy']['Taxonomy']['namespace'],
$hTags,
$hButtonData ? '<span style="white-space:nowrap">' . implode('', $hButtonData) . '</span>' : ''
);
foreach ($tags as $k => $tag) {
foreach ($hTaxonomy['tags'] as $hTag) {
if ($tag['Tag']['name'] === $hTag['Tag']['name']) {
unset($tags[$k]);
}
}
}
}
$tagData .= sprintf('<table>%s</table>', $highlitedTags);
}
foreach ($tags as $tag) {
$tagData .= $this->element('rich_tag', [
'tag' => $tag,
'tagAccess' => $tagAccess,
'localTagAccess' => $localTagAccess,
'searchUrl' => $searchUrl,
'scope' => $scope,
'id' => $id
]);
}
if (!empty($buttonData)) {
$tagData .= '<span style="white-space:nowrap">' . implode('', $buttonData) . '</span>';
}
@ -174,4 +138,4 @@
}
}
echo '</div></div></span>';
}
}

View File

@ -75,6 +75,18 @@
'data_path' => 'Taxonomy.required',
'disabled' => !$isSiteAdmin,
),
array(
'name' => __('Highlighted'),
'element' => 'toggle',
'url' => $baseurl . '/taxonomies/toggleHighlighted',
'url_params_data_paths' => array(
'Taxonomy.id'
),
'sort' => 'highlighted',
'class' => 'short',
'data_path' => 'Taxonomy.highlighted',
'disabled' => !$isSiteAdmin,
),
array(
'name' => __('Active Tags'),
'element' => 'custom',

View File

@ -46,6 +46,11 @@ echo $this->element(
'path' => 'enabled',
'type' => 'boolean'
],
[
'key' => __('Highlighted'),
'path' => 'highlighted',
'type' => 'boolean'
],
[
'key' => __('Action'),
'type' => 'custom',

View File

@ -7279,6 +7279,17 @@
"column_type": "tinyint(1)",
"column_default": "0",
"extra": ""
},
{
"column_name": "highlighted",
"is_nullable": "NO",
"data_type": "tinyint",
"character_maximum_length": null,
"numeric_precision": "3",
"collation_name": null,
"column_type": "tinyint(1)",
"column_default": "0",
"extra": ""
}
],
"taxonomy_entries": [
@ -9257,5 +9268,5 @@
"uuid": false
}
},
"db_version": "101"
"db_version": "102"
}