diff --git a/pymisp/abstract.py b/pymisp/abstract.py index 88e881d..c6d5a38 100644 --- a/pymisp/abstract.py +++ b/pymisp/abstract.py @@ -8,7 +8,7 @@ from deprecated import deprecated # type: ignore from json import JSONEncoder from uuid import UUID from abc import ABCMeta -from enum import Enum, IntEnum +from enum import Enum from typing import Any, Mapping from collections.abc import MutableMapping from functools import lru_cache @@ -147,19 +147,6 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta): # type: i treatment are processed. Note: This method is used when you initialize an object with existing data so by default, the class is flaged as not edited.""" - # Recursively loads more analyst data - from pymisp.mispevent import AnalystDataBehaviorMixin, MISPNote, MISPOpinion, MISPRelationship - if isinstance(self, AnalystDataBehaviorMixin): - for analystType in ['Note', 'Opinion', 'Relationship']: - if kwargs.get(analystType): - analystDataList = kwargs.pop(analystType) - for analystDataDict in analystDataList: - analystData = {'Note': MISPNote, 'Opinion': MISPOpinion, 'Relationship': MISPRelationship}.get(analystType, MISPNote)() - analystDataDict['object_uuid'] = self.uuid if 'object_uuid' not in analystDataDict else analystDataDict['object_uuid'] - analystDataDict['object_type'] = self.classObjectType - analystData.from_dict(**analystDataDict) - {'Note': self.notes, 'Opinion': self.opinions, 'Relationship': self.relationships}.get(analystType, 'Note').append(analystData) - for prop, value in kwargs.items(): if value is None: continue diff --git a/pymisp/api.py b/pymisp/api.py index e10c04f..a92ac22 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -653,8 +653,7 @@ class PyMISP: type = analyst_data.classObjectType analyst_data_id = get_uuid_or_id_from_abstract_misp(analyst_data) request_url = f'analyst_data/delete/{type}/{analyst_data_id}' - data = {} - r = self._prepare_request('POST', request_url, data=data) + r = self._prepare_request('POST', request_url) return self._check_json_response(r) # ## END Analyst Data ### @@ -767,7 +766,6 @@ class PyMISP: # ## END Analyst Relationship ### - # ## BEGIN Object ### def get_object(self, misp_object: MISPObject | int | str | UUID, pythonify: bool = False) -> dict[str, Any] | MISPObject: diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index dd9f73d..2770d9e 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -82,6 +82,16 @@ class AnalystDataBehaviorMixin(AbstractMISP): self.edited = True return the_relationship + def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def] + if 'Note' in kwargs and kwargs.get('Note'): + self.add_note(**kwargs.pop('Note')) + if 'Opinion' in kwargs and kwargs.get('Opinion'): + self.add_opinion(**kwargs.pop('Opinion')) + if 'Relationship' in kwargs and kwargs.get('Relationship'): + self.add_relationship(**kwargs.pop('Relationship')) + super().from_dict(**kwargs) + + try: from dateutil.parser import parse except ImportError: @@ -1130,7 +1140,6 @@ class MISPEventReport(AnalystDataBehaviorMixin): super().__init__(**kwargs) self.uuid: str = str(uuid.uuid4()) - def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def] if 'EventReport' in kwargs: kwargs = kwargs['EventReport'] @@ -2422,7 +2431,6 @@ class MISPAnalystData(AbstractMISP): self.created: float | int | datetime self.modified: float | int | datetime self.SharingGroup: MISPSharingGroup - self.note_type_name = self.classObjectType def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def] self.distribution = kwargs.pop('distribution', None)