Service Layer low complexity backend
2
Dependencies
1
Dependents
2
Entities
0
Integrations

Description

Business logic layer responsible for fetching, filtering, and managing the audit log of generated Bufdir reports. Enforces role-based access, ensuring only coordinators and admins can access the history.

Feature: Bufdir Report History & Audit Log

report-history-service

Summaries

The Report History Service is the authoritative access control gate for all historical Bufdir report data within the platform. By centralising role enforcement — restricting access to coordinators and admins only — it protects sensitive submission records from unauthorised viewing, directly reducing compliance and data-governance risk. The service also resolves secure, time-limited download URLs, meaning report files are never exposed via permanent public links, further strengthening the organisation's data security posture. This centralised approach ensures that policy changes to access rules are applied consistently across every touchpoint without requiring UI-level changes.

Medium-priority backend component with two direct dependencies: the Report History Repository and the Report File Storage Client. Both must be available before integration testing can begin, making this a mid-sprint deliverable contingent on those components being scaffolded first. Development complexity is low — primarily thin orchestration over repository calls plus a role check. Key delivery risks are the signed URL expiry window (must be agreed with the storage infrastructure team) and ensuring pagination parameters are consistent with the frontend's page-size expectations.

Unit tests should cover role denial scenarios, empty result sets, and storage client failures with graceful error propagation.

Report History Service sits in the backend execution context and acts as the application-layer facade over the Report History Repository and Report File Storage Client. getReportHistory(orgId, {limit, offset}) delegates directly to the repository's getHistoryByOrg with pagination forwarded unchanged. validateRoleAccess(userRole) should throw an AuthorizationException for any role outside coordinator and admin before any database call is made. getSignedDownloadUrl(fileRef) calls the storage client to produce a short-lived pre-signed URL — cache the result per request but do not persist it.

filterByPeriod(from, to) applies date range constraints at the repository query level. Ensure all public methods are async and propagate repository errors with context-enriched messages for upstream error handlers.

Responsibilities

  • Fetch paginated report history scoped to organization
  • Enforce coordinator and admin role access
  • Resolve signed download URLs for stored report files
  • Support filtering by date range or reporting period

Interfaces

getReportHistory(orgId, {limit, offset})
getReportById(reportId)
getSignedDownloadUrl(fileRef)
filterByPeriod(from, to)
validateRoleAccess(userRole)

Relationships

Dependencies (2)

Components this component depends on

Dependents (1)

Components that depend on this component

Related Data Entities (2)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/report-history 6 endpoints
GET /api/v1/report-history List report history for an organisation with optional period filtering
GET /api/v1/report-history/:report_id Retrieve a single historical report record
GET /api/v1/report-history/:report_id/download-url Generate a signed download URL for a report file
POST /api/v1/report-history Create a new report history record
PUT /api/v1/report-history/:report_id Update an existing report history record (e.g. attach file_ref on completion)
DELETE /api/v1/report-history/:report_id Delete a report history record (retention policy enforcement applies)