minor change in getRelatedAttributes function

pull/61/head
Christophe Vandeplas 2012-03-27 14:02:49 +02:00
parent 1518b1ebcc
commit da99625a6c
2 changed files with 16 additions and 10 deletions

View File

@ -79,8 +79,9 @@ class EventsController extends AppController {
$relatedAttributes = array();
$this->loadModel('Attribute');
$fields = array('Attribute.id', 'Attribute.event_id');
foreach ($this->Event->data['Attribute'] as $attribute) {
$relatedAttributes[$attribute['id']] = $this->Attribute->getRelatedAttributes($attribute);
$relatedAttributes[$attribute['id']] = $this->Attribute->getRelatedAttributes($attribute, $fields);
}
$this->set('relatedAttributes', $relatedAttributes);
@ -146,19 +147,21 @@ class EventsController extends AppController {
// only edit own events verified by isAuthorized
if ($this->request->is('post') || $this->request->is('put')) {
// say what fields are to be updated
$fieldList=array('user_id', 'date', 'risk', 'info', 'alerted', 'private');
// always force the user and org, but do not force it for admins
if (!$this->_isAdmin()) {
$this->request->data['Event']['user_id'] = $this->Auth->user('id');
$this->request->data['Event']['org'] = $this->Auth->user('org');
} else {
$this->request->data['Event']['user_id'] = $old_event['Event']['id'];
$this->request->data['Event']['org'] = $old_event['Event']['org'];
$this->Event->read();
$this->request->data['Event']['user_id'] = $this->Event->data['Event']['user_id'];
$fieldList[]='org';
$this->request->data['Event']['org'] = $this->Event->data['Event']['org'];
}
// we probably also want to remove the alerted flag
$this->request->data['Event']['alerted'] = 0;
// say what fields are to be updated
$fieldList=array('user_id', 'org', 'date', 'risk', 'info', 'alerted', 'private');
if ($this->Event->save($this->request->data, true, $fieldList)) {
$this->Session->setFlash(__('The event has been saved'));
$this->redirect(array('action' => 'view', $id));

View File

@ -64,7 +64,8 @@ class Attribute extends AppModel {
),
'category' => array(
'rule' => array('inList', array('Payload delivery',
'rule' => array('inList', array(
'Payload delivery',
'Antivirus detection',
'Payload installation',
'Artifacts dropped',
@ -347,18 +348,20 @@ class Attribute extends AppModel {
return $this->data['Event']['org'] === $org;
}
function getRelatedAttributes($attribute) {
function getRelatedAttributes($attribute, $fields=array()) {
// LATER there should be a list of types/categories included here as some are not eligible (AV detection category
// or "other" type could be excluded)
// LATER getRelatedAttributes($attribute) this might become a performance bottleneck
$conditions = array('Attribute.value =' => $attribute['value'],
'Attribute.id !=' => $attribute['id'],
'Attribute.type =' => $attribute['type'], );
// $fields = array('Event.*');
$fields = array('Attribute.*');
if (empty($fields)) {
$fields = array('Attribute.*');
}
$similar_events = $this->find('all',array('conditions' => $conditions,
'fields' => $fields,
'recursive' => 0,
'order' => 'Attribute.event_id DESC', )
);
return $similar_events;