ahoy_email 2.0.2 → 2.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
2
  SHA256:
3
- metadata.gz: 12cfd52040334d8582ee01785c46c290d9a8e125d79ea5a5cddabed3d26ed144
4
- data.tar.gz: db924f04d522c4bb9fd488fb34533349b231148170de637fff11ca34c6c18b36
3
+ metadata.gz: c5533583685af32099af8100fe872c8dd146b1b3539d373ba99c12774745c24f
4
+ data.tar.gz: d4aa807926b5e0d70421c75dbc507ddd1ffeb7856c9c1706c71d4a6ff922dd38
5
5
  SHA512:
6
- metadata.gz: ba35f76f9d5bb2d52972ab648179e710c16eeda09bc51b4f91aff083bad354ec5dd6b8c98985b913efbf40c9e3215a3111e2a45978c647cf2fa8d9bd96519925
7
- data.tar.gz: 1247bc81b9cc52a43ec480640c4c94989cfcf7ac4c0868c5c5cdeb0d85da013f93e9bc61993f78d94a8191819e6b7c76d6593f84d70203ed329793debbf7df2a
6
+ metadata.gz: 81ce556e09096d9ffbddcecbfd512023ff86f5acee6a8327634f37fe054d9b1547706b92d7de812c8932fe79257cef380976e0a8101467085d45865dfe45f967
7
+ data.tar.gz: 830f93a92a24c1d5a338bcf48555df6684e227c07da331b47b8362698f1f928b0282364d13d6533f4d8dfb46b75fa615b60f807b334e6d77c5dfab9fc05dfcd2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 2.1.2 (2022-02-09)
2
+
3
+ - Fixed external redirects with Rails 7
4
+
5
+ ## 2.1.1 (2021-12-13)
6
+
7
+ - Added experimental support for Active Record encryption
8
+
9
+ ## 2.1.0 (2021-09-25)
10
+
11
+ - Fixed mailer `default_url_options` not being applied to click links
12
+
13
+ ## 2.0.3 (2021-03-31)
14
+
15
+ - Fixed `utm_params` and `track_clicks` stripping `<head>` tags from messages
16
+
1
17
  ## 2.0.2 (2021-03-14)
2
18
 
3
19
  - Added support for Mongoid to database subscriber
data/README.md CHANGED
@@ -28,17 +28,24 @@ There are three main features, which can be used independently:
28
28
 
29
29
  ## Message History
30
30
 
