Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 402b25a

Browse files
committed
[client] handle notification update & delete
1 parent e0754a9 commit 402b25a

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

pycti/api/opencti_api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pycti import __version__
1212
from pycti.api.opencti_api_connector import OpenCTIApiConnector
1313
from pycti.api.opencti_api_draft import OpenCTIApiDraft
14+
from pycti.api.opencti_api_notification import OpenCTIApiNotification
1415
from pycti.api.opencti_api_pir import OpenCTIApiPir
1516
from pycti.api.opencti_api_playbook import OpenCTIApiPlaybook
1617
from pycti.api.opencti_api_public_dashboard import OpenCTIApiPublicDashboard
@@ -172,6 +173,7 @@ def __init__(
172173
self.session = requests.session()
173174
# Define the dependencies
174175
self.work = OpenCTIApiWork(self)
176+
self.notification = OpenCTIApiNotification(self)
175177
self.trash = OpenCTIApiTrash(self)
176178
self.draft = OpenCTIApiDraft(self)
177179
self.workspace = OpenCTIApiWorkspace(self)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class OpenCTIApiNotification:
2+
"""OpenCTIApiJob"""
3+
4+
def __init__(self, api):
5+
self.api = api
6+
7+
def delete(self, **kwargs):
8+
notification_id = kwargs.get("id", None)
9+
self.api.app_logger.info(
10+
"Deleting notifcation", {"notification_id": notification_id}
11+
)
12+
query = """
13+
mutation notificationDelete($id: ID!) {
14+
notificationDelete(id: $id)
15+
}
16+
"""
17+
self.api.query(query, {"id": notification_id})
18+
19+
def update_field(self, **kwargs):
20+
notification_id = kwargs.get("id", None)
21+
input = kwargs.get("input", None)
22+
for input_value in input:
23+
if input_value["key"] == "is_read":
24+
is_read_value = bool(input_value["value"][0])
25+
self.mark_as_read(notification_id, is_read_value)
26+
27+
def mark_as_read(self, notification_id: str, read: bool):
28+
self.api.app_logger.info(
29+
"Marking notifcation as read",
30+
{"notification_id": notification_id, "read": read},
31+
)
32+
query = """
33+
mutation notificationMarkRead($id: ID!, $read: Boolean!) {
34+
notificationMarkRead(id: $id, read: $read) {
35+
id
36+
}
37+
}
38+
"""
39+
self.api.query(query, {"id": notification_id, "read": read})

pycti/utils/opencti_stix2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ def get_internal_helper(self):
925925
"playbook": self.opencti.playbook,
926926
"workspace": self.opencti.workspace,
927927
"publicdashboard": self.opencti.public_dashboard,
928+
"notification": self.opencti.notification,
928929
}
929930

930931
def generate_standard_id_from_stix(self, data):
@@ -2490,6 +2491,10 @@ def apply_patch(self, item):
24902491
self.opencti.indicator.update_field(
24912492
id=item_id, input=field_patch_without_files
24922493
)
2494+
elif item["type"] == "notification":
2495+
self.opencti.notification.update_field(
2496+
id=item_id, input=field_patch_without_files
2497+
)
24932498
else:
24942499
self.opencti.stix_domain_object.update_field(
24952500
id=item_id, input=field_patch_without_files

pycti/utils/opencti_stix2_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"capability",
99
"role",
1010
"settings",
11+
"notification",
1112
"work",
1213
"trash",
1314
"draftworkspace",

0 commit comments

Comments
 (0)