|
75 | 75 | from drf_spectacular.views import SpectacularAPIView |
76 | 76 | from rest_framework.response import Response |
77 | 77 |
|
| 78 | +ADMIRALTY_MARKING_MAPPING = { |
| 79 | + "SOURCE": { |
| 80 | + "A": "marking-definition--cf438540-077a-56c7-b68e-82fcc2bb0208", |
| 81 | + "B": "marking-definition--b3cd9dd0-9081-5cbe-84d0-ef5bc11b8b13", |
| 82 | + "C": "marking-definition--3545f856-c5f5-5d2f-a1ae-102e0b6028b2", |
| 83 | + "D": "marking-definition--223ecfcc-22ce-5ece-b91c-a05a53a91959", |
| 84 | + "E": "marking-definition--9eff5f66-33b9-5e54-9868-72179b28ae12", |
| 85 | + "F": "marking-definition--adebda39-90c9-5ac0-9107-c26d86a6c3d8", |
| 86 | + }, |
| 87 | + "INFORMATION": { |
| 88 | + "1": "marking-definition--2462b621-0825-5879-917c-082e0394bcf4", |
| 89 | + "2": "marking-definition--9cf59b27-57f8-5250-98f4-16c462d5652c", |
| 90 | + "3": "marking-definition--4c76ec83-d905-5ada-b0bf-8ae2fb9e9f4d", |
| 91 | + "4": "marking-definition--c36a018d-bc8e-57a4-a39d-9e7e31d1bc17", |
| 92 | + "5": "marking-definition--0a48adab-e7d5-5354-8a41-abf199fe2628", |
| 93 | + "6": "marking-definition--2244db4b-ee29-5b8c-bed4-c7ac784c647a", |
| 94 | + }, |
| 95 | +} |
| 96 | + |
78 | 97 |
|
79 | 98 | class SchemaViewCached(SpectacularAPIView): |
80 | 99 | _schema = None |
@@ -250,6 +269,15 @@ class filterset_class(FilterSet): |
250 | 269 | choices=JobState.choices, |
251 | 270 | ) |
252 | 271 |
|
| 272 | + admiralty_source_reliability = filters.ChoiceFilter( |
| 273 | + choices=File._meta.get_field("admiralty_source_reliability").choices, |
| 274 | + help_text="Filter Files by the Admiralty source reliability rating assigned to them (e.g. `A`).", |
| 275 | + ) |
| 276 | + admiralty_information_credibility = filters.ChoiceFilter( |
| 277 | + choices=File._meta.get_field("admiralty_information_credibility").choices, |
| 278 | + help_text="Filter Files by the Admiralty information credibility rating assigned to them (e.g. `1`).", |
| 279 | + ) |
| 280 | + |
253 | 281 | ai_describes_incident = filters.BooleanFilter( |
254 | 282 | help_text="If `ai_content_check_provider` set in profile used to process report, AI will answer if file describes security incident. Default will show all reports, can filter those that only describe incident by setting to true." |
255 | 283 | ) |
@@ -669,6 +697,16 @@ def get_report(cls, report_id, request=None): |
669 | 697 | description="Filter the results by TLP marking of the Report object (set at file upload time).", |
670 | 698 | enum=[f[0] for f in TLP_Levels.choices], |
671 | 699 | ), |
| 700 | + OpenApiParameter( |
| 701 | + "admiralty_source_reliability", |
| 702 | + description="Filter the results by the Admiralty source reliability marking applied to the Report object (set at file upload time). Checks the `object_marking_refs` of the Report object for the marking definition `id` matching the rating selected.", |
| 703 | + enum=[f[0] for f in File._meta.get_field("admiralty_source_reliability").choices], |
| 704 | + ), |
| 705 | + OpenApiParameter( |
| 706 | + "admiralty_information_credibility", |
| 707 | + description="Filter the results by the Admiralty information credibility marking applied to the Report object (set at file upload time). Checks the `object_marking_refs` of the Report object for the marking definition `id` matching the rating selected.", |
| 708 | + enum=[f[0] for f in File._meta.get_field("admiralty_information_credibility").choices], |
| 709 | + ), |
672 | 710 | OpenApiParameter( |
673 | 711 | "description", |
674 | 712 | description="Filter by the content in a report `description` (which contains the markdown version of the report). Will search for descriptions that contain the value entered. Search is wildcard so `exploit` will match `exploited`, `exploits`, etc.", |
@@ -867,6 +905,14 @@ def get_reports(self, id=None): |
867 | 905 | bind_vars["tlp_level_stix_id"] = TLP_LEVEL_STIX_ID_MAPPING.get(tlp_level) |
868 | 906 | filters.append("FILTER @tlp_level_stix_id IN doc.object_marking_refs") |
869 | 907 |
|
| 908 | + if rating := helper.query.get("admiralty_source_reliability"): |
| 909 | + bind_vars["admiralty_source_reliability_stix_id"] = ADMIRALTY_MARKING_MAPPING["SOURCE"].get(rating) |
| 910 | + filters.append("FILTER @admiralty_source_reliability_stix_id IN doc.object_marking_refs") |
| 911 | + |
| 912 | + if rating := helper.query.get("admiralty_information_credibility"): |
| 913 | + bind_vars["admiralty_information_credibility_stix_id"] = ADMIRALTY_MARKING_MAPPING["INFORMATION"].get(rating) |
| 914 | + filters.append("FILTER @admiralty_information_credibility_stix_id IN doc.object_marking_refs") |
| 915 | + |
870 | 916 | if q := helper.query.get("name"): |
871 | 917 | bind_vars["name"] = q.lower() |
872 | 918 | filters.append("FILTER CONTAINS(LOWER(doc.name), @name)") |
|
0 commit comments