ahoy_email 2.1.0 → 2.1.1

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: b84f8c566d81a470ba99f4318c2d7dd3f1b3fae6b05155491f486cbdbff7c0a6
4
- data.tar.gz: 8ab62441cf6df6b4ab6af401a9cbed8864ac634d28dd728f6b83bfd743dce284
3
+ metadata.gz: bf88f44f04ee798926e9363928aed4be7c34d0b4f5456b01f1dc210f18967cc4
4
+ data.tar.gz: bb0c2ea92f067cbd6f37f7d06bb7700f51427dd68f178d0405ccf31f02b21fea
5
5
  SHA512:
6
- metadata.gz: cf70b92f9ba7b0d91324eae1927fe49464c3b3a76293272570559526064d20a1df5a3859a350dac9d6708113b787e8566a8db58cb6bc881d463ae2f4581865c8
7
- data.tar.gz: 62019c44c7e66c5d3858c9862d20276dbb876d024ca21d1d8691e3969944778c493fa3e988e0e22e2253c7515a6d453d2f11c794867941fa024017c9f28eeb02
6
+ metadata.gz: 9568577466f777d12ad274926490b72f0976eec913b12e8e524f3af66612f22a9a07fa5065c5e2f8817b735ee4ed683a2391b62211aadda716168b3b12833f4b
7
+ data.tar.gz: 122f4e7758d69d4cba1c16b3ff677317084b562921db52d7bcd9408b760aa5ef3e5ebd61808e04e39c1f6e538722d51247daba68037bad88939338049db6f80e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.1.1 (2021-12-13)
2
+
3
+ - Added experimental support for Active Record encryption
4
+
1
5
  ## 2.1.0 (2021-09-25)
2
6
 
3
7
  - Fixed mailer `default_url_options` not being applied to click links
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
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
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.1.0
4
+ version: 2.1.1
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-09-25 00:00:00.000000000 Z
11
+ date: 2021-12-14 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.22
126
+ rubygems_version: 3.2.32
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: First-party email analytics for Rails