Skip to content

feat(audit): add file view event type to distinguish preview from download#2563

Open
yuuhikaze wants to merge 3 commits intoopencloud-eu:mainfrom
yuuhikaze:feat/file-intent-distinction
Open

feat(audit): add file view event type to distinguish preview from download#2563
yuuhikaze wants to merge 3 commits intoopencloud-eu:mainfrom
yuuhikaze:feat/file-intent-distinction

Conversation

@yuuhikaze
Copy link
Copy Markdown

@yuuhikaze yuuhikaze commented Apr 2, 2026

Summary

Add FileViewed event type to distinguish file previews from downloads in audit logs. Complements opencloud-eu/web#2281 (intent signaling) for complete audit trail distinction.

Purpose

Enable audit trail distinction between file access patterns:

  • file_viewed: File opened for viewing (browser preview, PDF viewer, etc.)
  • file_read: File downloaded/saved locally

This enables policies like:

  • Track who downloads sensitive files
  • Ban downloads of specific types while allowing previews
  • Audit compliance for regulated file types (MP4, PDF, etc.)

Similar to Microsoft 365's intent signaling for compliance and data protection.

Changes

OpenCloud Audit Service

  • New Event Type: AuditEventFileViewed in audit service
  • Event Handler: Converts reva FileViewed events to audit log entries with action file_viewed
  • Registration: FileViewed registered in RegisteredEvents() list

Reva Events

  • Event Type: New events.FileViewed with proper marshaling
  • Middleware Logic: Events middleware checks intent from gRPC Opaque field:
    • oc:intent == 'preview' → emit FileViewed
    • Otherwise → emit FileDownloaded (backward compatible)
  • HTTP Handler: GET handler extracts intent from:
    • Query parameter: ?intent=preview|download
    • HTTP header: X-OC-Intent
    • Adds to gRPC Opaque field for middleware detection

Request Flow

Web UI signals intent [opencloud-eu/web#2281]
  ↓
GET /dav/file?intent=preview
  ↓
Frontend Service extracts intent and adds to gRPC Opaque
  ↓
Reva Events Middleware detects intent and emits appropriate event
  ↓
OpenCloud Audit Service converts to audit log entry
  ↓
Audit Log: action = "file_viewed" or "file_read"

Testing Status

⚠️ Proof of Concept: Changes have not been fully tested. This PR is a reference implementation requiring:

Notes

  • Default intent is 'download' if not specified (backward compatible)
  • Non-breaking change to audit service
  • Existing deployments continue to emit FileDownloaded events

…nload

Add FileViewed event type alongside FileDownloaded for audit logging:
- Reva: Add events.FileViewed event type with Unmarshal() method
- Reva: Modify events middleware to check intent parameter from gRPC Opaque
  - If intent == 'preview', emit FileViewed event
  - Otherwise, emit FileDownloaded event for backward compatibility
- Reva: Extract intent from HTTP query parameters and headers in GET handler
  - Read intent from ?intent= query param or X-OC-Intent header
  - Add to gRPC request Opaque field as 'oc:intent'
- OpenCloud: Add AuditEventFileViewed type and conversion function
- OpenCloud: Register FileViewed event handler in audit service
- OpenCloud: Update RegisteredEvents() to include FileViewed

This enables distinguishing file views from downloads for compliance tracking
and audit logging purposes. Intent is signaled client-side and propagates
through HTTP headers/query parameters to gRPC Opaque field, where the
events middleware uses it to emit appropriate audit events.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add clear comments explaining the event conversion pattern and the purpose
of the new FileViewed event type for audit trail distinction. This improves
code readability and helps maintainers understand the design intent.
Add NOSONAR comment for squid:S3776 (cognitive complexity) to acknowledge
that large switch statements are idiomatic for event type handling.
Document why this pattern is necessary and unavoidable in event systems.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant