Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
144 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class AuditEvent < ActiveRecord::Base | ||
serialize :details, Hash | ||
|
||
belongs_to :user, foreign_key: :author_id | ||
|
||
validates :author_id, presence: true | ||
validates :entity_id, presence: true | ||
validates :entity_type, presence: true | ||
|
||
after_initialize :initialize_details | ||
|
||
def initialize_details | ||
self.details = {} if details.nil? | ||
end | ||
|
||
def author_name | ||
self.user.name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class SecurityEvent < AuditEvent | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class AuditEventService | ||
def initialize(author, entity, details = {}) | ||
@author, @entity, @details = author, entity, details | ||
end | ||
|
||
def for_authentication | ||
@details = { | ||
with: @details[:with], | ||
target_id: @author.id, | ||
target_type: "User", | ||
target_details: @author.name, | ||
} | ||
|
||
self | ||
end | ||
|
||
def security_event | ||
SecurityEvent.create( | ||
author_id: @author.id, | ||
entity_id: @entity.id, | ||
entity_type: @entity.class.name, | ||
details: @details | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
%table.table#audits | ||
%thead | ||
%tr | ||
%th Action | ||
%th When | ||
|
||
%tbody | ||
- events.each do |event| | ||
%tr | ||
%td | ||
%span | ||
Signed in with | ||
%b= event.details[:with] | ||
authentication | ||
%td #{time_ago_in_words event.created_at} ago | ||
= paginate events, theme: "gitlab" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- page_title "Audit Log" | ||
%h3.page-title Audit Log | ||
%p.light History of authentications | ||
|
||
= render 'event_table', events: @events |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class AddAuditEvent < ActiveRecord::Migration | ||
def change | ||
create_table :audit_events do |t| | ||
t.integer :author_id, null: false | ||
t.string :type, null: false | ||
|
||
# "Namespace" where the change occurs | ||
# eg. On a project, group or user | ||
t.integer :entity_id, null: false | ||
t.string :entity_type, null: false | ||
|
||
# Details for the event | ||
t.text :details | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :audit_events, :author_id | ||
add_index :audit_events, :type | ||
add_index :audit_events, [:entity_id, :entity_type] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters