Class: ForestAdminAgent::Routes::Resources::AuditTrailCorrelation
- Inherits:
-
AbstractAuthenticatedRoute
- Object
- AbstractRoute
- AbstractAuthenticatedRoute
- ForestAdminAgent::Routes::Resources::AuditTrailCorrelation
- Includes:
- AuditTrailRoute
- Defined in:
- lib/forest_admin_agent/routes/resources/audit_trail_correlation.rb
Overview
Correlation-scoped record-history routes, mirroring the Node agent's
/_audit-trail/correlation/:key and /_audit-trail/correlations. Registered only when
config.audit_trail[:database] is set. All three routes are scoped to a single record through the
collection/recordId query (GET) or body (POST) params and share the per-record auth.
Instance Method Summary collapse
Methods included from AuditTrailRoute
#assert_record_in_scope, #audited_projection, #earlier_bound, #first_record, #key_projection, #record_segments, #scoped_record, #serialize_record, #store
Methods inherited from AbstractAuthenticatedRoute
#build, #format_attributes, #redacted_full_projection, #redacted_projection_with_pks
Methods inherited from AbstractRoute
#add_route, #build, #initialize, #routes
Constructor Details
This class inherits a constructor from ForestAdminAgent::Routes::AbstractRoute
Instance Method Details
#handle_batch(args = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/forest_admin_agent/routes/resources/audit_trail_correlation.rb', line 49 def handle_batch(args = {}) collection, record_id = assert_scope(args) correlation_keys = parse_correlation_keys(args) history = if correlation_keys.empty? [] else store.list_by_correlations( collection: collection.name, record_id: record_id, correlation_keys: correlation_keys ) end { name: collection.name, content: { data: history.map { |record| serialize_record(record) } } } end |
#handle_history(args = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/forest_admin_agent/routes/resources/audit_trail_correlation.rb', line 37 def handle_history(args = {}) collection, record_id = assert_scope(args) history = store.list_by_correlation( collection: collection.name, record_id: record_id, correlation_key: args[:params]['correlation_key'] ) { name: collection.name, content: { data: history.map { |record| serialize_record(record) } } } end |
#setup_routes ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/forest_admin_agent/routes/resources/audit_trail_correlation.rb', line 11 def setup_routes return self unless store add_route( 'forest_audit_trail_correlation', 'get', '/_audit-trail/correlation/:correlation_key', ->(args) { handle_history(args) } ) # GET carries the keys in `correlationKeys`; POST accepts a body list to dodge URL limits. add_route( 'forest_audit_trail_correlations', 'get', '/_audit-trail/correlations', ->(args) { handle_batch(args) } ) add_route( 'forest_audit_trail_correlations_batch', 'post', '/_audit-trail/correlations', ->(args) { handle_batch(args) } ) self end |