auth_activity 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b7618cb4527bcbdb6bc80ba2805aeedbf91014f1
4
- data.tar.gz: a5ae8e4baba046dfa8ced6e1e26d8e7fc6a12dc3
2
+ SHA256:
3
+ metadata.gz: f82ede4f51f2663e17393e2959b0e5f719743fed770bd734df1d1b528148266f
4
+ data.tar.gz: 2074e32f692e6b558209b7a12ef228f827b4080a1ba9f15b071b947f36d437ff
5
5
  SHA512:
6
- metadata.gz: 55294703a626123cc20ec2cf840f7cbe37fa36b7f923334d078030f71fc8b4e0629c6414ac8c8995b1d9360400bcb58a018979ebbfac57ef3c6ac572cc01b8b1
7
- data.tar.gz: ef1a7d86b70c14198094d713a519328d0b44f2ec473369311c6162af50cf0ea509dd8bbdcf0a4931eea9c4856532cc3e0ee79e4f938403923ff58d9f7c21097a
6
+ metadata.gz: 1b29277bff373bf247c4a0a740f769a48cb4d1028e85484330203fc8a4637b85e736261f3fb005c2a113aaf0b8f0f42f865afdaf967fa9c8d7ba902f463b3325
7
+ data.tar.gz: 96cb6ed9980c09bd60412695c1b019284cfc9af0ffd72efd49cfc35a09686ecaf6f8f25fa3daf6e207dc4190cebb53fe08a5bbe96b03abadae70180c3ef894e1
@@ -0,0 +1,6 @@
1
+ module AuthActivity
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: AuthActivity::Engine.config.mailer_from || "Example <no-reply@example.com>"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ require_dependency "auth_activity/application_mailer"
2
+
3
+ module AuthActivity
4
+ class UserMailer < ApplicationMailer
5
+ def password_changed(user)
6
+ @user = user
7
+
8
+ mail to: @user.email, subject: I18n.t(".password_changed_subject")
9
+ end
10
+ end
11
+ end
@@ -1,14 +1,18 @@
1
1
  module AuthActivity::User
2
- AUTH_ATTRIBUTES = %w[email encrypted_password]
3
- FILTER_ATTRIBUTES = %w[encrypted_password]
2
+ AUTH_ATTRIBUTES = %w[email encrypted_password].freeze
3
+ FILTER_ATTRIBUTES = %w[encrypted_password].freeze
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- after_update :log_changed
7
+ after_update :log_changed, :send_password_changed_email
8
8
  after_create :log_created
9
9
  after_destroy :log_destroyed
10
10
  end
11
11
 
12
+ def plausible_name
13
+ try(:full_name) || try(:name) || [try(:first_name), try(:last_name)].compact.join(" ")
14
+ end
15
+
12
16
  private
13
17
 
14
18
  def log_created
@@ -17,7 +21,10 @@ module AuthActivity::User
17
21
 
18
22
  def log_changed
19
23
  return unless changed_auth_attributes.any?
20
- AuthActivity::AuthEvent.attributes_changed.create!(trackable: self, metadata: { attributes_changed: filtered_auth_changes } )
24
+
25
+ AuthActivity::AuthEvent.
26
+ attributes_changed.create!(trackable: self,
27
+ metadata: { attributes_changed: filtered_auth_changes })
21
28
  end
22
29
 
23
30
  def log_destroyed
@@ -29,16 +36,21 @@ module AuthActivity::User
29
36
  end
30
37
 
31
38
  def filtered_auth_changes
32
- auth_changes.update(auth_changes) do |k,v|
33
- if k.in? FILTER_ATTRIBUTES
34
- return { k => ["[filtered]", "[filtered]"] }
35
- else
36
- { k => v }
37
- end
39
+ auth_changes.update(auth_changes) do |k, v|
40
+ return { k => ["[filtered]", "[filtered]"] } if k.in? FILTER_ATTRIBUTES
41
+
42
+ { k => v }
38
43
  end
39
44
  end
40
45
 
41
46
  def auth_changes
42
- saved_changes.select { |k,v| k.in?(changed_auth_attributes) }
47
+ saved_changes.select { |k| k.in?(changed_auth_attributes) }
48
+ end
49
+
50
+ def send_password_changed_email
51
+ return unless AuthActivity::Engine.config.enable_password_changed_email
52
+ return unless saved_changes.key?(:encrypted_password)
53
+
54
+ UserMailer.password_changed(self).deliver_later
43
55
  end
44
56
  end
@@ -8,7 +8,7 @@
8
8
  <th>When</th>
9
9
  </tr>
10
10
  </thead>
11
- <%= render @auth_events %>
11
+ <%= render 'auth_event', collection: @auth_events %>
12
12
  </table>
13
13
 
14
14
  <%= paginate @auth_events %>
@@ -0,0 +1,2 @@
1
+ <p>Hi <%= @user.plausible_name %>,</p>
2
+ <p><%= I18n.t(".password_changed_text") %></p>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ en:
2
+ password_changed_text: "Someone just changed your password. Hopefully it was you, but if not, please reach out to us as soon as possible."
3
+ password_changed_subject: "Your password has been changed"
@@ -1,3 +1,3 @@
1
1
  module AuthActivity
2
- VERSION = '0.1.3'
2
+ VERSION = "0.1.4".freeze
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.3
4
+ version: 0.1.4
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-21 00:00:00.000000000 Z
12
+ date: 2019-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -86,12 +86,15 @@ files:
86
86
  - app/controllers/auth_activity/application_controller.rb
87
87
  - app/controllers/auth_activity/auth_events_controller.rb
88
88
  - app/controllers/concerns/auth_activity/auth_logger.rb
89
+ - app/mailers/auth_activity/application_mailer.rb
90
+ - app/mailers/auth_activity/user_mailer.rb
89
91
  - app/models/auth_activity/application_record.rb
90
92
  - app/models/auth_activity/auth_event.rb
91
93
  - app/models/auth_activity/current.rb
92
94
  - app/models/concerns/auth_activity/user.rb
93
95
  - app/views/auth_activity/auth_events/_auth_event.html.erb
94
96
  - app/views/auth_activity/auth_events/index.html.erb
97
+ - app/views/auth_activity/user_mailer/password_changed.html.erb
95
98
  - app/views/kaminari/_first_page.html.erb
96
99
  - app/views/kaminari/_gap.html.erb
97
100
  - app/views/kaminari/_last_page.html.erb
@@ -100,6 +103,9 @@ files:
100
103
  - app/views/kaminari/_paginator.html.erb
101
104
  - app/views/kaminari/_prev_page.html.erb
102
105
  - app/views/layouts/auth_activity/application.html.erb
106
+ - app/views/layouts/auth_activity/mailer.html.erb
107
+ - app/views/layouts/auth_activity/mailer.text.erb
108
+ - config/locales/en.yml
103
109
  - config/routes.rb
104
110
  - db/migrate/20180914084603_create_auth_activity_auth_events.rb
105
111
  - db/migrate/20180914211658_make_trackable_polymorphic.rb
@@ -126,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  - !ruby/object:Gem::Version
127
133
  version: '0'
128
134
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.5.2.3
135
+ rubygems_version: 3.0.4
131
136
  signing_key:
132
137
  specification_version: 4
133
138
  summary: Authorisation auditing