Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add event logger to reports/alerts CRUD #20249

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions superset/reports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.dashboards.filters import DashboardAccessFilter
from superset.databases.filters import DatabaseFilter
from superset.extensions import event_logger
from superset.models.reports import ReportSchedule
from superset.reports.commands.bulk_delete import BulkDeleteReportScheduleCommand
from superset.reports.commands.create import CreateReportScheduleCommand
Expand Down Expand Up @@ -227,8 +228,12 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]:
@expose("/<int:pk>", methods=["DELETE"])
@protect()
@safe
@statsd_metrics
@permission_name("delete")
@statsd_metrics
@event_logger.log_this_with_context(
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.delete",
log_to_statsd=False,
)
def delete(self, pk: int) -> Response:
"""Delete a Report Schedule
---
Expand Down Expand Up @@ -281,7 +286,9 @@ def delete(self, pk: int) -> Response:
@statsd_metrics
@permission_name("post")
@requires_json
def post(self) -> Response:
def post(
self,
) -> Response:
"""Creates a new Report Schedule
---
post:
Expand Down Expand Up @@ -319,6 +326,16 @@ def post(self) -> Response:
"""
try:
item = self.add_model_schema.load(request.json)
# normally this would be covered by a decorator, however
# due to this model being formatted incorrectly the data
# needed some manipulation.
event_logger.log_with_context(
action="ReportScheduleRestApi.post",
dashboard_id=request.json.get("dashboard", None),
chart_id=request.json.get("chart", None),
report_format=request.json.get("report_format", None),
active=request.json.get("active", None),
)
# This validates custom Schema with custom validations
except ValidationError as error:
return self.response_400(message=error.messages)
Expand Down Expand Up @@ -390,6 +407,16 @@ def put(self, pk: int) -> Response:
"""
try:
item = self.edit_model_schema.load(request.json)
# normally this would be covered by a decorator, however
# due to this model being formatted incorrectly the data
# needed some manipulation.
event_logger.log_with_context(
action="ReportScheduleRestApi.put",
dashboard_id=request.json.get("dashboard", None),
chart_id=request.json.get("chart", None),
report_format=request.json.get("report_format", None),
active=request.json.get("active", None),
)
# This validates custom Schema with custom validations
except ValidationError as error:
return self.response_400(message=error.messages)
Expand All @@ -416,6 +443,10 @@ def put(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.bulk_delete",
log_to_statsd=False,
)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Report Schedule layers
---
Expand Down
Loading