31
- To encrypt email addresses, install [Lockbox](https://github.com/ankane/lockbox) and [Blind Index](https://github.com/ankane/blind_index) and run:
31
+ To encrypt email addresses with Lockbox, install [Lockbox](https://github.com/ankane/lockbox) and [Blind Index](https://github.com/ankane/blind_index) and run:
32
32
 
33
33
  ```sh
34
- rails generate ahoy:messages
34
+ rails generate ahoy:messages --encryption=lockbox
35
+ rails db:migrate
36
+ ```
37
+
38
+ To use Active Record encryption (Rails 7+, experimental), run:
39
+
40
+ ```sh
41
+ rails generate ahoy:messages --encryption=activerecord
35
42
  rails db:migrate
36
43
  ```
37
44
 
38
45
  If you prefer not to encrypt data, run:
39
46
 
40
47
  ```sh
41
- rails generate ahoy:messages --unencrypted
48
+ rails generate ahoy:messages --encryption=none
42
49
  rails db:migrate
43
50
  ```
44
51
 
@@ -157,7 +164,7 @@ Ahoy::Message.where("created_at < ?", 1.year.ago).in_batches.delete_all
157
164
  Delete data for a specific user with:
158
165
 
159
166
  ```ruby
160
- Ahoy::Message.where(user_id: 1).in_batches.delete_all
167
+ Ahoy::Message.where(user_id: 1, user_type: "User").in_batches.delete_all
161
168
  ```
162
169
 
163
170
  ## UTM Tagging
@@ -285,6 +292,14 @@ class CouponMailer < ApplicationMailer
285
292
  end
286
293
  ```
287
294
 
295
+ You can also use a proc
296
+
297
+ ```ruby
298
+ class CouponMailer < ApplicationMailer
299
+ track_clicks campaign: -> { "coupon-#{action_name}" }
300
+ end
301
+ ```
302
+
288
303
  Skip specific links with:
289
304
 
290
305
  ```erb
@@ -25,6 +25,9 @@ module Ahoy
25
25
  expected_signature = AhoyEmail::Utils.signature(token: token, campaign: campaign, url: url)
26
26
  end
27
27
 
28
+ redirect_options = {}
29
+ redirect_options[:allow_other_host] = true if ActionPack::VERSION::MAJOR >= 7
30
+
28
31
  if ActiveSupport::SecurityUtils.secure_compare(signature, expected_signature)
29
32
  data = {}
30
33
  data[:campaign] = campaign if campaign
@@ -33,10 +36,10 @@ module Ahoy
33
36
  data[:controller] = self
34
37
  AhoyEmail::Utils.publish(:click, data)
35
38
 
36
- redirect_to url
39
+ redirect_to url, **redirect_options
37
40
  else
38
41
  if AhoyEmail.invalid_redirect_url
39
- redirect_to AhoyEmail.invalid_redirect_url
42
+ redirect_to AhoyEmail.invalid_redirect_url, **redirect_options
40
43
  else
41
44
  render plain: "Link expired", status: :not_found
42
45
  end
@@ -53,7 +53,7 @@ module AhoyEmail
53
53
  if html_part?
54
54
  part = message.html_part || message
55
55
 
56
- doc = Nokogiri::HTML::DocumentFragment.parse(part.body.raw_source)
56
+ doc = Nokogiri::HTML::Document.parse(part.body.raw_source)
57
57
  doc.css("a[href]").each do |link|
58
58
  uri = parse_uri(link["href"])
59
59
  next unless trackable?(uri)
@@ -123,7 +123,7 @@ module AhoyEmail
123
123
  end
124
124
 
125
125
  def url_for(opt)
126
- opt = (ActionMailer::Base.default_url_options || {})
126
+ opt = (mailer.default_url_options || {})
127
127
  .merge(options[:url_options])
128
128
  .merge(opt)
129
129
  AhoyEmail::Engine.routes.url_helpers.url_for(opt)
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -7,15 +7,21 @@ module Ahoy
7
7
  include ActiveRecord::Generators::Migration
8
8
  source_root File.join(__dir__, "templates")
9
9
 
10
+ class_option :encryption, type: :string
11
+ # deprecated
10
12
  class_option :unencrypted, type: :boolean
11
13
 
12
14
  def copy_migration
15
+ encryption # ensure valid
13
16
  migration_template "migration.rb", "db/migrate/create_ahoy_messages.rb", migration_version: migration_version
14
17
  end
15
18
 
16
19
  def copy_template
17
- if encrypted?
18
- template "model_encrypted.rb", "app/models/ahoy/message.rb"
20
+ case encryption
21
+ when "lockbox"
22
+ template "model_lockbox.rb", "app/models/ahoy/message.rb"
23
+ when "activerecord"
24
+ template "model_activerecord.rb", "app/models/ahoy/message.rb"
19
25
  end
20
26
  end
21
27
 
@@ -24,15 +30,30 @@ module Ahoy
24
30
  end
25
31
 
26
32
  def to_column
27
- if encrypted?
33
+ case encryption
34
+ when "lockbox"
28
35
  "t.text :to_ciphertext\n t.string :to_bidx, index: true"
29
36
  else
37
+ # TODO add limit: 510 for Active Record encryption + MySQL?
30
38
  "t.string :to, index: true"
31
39
  end
32
40
  end
33
41
 
34
- def encrypted?
35
- !options[:unencrypted]
42
+ # TODO remove default
43
+ def encryption
44
+ case options[:encryption]
45
+ when "lockbox", "activerecord", "none"
46
+ options[:encryption]
47
+ when nil
48
+ if options[:unencrypted]
49
+ # TODO deprecation warning
50
+ "none"
51
+ else
52
+ "lockbox"
53
+ end
54
+ else
55
+ abort "Error: encryption must be lockbox, activerecord, or none"
56
+ end
36
57
  end
37
58
  end
38
59
  end
@@ -6,13 +6,33 @@ module Ahoy
6
6
  class MongoidGenerator < Rails::Generators::Base
7
7
  source_root File.join(__dir__, "templates")
8
8
 
9
+ class_option :encryption, type: :string
10
+ # deprecated
9
11
  class_option :unencrypted, type: :boolean
10
12
 
11
13
  def copy_templates
12
- if options[:unencrypted]
14
+ case encryption
15
+ when "lockbox"
16
+ template "mongoid_lockbox.rb", "app/models/ahoy/message.rb"
17
+ else
13
18
  template "mongoid.rb", "app/models/ahoy/message.rb"
19
+ end
20
+ end
21
+
22
+ # TODO remove default
23
+ def encryption
24
+ case options[:encryption]
25
+ when "lockbox", "none"
26
+ options[:encryption]
27
+ when nil
28
+ if options[:unencrypted]
29
+ # TODO deprecation warning
30
+ "none"
31
+ else
32
+ "lockbox"
33
+ end
14
34
  else
15
- template "mongoid_encrypted.rb", "app/models/ahoy/message.rb"
35
+ abort "Error: encryption must be lockbox or none"
16
36
  end
17
37
  end
18
38
  end
@@ -0,0 +1,7 @@
1
+ class Ahoy::Message < ActiveRecord::Base
2
+ self.table_name = "ahoy_messages"
3
+
4
+ belongs_to :user, polymorphic: true, optional: true
5
+
6
+ encrypts :to, deterministic: true
7
+ end
@@ -3,6 +3,8 @@ require "rails/generators"
3
3
  module Ahoy
4
4
  module Generators
5
5
  class MessagesGenerator < Rails::Generators::Base
6
+ class_option :encryption, type: :string
7
+ # deprecated
6
8
  class_option :unencrypted, type: :boolean
7
9
 
8
10
  def copy_templates
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -99,9 +99,10 @@ files:
99
99
  - lib/generators/ahoy/messages/activerecord_generator.rb
100
100
  - lib/generators/ahoy/messages/mongoid_generator.rb
101
101
  - lib/generators/ahoy/messages/templates/migration.rb.tt
102
- - lib/generators/ahoy/messages/templates/model_encrypted.rb.tt
102
+ - lib/generators/ahoy/messages/templates/model_activerecord.rb.tt
103
+ - lib/generators/ahoy/messages/templates/model_lockbox.rb.tt
103
104
  - lib/generators/ahoy/messages/templates/mongoid.rb.tt
104
- - lib/generators/ahoy/messages/templates/mongoid_encrypted.rb.tt
105
+ - lib/generators/ahoy/messages/templates/mongoid_lockbox.rb.tt
105
106
  - lib/generators/ahoy/messages_generator.rb
106
107
  homepage: https://github.com/ankane/ahoy_email
107
108
  licenses:
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 3.2.3
126
+ rubygems_version: 3.3.3
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: First-party email analytics for Rails