new: soft delete object in MISPEvent

Fix #706
pull/749/head
Raphaël Vinot 2021-02-26 17:55:08 +01:00
parent 28fed5c778
commit 2e05a1b24f
2 changed files with 22 additions and 1 deletions

View File

@ -752,7 +752,7 @@ class MISPObject(AbstractMISP):
pass
def delete(self):
"""Mark the attribute as deleted (soft delete)"""
"""Mark the object as deleted (soft delete)"""
self.deleted = True
@property
@ -1888,6 +1888,19 @@ class MISPEvent(AbstractMISP):
self.edited = True
return misp_obj
def delete_object(self, object_id: str):
"""Delete an object
:param object_id: ID or UUID
"""
for o in self.objects:
if ((hasattr(o, 'id') and o.id == object_id)
or (hasattr(o, 'uuid') and o.uuid == object_id)):
o.delete()
break
else:
raise PyMISPError('No object with UUID/ID {} found.'.format(object_id))
def run_expansions(self):
for index, attribute in enumerate(self.attributes):
if 'expand' not in attribute:

View File

@ -1255,6 +1255,14 @@ class TestComprehensive(unittest.TestCase):
response = self.admin_misp_connector.delete_tag(t)
self.assertEqual(response['message'], 'Tag deleted.')
# Test soft delete object
second.delete_object(ip_dom.uuid)
self.assertTrue(second.objects[-1].deleted)
second = self.user_misp_connector.update_event(second)
self.assertFalse(second.objects)
second = self.user_misp_connector.get_event(second, deleted=True)
self.assertTrue(second.objects[-1].deleted)
# Test delete object
r = self.user_misp_connector.delete_object(second.objects[0])
self.assertEqual(r['message'], 'Object deleted', r)