new: [events] endpoint `runTaxonomyExclusivityCheck` for event elements

pull/6541/head
mokaddem 2020-11-05 16:08:17 +01:00
parent 60d1adb1cf
commit 106fa7300a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 50 additions and 0 deletions

View File

@ -223,6 +223,7 @@ class ACLComponent extends Component
'reportValidationIssuesEvents' => array(),
'restoreDeletedEvents' => array('perm_site_admin'),
'restSearch' => array('*'),
'runTaxonomyExclusivityCheck' => array('*'),
'saveFreeText' => array('perm_add'),
'stix' => array('*'),
'stix2' => array('*'),

View File

@ -5633,4 +5633,53 @@ class EventsController extends AppController
$this->redirect(['action' => 'restoreDeletedEvents']);
}
}
public function runTaxonomyExclusivityCheck($id)
{
$conditions = [];
if (is_numeric($id)) {
$conditions = array('eventid' => $id);
} else if (Validation::uuid($id)) {
$conditions = array('event_uuid' => $id);
} else {
throw new NotFoundException(__('Invalid event'));
}
$conditions['excludeLocalTags'] = false;
$conditions['excludeGalaxy'] = true;
$event = $this->Event->fetchEvent($this->Auth->user(), $conditions);
if (empty($event)) {
throw new NotFoundException(__('Invalid event'));
}
$event = $event[0];
$this->loadModel('Taxonomy');
$allConflicts = [];
$tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($event['EventTag']);
if (!empty($tagConflicts['global']) || !empty($tagConflicts['local'])) {
$tagConflicts['Event'] = $event['Event'];
$allConflicts[] = $tagConflicts;
}
foreach ($event['Object'] as $k => $object) {
if (isset($object['Attribute'])) {
foreach ($object['Attribute'] as $k2 => $attribute) {
$this->Event->Attribute->removeGalaxyClusterTags($event['Object'][$k]['Attribute'][$k2]);
$tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']);
if (!empty($tagConflicts['global']) || !empty($tagConflicts['local'])) {
$tagConflicts['Attribute'] = $event['Object'][$k]['Attribute'][$k2];
unset($tagConflicts['Attribute']['AttributeTag'], $tagConflicts['Attribute']['Galaxy'], $tagConflicts['Attribute']['ShadowAttribute']);
$allConflicts[] = $tagConflicts;
}
}
}
}
foreach ($event['Attribute'] as $k => $attribute) {
$this->Event->Attribute->removeGalaxyClusterTags($event['Attribute'][$k]);
$tagConflicts = $this->Taxonomy->checkIfTagInconsistencies($attribute['AttributeTag']);
if (!empty($tagConflicts['global']) || !empty($tagConflicts['local'])) {
$tagConflicts['Attribute'] = $event['Attribute'][$k];
unset($tagConflicts['Attribute']['AttributeTag'], $tagConflicts['Attribute']['Galaxy'], $tagConflicts['Attribute']['ShadowAttribute']);
$allConflicts[] = $tagConflicts;
}
}
return $this->RestResponse->viewData($allConflicts);
}
}