feat: hide event types from SAC UI via Settings checkbox (0.20.23)

Per-type «Показывать в событиях» in severity settings; filters lists, dashboard, hosts, and problems.
This commit is contained in:
2026-06-21 20:13:40 +10:00
parent 87ac1e09b0
commit bf7c83c408
15 changed files with 313 additions and 60 deletions
@@ -0,0 +1,76 @@
"""Tests for hiding event types from SAC UI."""
import uuid
from app.models.event_type_visibility import EventTypeVisibility
VALID_EVENT = {
"schema_version": "1.0",
"event_id": "550e8400-e29b-41d4-a716-446655440000",
"occurred_at": "2026-05-27T10:00:00+03:00",
"source": {"product": "rdp-login-monitor", "product_version": "1.2.3-SAC"},
"host": {"hostname": "test-host", "os_family": "windows"},
"category": "auth",
"type": "agent.heartbeat",
"severity": "info",
"title": "Heartbeat",
"summary": "pytest",
}
LOGIN_EVENT = {
**VALID_EVENT,
"type": "rdp.login.success",
"title": "RDP login",
"summary": "login pytest",
}
def _ingest(client, auth_headers, payload):
event_id = str(uuid.uuid4())
r = client.post("/api/v1/events", json={**payload, "event_id": event_id}, headers=auth_headers)
assert r.status_code == 201
return event_id
def test_hidden_event_type_excluded_from_list(client, auth_headers, jwt_headers, db_session):
db_session.add(EventTypeVisibility(event_type="agent.heartbeat", show_in_events=False))
db_session.commit()
hb_id = _ingest(client, auth_headers, VALID_EVENT)
login_id = _ingest(client, auth_headers, LOGIN_EVENT)
listed = client.get("/api/v1/events", headers=jwt_headers)
assert listed.status_code == 200
ids = {item["event_id"] for item in listed.json()["items"]}
assert hb_id not in ids
assert login_id in ids
def test_hidden_event_type_returns_404_on_detail(client, auth_headers, jwt_headers, db_session):
db_session.add(EventTypeVisibility(event_type="agent.heartbeat", show_in_events=False))
db_session.commit()
_ingest(client, auth_headers, VALID_EVENT)
listed = client.get("/api/v1/events", headers=jwt_headers, params={"type": "agent.heartbeat"})
assert listed.json()["total"] == 0
def test_visibility_settings_api(client, jwt_headers, db_session):
put = client.put(
"/api/v1/settings/notifications/severity-overrides",
headers=jwt_headers,
json={"visibility": {"agent.heartbeat": False}},
)
assert put.status_code == 200
items = {i["event_type"]: i for i in put.json()["items"]}
assert items["agent.heartbeat"]["show_in_events"] is False
assert items["rdp.login.success"]["show_in_events"] is True
reset = client.put(
"/api/v1/settings/notifications/severity-overrides",
headers=jwt_headers,
json={"visibility": {"agent.heartbeat": None}},
)
assert reset.status_code == 200
items = {i["event_type"]: i for i in reset.json()["items"]}
assert items["agent.heartbeat"]["show_in_events"] is True