auth_activity 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 6a54b8f73dcb2fc1e97da5d32d41b62b52ed0b9c75c0ecfce1e76259a925bfc2
4
- data.tar.gz: 36060c0d21776ffa7f27a75ccc6d728ad8718590c91f0e836877230c3e6ecd6b
2
+ SHA1:
3
+ metadata.gz: 660f5c0c43b067a4b75e18faf11829380074d497
4
+ data.tar.gz: eb93b6e935017788878059383988d348e0b6fb83
5
5
  SHA512:
6
- metadata.gz: 830350b87dc0d2f14f335eb556b4d41fc9d81c964d0d3700ac508c491875fcd0cbf0e11dc9ec5b17ce59177d45343b070da4fbd198535007cdfd21b8b3730d35
7
- data.tar.gz: 0fae43ad38fcfc7abff573402614f7141a67cfa1f546aa9864c43b61d1fe08d2c99b0f2c6eba05b1441d65dc7cace1c381276fac4165162b78966ce7b0b863c4
6
+ metadata.gz: 54ddc717fda8d91076fa343e21c5a7e41870fb3bce377bdb7546955fc8569b498a136b352b78e27cb0d9b2c0f036c0190441cb144085b7953868bbdbfff297b8
7
+ data.tar.gz: ada5300a388250a37c36428f44ef1e494d467ef37e71f084359ea5a8bda24929faa6fcb9bc796b686a1734197df8568b25710b27c43086893545491fff767a74
@@ -0,0 +1,9 @@
1
+ require_dependency "auth_activity/application_controller"
2
+
3
+ module AuthActivity
4
+ class AuthEventsController < ApplicationController
5
+ def index
6
+ @auth_events = AuthEvent.includes(:trackable).order(created_at: :desc).all
7
+ end
8
+ end
9
+ end
@@ -37,9 +37,9 @@ module AuthActivity
37
37
  return unless login_attempt?
38
38
 
39
39
  if signed_in?
40
- AuthEvent.succesful_login.create(user: user, metadata: { email: email })
40
+ AuthEvent.succesful_login.create(trackable: user, metadata: { email: email })
41
41
  else
42
- AuthEvent.failed_login.create(user: user, metadata: { email: email })
42
+ AuthEvent.failed_login.create(trackable: user, metadata: { email: email })
43
43
  end
44
44
  end
45
45
 
@@ -47,7 +47,7 @@ module AuthActivity
47
47
  return unless password_request_attempt?
48
48
 
49
49
  if user.present?
50
- AuthEvent.succesful_password_request.create(user: user, metadata: { email: email })
50
+ AuthEvent.succesful_password_request.create(trackable: user, metadata: { email: email })
51
51
  else
52
52
  AuthEvent.failed_password_request.create(metadata: { email: email })
53
53
  end
@@ -57,7 +57,7 @@ module AuthActivity
57
57
  if user.present? && logout_action?
58
58
  user = current_user
59
59
  yield
60
- AuthEvent.logout.create(user: user, metadata: { email: user.email })
60
+ AuthEvent.logout.create(trackable: user, metadata: { email: user.email })
61
61
  else
62
62
  yield
63
63
  end
@@ -1,6 +1,6 @@
1
1
  module AuthActivity
2
2
  class AuthEvent < ApplicationRecord
3
- belongs_to :user, optional: true
3
+ belongs_to :trackable, optional: true, polymorphic: true
4
4
 
5
5
  enum action_type: {
6
6
  failed_login: 0,
@@ -10,7 +10,7 @@ module AuthActivity
10
10
  succesful_password_request: 4,
11
11
  user_created: 5,
12
12
  user_destroyed: 6,
13
- logout: 7
13
+ logout: 7
14
14
  }
15
15
  end
16
16
  end
@@ -12,16 +12,16 @@ module AuthActivity::User
12
12
  private
13
13
 
14
14
  def log_created
15
- AuthActivity::AuthEvent.user_created.create!(user: self)
15
+ AuthActivity::AuthEvent.user_created.create!(trackable: self)
16
16
  end
17
17
 
18
18
  def log_changed
19
19
  return unless changed_auth_attributes.any?
20
- AuthActivity::AuthEvent.attributes_changed.create!(user: self, metadata: { attributes_changed: filtered_auth_changes } )
20
+ AuthActivity::AuthEvent.attributes_changed.create!(trackable: self, metadata: { attributes_changed: filtered_auth_changes } )
21
21
  end
22
22
 
23
23
  def log_destroyed
24
- AuthActivity::AuthEvent.user_destroyed.create!(user: self)
24
+ AuthActivity::AuthEvent.user_destroyed.create!(trackable: self)
25
25
  end
26
26
 
27
27
  def changed_auth_attributes
@@ -0,0 +1,9 @@
1
+ <tr id="<%= dom_id(auth_event) %>">
2
+ <td>
3
+ <% if auth_event.trackable.present? %>
4
+ <%= auth_event.trackable.try(:full_name) || auth_event.trackable.id %>
5
+ <% end %>
6
+ </td>
7
+ <td><%= auth_event.action_type %></td>
8
+ <td><%= l auth_event.created_at %></td>
9
+ </tr>
@@ -0,0 +1,10 @@
1
+ <h1>Events</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>User</th>
6
+ <th>Action</th>
7
+ <th>When</th>
8
+ </tr>
9
+ <%= render @auth_events %>
10
+ </table>
@@ -1,2 +1,3 @@
1
1
  AuthActivity::Engine.routes.draw do
2
+ root to: "auth_events#index"
2
3
  end
@@ -0,0 +1,7 @@
1
+ class MakeTrackablePolymorphic < ActiveRecord::Migration[5.2]
2
+ def change
3
+ change_table :auth_activity_auth_events do |t|
4
+ t.references :trackable, polymorphic: true, index: { name: 'index_auth_events_on_trackable_type_and_trackable_id' }
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module AuthActivity
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michiel Sikkes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-14 00:00:00.000000000 Z
12
+ date: 2018-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -68,13 +68,17 @@ files:
68
68
  - app/assets/javascripts/auth_activity/application.js
69
69
  - app/assets/stylesheets/auth_activity/application.css
70
70
  - app/controllers/auth_activity/application_controller.rb
71
+ - app/controllers/auth_activity/auth_events_controller.rb
71
72
  - app/controllers/concerns/auth_activity/auth_logger.rb
72
73
  - app/models/auth_activity/application_record.rb
73
74
  - app/models/auth_activity/auth_event.rb
74
75
  - app/models/concerns/auth_activity/user.rb
76
+ - app/views/auth_activity/auth_events/_auth_event.html.erb
77
+ - app/views/auth_activity/auth_events/index.html.erb
75
78
  - app/views/layouts/auth_activity/application.html.erb
76
79
  - config/routes.rb
77
80
  - db/migrate/20180914084603_create_auth_activity_auth_events.rb
81
+ - db/migrate/20180914211658_make_trackable_polymorphic.rb
78
82
  - lib/auth_activity.rb
79
83
  - lib/auth_activity/engine.rb
80
84
  - lib/auth_activity/version.rb
@@ -99,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
103
  version: '0'
100
104
  requirements: []
101
105
  rubyforge_project:
102
- rubygems_version: 2.7.6
106
+ rubygems_version: 2.5.2.3
103
107
  signing_key:
104
108
  specification_version: 4
105
109
  summary: Authorisation auditing