new: [internal] OrgBlocklist::removeBlockedEvents

pull/7796/head
Jakub Onderka 2021-09-30 21:18:25 +02:00
parent cb53c030b7
commit 1a44c3885d
2 changed files with 23 additions and 11 deletions

View File

@ -1,5 +1,6 @@
<?php
App::uses('AppModel', 'Model');
class OrgBlocklist extends AppModel
{
public $useTable = 'org_blocklists';
@ -39,4 +40,24 @@ class OrgBlocklist extends AppModel
}
return true;
}
/**
* @param array $eventArray
*/
public function removeBlockedEvents(array &$eventArray)
{
$blocklistHits = $this->find('column', array(
'conditions' => array('OrgBlocklist.org_uuid' => array_unique(array_column($eventArray, 'orgc_uuid'))),
'fields' => array('OrgBlocklist.org_uuid'),
));
if (empty($blocklistHits)) {
return;
}
$blocklistHits = array_flip($blocklistHits);
foreach ($eventArray as $k => $event) {
if (isset($blocklistHits[$event['orgc_uuid']])) {
unset($eventArray[$k]);
}
}
}
}

View File

@ -733,7 +733,7 @@ class Server extends AppModel
public function getEventIdsFromServer(ServerSyncTool $serverSync, $all = false, $ignoreFilterRules = false, $scope = 'events', $force = false)
{
if (!in_array($scope, ['events', 'sightings'], true)) {
throw new InvalidArgumentException("Scope mus be 'events' or 'sightings', '$scope' given.");
throw new InvalidArgumentException("Scope must be 'events' or 'sightings', '$scope' given.");
}
$eventArray = $this->getEventIndexFromServer($serverSync, $ignoreFilterRules);
@ -767,16 +767,7 @@ class Server extends AppModel
if (Configure::read('MISP.enableOrgBlocklisting') !== false) {
$this->OrgBlocklist = ClassRegistry::init('OrgBlocklist');
$blocklistHits = $this->OrgBlocklist->find('column', array(
'conditions' => array('OrgBlocklist.org_uuid' => array_unique(array_column($eventArray, 'orgc_uuid'))),
'fields' => array('OrgBlocklist.org_uuid'),
));
$blocklistHits = array_flip($blocklistHits);
foreach ($eventArray as $k => $event) {
if (isset($blocklistHits[$event['orgc_uuid']])) {
unset($eventArray[$k]);
}
}
$this->OrgBlocklist->removeBlockedEvents($eventArray);
}
foreach ($eventArray as $k => $event) {