Skip to content

Commit

Permalink
auto update _is_latest on object removal #59 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
fqrious authored Feb 10, 2025
1 parent 2489aa1 commit cc27f5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dogesec_commons/objects/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from drf_spectacular.utils import OpenApiParameter
from ..utils.pagination import Pagination
from rest_framework.exceptions import ValidationError

from stix2arango.services import ArangoDBService
from . import conf

from django.http import HttpResponse
Expand Down Expand Up @@ -524,6 +524,15 @@ def get_post_objects(self, post_id, feed_id):


def delete_report_object(self, report_id, object_id):
db_service = ArangoDBService(
self.DB_NAME,
[],
[],
create=False,
username=settings.ARANGODB_USERNAME,
password=settings.ARANGODB_PASSWORD,
host_url=settings.ARANGODB_HOST_URL,
)
query = """
let doc_ids = (
FOR doc IN @@view
Expand Down Expand Up @@ -579,6 +588,8 @@ def delete_report_object(self, report_id, object_id):
RETURN {new_length: LENGTH(NEW.object_refs), old_length: LENGTH(doc.object_refs)}
""", bind_vars={'report_idkey': report_idkey, 'stix_ids': stix_ids, '@collection': report_idkey.split('/')[0]}, paginate=False)
logging.info(f"removed references from report.object_refs: {resp}")
doc_collection_name = doc_id.split('/')[0]
db_service.update_is_latest_several_chunked([object_id], doc_collection_name, doc_collection_name.removesuffix('_vertex_collection')+'_edge_collection')
return response.Response(status=status.HTTP_204_NO_CONTENT)
# self.execute_query("LET" (",\n\t".join(queries)), bind_vars=bind_vars)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies = [
"drf-spectacular>=0.27.2",
"python-arango>=8.1.3; python_version >= '3.8'",
"stix2",
"stix2arango",
]

[tool.hatch.metadata]
Expand All @@ -34,5 +35,4 @@ Issues = "https://github.com/muchdogesec/stixifier_commons/issues"
stixifier = [
"txt2stix",
"file2txt",
"stix2arango",
]

0 comments on commit cc27f5e

Please sign in to comment.