mirror of https://github.com/MISP/PyMISP
fix: [AnalystData] Avoiding issues with analyst data objects
parent
d5e472b95d
commit
1dce13d61b
|
@ -60,28 +60,35 @@ class AnalystDataBehaviorMixin(AbstractMISP):
|
||||||
|
|
||||||
def add_note(self, note: str, language: str | None = None, **kwargs) -> MISPNote: # type: ignore[no-untyped-def]
|
def add_note(self, note: str, language: str | None = None, **kwargs) -> MISPNote: # type: ignore[no-untyped-def]
|
||||||
the_note = MISPNote()
|
the_note = MISPNote()
|
||||||
the_note.from_dict(note=note, language=language,
|
the_note.from_dict(
|
||||||
object_uuid=self.uuid, object_type=self.analyst_data_object_type,
|
note=note, language=language, object_uuid=self.uuid,
|
||||||
**kwargs)
|
object_type=self.analyst_data_object_type, contained=True,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
self.notes.append(the_note)
|
self.notes.append(the_note)
|
||||||
self.edited = True
|
self.edited = True
|
||||||
return the_note
|
return the_note
|
||||||
|
|
||||||
def add_opinion(self, opinion: int, comment: str | None = None, **kwargs) -> MISPOpinion: # type: ignore[no-untyped-def]
|
def add_opinion(self, opinion: int, comment: str | None = None, **kwargs) -> MISPOpinion: # type: ignore[no-untyped-def]
|
||||||
the_opinion = MISPOpinion()
|
the_opinion = MISPOpinion()
|
||||||
the_opinion.from_dict(opinion=opinion, comment=comment,
|
the_opinion.from_dict(
|
||||||
object_uuid=self.uuid, object_type=self.analyst_data_object_type,
|
opinion=opinion, comment=comment, object_uuid=self.uuid,
|
||||||
**kwargs)
|
object_type=self.analyst_data_object_type, contained=True,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
self.opinions.append(the_opinion)
|
self.opinions.append(the_opinion)
|
||||||
self.edited = True
|
self.edited = True
|
||||||
return the_opinion
|
return the_opinion
|
||||||
|
|
||||||
def add_relationship(self, related_object_type: AbstractMISP | str, related_object_uuid: str | None, relationship_type: str, **kwargs) -> MISPRelationship: # type: ignore[no-untyped-def]
|
def add_relationship(self, related_object_type: AbstractMISP | str, related_object_uuid: str | None, relationship_type: str, **kwargs) -> MISPRelationship: # type: ignore[no-untyped-def]
|
||||||
the_relationship = MISPRelationship()
|
the_relationship = MISPRelationship()
|
||||||
the_relationship.from_dict(related_object_type=related_object_type, related_object_uuid=related_object_uuid,
|
the_relationship.from_dict(
|
||||||
relationship_type=relationship_type,
|
related_object_type=related_object_type,
|
||||||
object_uuid=self.uuid, object_type=self.analyst_data_object_type,
|
related_object_uuid=related_object_uuid,
|
||||||
**kwargs)
|
relationship_type=relationship_type, object_uuid=self.uuid,
|
||||||
|
object_type=self.analyst_data_object_type, contained=True,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
self.relationships.append(the_relationship)
|
self.relationships.append(the_relationship)
|
||||||
self.edited = True
|
self.edited = True
|
||||||
return the_relationship
|
return the_relationship
|
||||||
|
@ -2591,8 +2598,8 @@ class MISPNote(AnalystDataBehaviorMixin, MISPAnalystData):
|
||||||
self.language: str
|
self.language: str
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
def from_dict(self, contained=False, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||||
if 'Note' in kwargs:
|
if not conainted and 'Note' in kwargs:
|
||||||
kwargs = kwargs['Note']
|
kwargs = kwargs['Note']
|
||||||
self.note = kwargs.pop('note', None)
|
self.note = kwargs.pop('note', None)
|
||||||
if self.note is None:
|
if self.note is None:
|
||||||
|
@ -2616,8 +2623,8 @@ class MISPOpinion(AnalystDataBehaviorMixin, MISPAnalystData):
|
||||||
self.comment: str
|
self.comment: str
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
def from_dict(self, contained=False, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||||
if 'Opinion' in kwargs:
|
if not contained and 'Opinion' in kwargs:
|
||||||
kwargs = kwargs['Opinion']
|
kwargs = kwargs['Opinion']
|
||||||
self.opinion = kwargs.pop('opinion', None)
|
self.opinion = kwargs.pop('opinion', None)
|
||||||
if self.opinion is not None:
|
if self.opinion is not None:
|
||||||
|
@ -2651,8 +2658,8 @@ class MISPRelationship(AnalystDataBehaviorMixin, MISPAnalystData):
|
||||||
self.relationship_type: str
|
self.relationship_type: str
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
def from_dict(self, contained=False, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||||
if 'Relationship' in kwargs:
|
if not contained and 'Relationship' in kwargs:
|
||||||
kwargs = kwargs['Relationship']
|
kwargs = kwargs['Relationship']
|
||||||
self.related_object_type = kwargs.pop('related_object_type', None)
|
self.related_object_type = kwargs.pop('related_object_type', None)
|
||||||
if self.related_object_type is None:
|
if self.related_object_type is None:
|
||||||
|
|
Loading…
Reference in New Issue