mirror of https://github.com/MISP/MISP
fix: [Attribute:editTag] Correctly escalate the timestamp refresh to the
Objectpull/5462/head
parent
38c6f05d1b
commit
5c97c5da53
|
@ -2948,6 +2948,9 @@ class AttributesController extends AppController
|
|||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$result = $this->Attribute->Event->save($event);
|
||||
$attribute['Attribute']['timestamp'] = $date->getTimestamp();
|
||||
if ($attribute['Attribute']['object_id'] != 0) {
|
||||
$this->Attribute->Object->updateTimestamp($attribute['Attribute']['object_id'], $date->getTimestamp());
|
||||
}
|
||||
$this->Attribute->save($attribute);
|
||||
}
|
||||
$log = ClassRegistry::init('Log');
|
||||
|
@ -3094,6 +3097,9 @@ class AttributesController extends AppController
|
|||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->Event->save($event);
|
||||
if ($this->Attribute->data['Attribute']['object_id'] != 0) {
|
||||
$this->Attribute->Object->updateTimestamp($this->Attribute->data['Attribute']['object_id'], $date->getTimestamp());
|
||||
}
|
||||
$this->Attribute->data['Attribute']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->save($this->Attribute->data);
|
||||
}
|
||||
|
|
|
@ -3965,7 +3965,8 @@ class Attribute extends AppModel
|
|||
if (isset($attribute['uuid'])) {
|
||||
$existingAttribute = $this->find('first', array(
|
||||
'conditions' => array('Attribute.uuid' => $attribute['uuid']),
|
||||
'recursive' => -1
|
||||
'contain' => array('AttributeTag' => 'Tag'),
|
||||
'recursive' => -1,
|
||||
));
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
if (count($existingAttribute)) {
|
||||
|
@ -4076,28 +4077,31 @@ class Attribute extends AppModel
|
|||
));
|
||||
return $this->validationErrors;
|
||||
} else {
|
||||
if (isset($attribute['Tag']) && $user['Role']['perm_tagger']) {
|
||||
foreach ($attribute['Tag'] as $tag) {
|
||||
$tag_id = $this->AttributeTag->Tag->captureTag($tag, $user);
|
||||
if ($tag_id) {
|
||||
// fix the IDs here
|
||||
$this->AttributeTag->attachTagToAttribute($this->id, $attribute['event_id'], $tag_id);
|
||||
} else {
|
||||
// If we couldn't attach the tag it is most likely because we couldn't create it - which could have many reasons
|
||||
// However, if a tag couldn't be added, it could also be that the user is a tagger but not a tag editor
|
||||
// In which case if no matching tag is found, no tag ID is returned. Logging these is pointless as it is the correct behaviour.
|
||||
if ($user['Role']['perm_tag_editor']) {
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => 'Attrubute',
|
||||
'model_id' => $this->id,
|
||||
'email' => $user['email'],
|
||||
'action' => 'edit',
|
||||
'user_id' => $user['id'],
|
||||
'title' => 'Failed create or attach Tag ' . $tag['name'] . ' to the attribute.',
|
||||
'change' => ''
|
||||
));
|
||||
if ($user['Role']['perm_tagger']) {
|
||||
$this->AttributeTag->pruneOutdatedAttributeTagsFromSync(isset($attribute['Tag']) ? $attribute['Tag'] : array(), $existingAttribute['AttributeTag']);
|
||||
if (isset($attribute['Tag'])) {
|
||||
foreach ($attribute['Tag'] as $tag) {
|
||||
$tag_id = $this->AttributeTag->Tag->captureTag($tag, $user);
|
||||
if ($tag_id) {
|
||||
// fix the IDs here
|
||||
$this->AttributeTag->attachTagToAttribute($this->id, $attribute['event_id'], $tag_id);
|
||||
} else {
|
||||
// If we couldn't attach the tag it is most likely because we couldn't create it - which could have many reasons
|
||||
// However, if a tag couldn't be added, it could also be that the user is a tagger but not a tag editor
|
||||
// In which case if no matching tag is found, no tag ID is returned. Logging these is pointless as it is the correct behaviour.
|
||||
if ($user['Role']['perm_tag_editor']) {
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => 'Attrubute',
|
||||
'model_id' => $this->id,
|
||||
'email' => $user['email'],
|
||||
'action' => 'edit',
|
||||
'user_id' => $user['id'],
|
||||
'title' => 'Failed create or attach Tag ' . $tag['name'] . ' to the attribute.',
|
||||
'change' => ''
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,21 @@ class AttributeTag extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function pruneOutdatedAttributeTagsFromSync($newerTags, $originalAttributeTags)
|
||||
{
|
||||
$newerTagsName = array();
|
||||
foreach ($newerTags as $tag) {
|
||||
$newerTagsName[] = strtolower($tag['name']);
|
||||
}
|
||||
foreach ($originalAttributeTags as $k => $attributeTag) {
|
||||
if (!$attributeTag['local']) { //
|
||||
if (!in_array(strtolower($attributeTag['Tag']['name']), $newerTagsName)) {
|
||||
$this->softDelete($attributeTag['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function countForTag($tag_id, $user)
|
||||
{
|
||||
return $this->find('count', array(
|
||||
|
|
|
@ -703,14 +703,14 @@ class MispObject extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function updateTimestamp($id)
|
||||
public function updateTimestamp($id, $timestamp = false)
|
||||
{
|
||||
$date = new DateTime();
|
||||
$object = $this->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('Object.id' => $id)
|
||||
));
|
||||
$object['Object']['timestamp'] = $date->getTimestamp();
|
||||
$object['Object']['timestamp'] = $timestamp == false ? $date->getTimestamp() : $timestamp;
|
||||
$object['Object']['skip_zmq'] = 1;
|
||||
$object['Object']['skip_kafka'] = 1;
|
||||
$result = $this->save($object);
|
||||
|
|
Loading…
Reference in New Issue