mirror of https://github.com/MISP/PyMISP
parent
cdcbe9bf32
commit
d01c17abf8
|
@ -751,7 +751,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
|
||||
|
@ -1553,6 +1553,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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue