From fa20e53b58f6b34d88c3c52a553ba9168b457388 Mon Sep 17 00:00:00 2001 From: Doston Toirov <31990136+Dostonbek1@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:03:56 -0500 Subject: [PATCH] [AAP-18790] Remove Audit Events endpoints (#561) * Remove /audit-events/ endpoints as they are not used by the UI Solves: AAP-18790 Co-authored-by: Alex --- src/aap_eda/api/urls.py | 1 - src/aap_eda/api/views/__init__.py | 2 - src/aap_eda/api/views/rulebook.py | 38 ---------- tests/integration/api/test_rulebook.py | 96 -------------------------- 4 files changed, 137 deletions(-) diff --git a/src/aap_eda/api/urls.py b/src/aap_eda/api/urls.py index 80b20b8a6..0e8ea86d6 100644 --- a/src/aap_eda/api/urls.py +++ b/src/aap_eda/api/urls.py @@ -34,7 +34,6 @@ router.register("activations", views.ActivationViewSet) router.register("activation-instances", views.ActivationInstanceViewSet) router.register("audit-rules", views.AuditRuleViewSet) -router.register("audit-events", views.AuditEventViewSet) router.register("users", views.UserViewSet) router.register( "users/me/awx-tokens", diff --git a/src/aap_eda/api/views/__init__.py b/src/aap_eda/api/views/__init__.py index e8b292d36..ea4b3e433 100644 --- a/src/aap_eda/api/views/__init__.py +++ b/src/aap_eda/api/views/__init__.py @@ -18,7 +18,6 @@ from .decision_environment import DecisionEnvironmentViewSet from .project import ExtraVarViewSet, ProjectViewSet from .rulebook import ( - AuditEventViewSet, AuditRuleViewSet, RulebookViewSet, RulesetViewSet, @@ -35,7 +34,6 @@ # project "ExtraVarViewSet", "ProjectViewSet", - "AuditEventViewSet", "AuditRuleViewSet", "RulebookViewSet", "RulesetViewSet", diff --git a/src/aap_eda/api/views/rulebook.py b/src/aap_eda/api/views/rulebook.py index 700824edd..f472560a3 100644 --- a/src/aap_eda/api/views/rulebook.py +++ b/src/aap_eda/api/views/rulebook.py @@ -321,44 +321,6 @@ def events(self, _request, id): return self.get_paginated_response(serializer.data) -@extend_schema_view( - retrieve=extend_schema( - description="Get the audit event by its id", - responses={ - status.HTTP_200_OK: OpenApiResponse( - serializers.AuditEventSerializer, - description="Return the audit event by its id.", - ), - }, - ), - list=extend_schema( - description="List all audit events", - responses={ - status.HTTP_200_OK: OpenApiResponse( - serializers.AuditEventSerializer, - description="Return a list of audit events.", - ), - }, - ), -) -class AuditEventViewSet( - viewsets.ReadOnlyModelViewSet, -): - queryset = models.AuditEvent.objects.all() - serializer_class = serializers.AuditEventSerializer - filter_backends = (defaultfilters.DjangoFilterBackend, OrderingFilter) - filterset_class = filters.AuditRuleEventFilter - ordering_fields = [ - "id", - "source_name", - "source_type", - "received_at", - "rule_fired_at", - ] - - rbac_resource_type = ResourceType.AUDIT_EVENT - - class RuleViewSet( viewsets.ReadOnlyModelViewSet, ): diff --git a/tests/integration/api/test_rulebook.py b/tests/integration/api/test_rulebook.py index 69b61d79c..ebe87cbc1 100644 --- a/tests/integration/api/test_rulebook.py +++ b/tests/integration/api/test_rulebook.py @@ -580,102 +580,6 @@ def test_list_events_from_audit_rule_ordering( ) -# ------------------------------------------ -# Test Audit Event: -# ------------------------------------------ -@pytest.mark.django_db -def test_list_audit_events(client: APIClient, init_db): - response = client.get(f"{api_url_v1}/audit-events/") - assert response.status_code == status.HTTP_200_OK - audit_events = response.data["results"] - - assert len(audit_events) == 4 - assert audit_events[0]["received_at"] > audit_events[1]["received_at"] - - -@pytest.mark.django_db -def test_list_audit_events_filter_name(client: APIClient, init_db): - filter_name = "event-1" - - response = client.get( - f"{api_url_v1}/audit-events/?source_name={filter_name}" - ) - assert response.status_code == status.HTTP_200_OK - filtered_audit_events = response.data["results"] - - assert len(filtered_audit_events) == 1 - assert filtered_audit_events[0]["source_name"] == "event-1" - assert list(filtered_audit_events[0]) == [ - "id", - "source_name", - "source_type", - "received_at", - "payload", - "rule_fired_at", - "audit_actions", - ] - - -@pytest.mark.django_db -def test_list_audit_events_filter_name_non_existent( - client: APIClient, init_db -): - filter_name = "doesn't exist" - - response = client.get( - f"{api_url_v1}/audit-events/?source_name={filter_name}" - ) - assert response.status_code == status.HTTP_200_OK - data = response.json()["results"] - assert data == [] - - -@pytest.mark.parametrize( - "ordering_field", - ["source_name", "source_type", "received_at", "rule_fired_at"], -) -@pytest.mark.django_db -def test_list_events_ordering(client: APIClient, init_db, ordering_field): - audit_rule_id = init_db.audit_rule_1.id - response = client.get( - f"{api_url_v1}/audit-rules/{audit_rule_id}/events/?ordering=" - f"{ordering_field}" - ) - assert response.status_code == status.HTTP_200_OK - events = response.data["results"] - assert len(events) == 4 - assert events[0][ordering_field] == getattr( - init_db.audit_event_1, ordering_field - ) - - response = client.get( - f"{api_url_v1}/audit-rules/{audit_rule_id}/events/?ordering=" - f"-{ordering_field}" - ) - assert response.status_code == status.HTTP_200_OK - events = response.data["results"] - assert len(events) == 4 - assert events[0][ordering_field] == getattr( - init_db.audit_event_4, ordering_field - ) - - -@pytest.mark.django_db -def test_retrieve_audit_event(client: APIClient, init_db): - audit_event_id = init_db.audit_event_1.id - - response = client.get(f"{api_url_v1}/audit-events/{audit_event_id}/") - - assert response.status_code == status.HTTP_200_OK - assert response.data["source_name"] == "event-1" - - -@pytest.mark.django_db -def test_retrieve_audit_event_not_exist(client: APIClient): - response = client.get(f"{api_url_v1}/audit-events/42/") - assert response.status_code == status.HTTP_404_NOT_FOUND - - @pytest.mark.django_db def test_delete_project_and_rulebooks(client: APIClient, init_db): project_id = init_db.project.id