Class: AuditEventService

Inherits:
Object
  • Object
show all
Defined in:
app/services/audit_event_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(author, entity, details = {}) ⇒ AuditEventService

Instantiates a new service

Parameters:

  • author (User)

    the user who authors the change

  • entity (User, Project, Group)

    the scope which audit event belongs to This param is also used to determine the visibility of the audit event.

    • Project: events are visible at Project and Instance level

    • Group: events are visible at Group and Instance level

    • User: events are visible at Instance level

  • details (Hash) (defaults to: {})

    extra data of audit event


15
16
17
18
19
20
# File 'app/services/audit_event_service.rb', line 15

def initialize(author, entity, details = {})
  @author = build_author(author)
  @entity = entity
  @details = details
  @ip_address = (@details[:ip_address].presence || @author.)
end

Instance Method Details

#for_authenticationAuditEventService

Builds the @details attribute for authentication

This uses the @author as the target object being audited

Returns:


27
28
29
30
31
32
33
34
35
36
# File 'app/services/audit_event_service.rb', line 27

def for_authentication
  @details = {
    with: @details[:with],
    target_id: @author.id,
    target_type: 'User',
    target_details: @author.name
  }

  self
end

#log_security_event_to_fileObject

Writes event to a file


47
48
49
# File 'app/services/audit_event_service.rb', line 47

def log_security_event_to_file
  file_logger.info(base_payload.merge(formatted_details))
end

#security_eventAuditEvent

Writes event to a file and creates an event record in DB

Returns:

  • (AuditEvent)

    persited if saves and non-persisted if fails


41
42
43
44
# File 'app/services/audit_event_service.rb', line 41

def security_event
  log_security_event_to_file
  log_security_event_to_database
end