Merge pull request 'Auto-commit local changes before build (2026-01-03 12:21:44)' (#14) from v20260103-01-reports-jobs-delete into main

Reviewed-on: #14
This commit is contained in:
Ivo Oskamp 2026-01-06 09:24:49 +01:00
commit 2eeb8266c7
3 changed files with 29 additions and 12 deletions

View File

@ -1 +1 @@
v20260101-15-changelog-0-1-15
v20260103-01-reports-jobs-delete

View File

@ -163,6 +163,20 @@ def api_reports_create():
return {"id": r.id}
@main_bp.route("/api/reports/<int:report_id>", methods=["DELETE"])
@login_required
def api_reports_delete(report_id: int):
err = _require_reporting_role()
if err is not None:
return err
report = ReportDefinition.query.get_or_404(report_id)
db.session.delete(report)
db.session.commit()
return {"status": "ok"}
@main_bp.route("/api/reports/<int:report_id>/generate", methods=["POST"])
@login_required
def api_reports_generate(report_id: int):
@ -191,7 +205,7 @@ def api_reports_generate(report_id: int):
where_customer = ""
params = {"rid": report_id, "start_ts": report.period_start, "end_ts": report.period_end}
if scope in ("single", "multiple") and customer_ids:
where_customer = " AND c.id = ANY(:customer_ids) "
where_customer = " AND j.customer_id = ANY(:customer_ids) "
params["customer_ids"] = customer_ids
db.session.execute(
@ -203,27 +217,25 @@ def api_reports_generate(report_id: int):
override_applied, reviewed_at, ticket_number, remark, created_at)
SELECT
:rid AS report_id,
co.object_name AS object_name,
COALESCE(j.job_name, '(unknown job)') AS object_name,
j.id AS job_id,
j.job_name AS job_name,
c.id AS customer_id,
j.customer_id AS customer_id,
c.name AS customer_name,
j.backup_software AS backup_software,
j.backup_type AS backup_type,
jr.id AS run_id,
jr.run_at AS run_at,
COALESCE(rol.status, jr.status) AS status,
jr.status AS status,
COALESCE(jr.missed, FALSE) AS missed,
COALESCE(jr.override_applied, FALSE) AS override_applied,
jr.reviewed_at AS reviewed_at,
NULL AS ticket_number,
jr.remark AS remark,
NOW() AS created_at
FROM run_object_links rol
JOIN customer_objects co ON co.id = rol.customer_object_id
JOIN customers c ON c.id = co.customer_id
JOIN job_runs jr ON jr.id = rol.run_id
FROM job_runs jr
JOIN jobs j ON j.id = jr.job_id
LEFT JOIN customers c ON c.id = j.customer_id
WHERE jr.run_at IS NOT NULL
AND jr.run_at >= :start_ts
AND jr.run_at < :end_ts
@ -242,7 +254,7 @@ def api_reports_generate(report_id: int):
warning_count, failed_count, missed_count, success_rate, created_at)
SELECT
:rid AS report_id,
s.object_name AS object_name,
COALESCE(s.job_name, '(unknown job)') AS object_name,
COUNT(*)::INTEGER AS total_runs,
SUM(CASE WHEN (COALESCE(s.status,'') ILIKE 'success%' AND s.override_applied = FALSE) THEN 1 ELSE 0 END)::INTEGER AS success_count,
SUM(CASE WHEN (s.override_applied = TRUE) THEN 1 ELSE 0 END)::INTEGER AS success_override_count,
@ -261,7 +273,7 @@ def api_reports_generate(report_id: int):
NOW() AS created_at
FROM report_object_snapshots s
WHERE s.report_id = :rid
GROUP BY s.object_name
GROUP BY s.job_id, s.job_name
'''
),
{"rid": report_id},

View File

@ -1,3 +1,8 @@
## v20260103-01-reports-jobs-delete
- Changed report output to aggregate results per job instead of listing individual objects, making reports more suitable for high-level job status review.
- Updated report generation logic to build snapshots and summaries based on job runs.
- Added the ability to delete reports, including removal of all associated report data.
================================================================================================================================================