activity_notification 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -16
  3. data/CHANGELOG.md +52 -0
  4. data/Gemfile +2 -3
  5. data/README.md +2 -2
  6. data/activity_notification.gemspec +1 -1
  7. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +1 -1
  8. data/app/channels/activity_notification/notification_channel.rb +1 -1
  9. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  10. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  11. data/app/controllers/activity_notification/subscriptions_api_controller.rb +1 -1
  12. data/app/controllers/activity_notification/subscriptions_controller.rb +2 -2
  13. data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
  14. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +2 -2
  15. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +2 -2
  16. data/app/views/activity_notification/subscriptions/default/index.html.erb +2 -2
  17. data/app/views/activity_notification/subscriptions/default/show.html.erb +2 -2
  18. data/bin/bundle_update.sh +0 -1
  19. data/docs/Functions.md +19 -3
  20. data/docs/Setup.md +190 -63
  21. data/gemfiles/Gemfile.rails-5.0 +3 -1
  22. data/gemfiles/Gemfile.rails-5.1 +3 -1
  23. data/gemfiles/Gemfile.rails-5.2 +3 -1
  24. data/gemfiles/Gemfile.rails-6.0 +2 -3
  25. data/gemfiles/{Gemfile.rails-4.2 → Gemfile.rails-6.1} +4 -5
  26. data/lib/activity_notification/apis/notification_api.rb +7 -0
  27. data/lib/activity_notification/apis/subscription_api.rb +5 -5
  28. data/lib/activity_notification/common.rb +15 -4
  29. data/lib/activity_notification/config.rb +53 -23
  30. data/lib/activity_notification/controllers/common_controller.rb +2 -18
  31. data/lib/activity_notification/models/concerns/notifiable.rb +12 -12
  32. data/lib/activity_notification/models/concerns/subscriber.rb +6 -4
  33. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +34 -34
  34. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +17 -17
  35. data/lib/activity_notification/models/concerns/target.rb +8 -12
  36. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +1 -1
  37. data/lib/activity_notification/optional_targets/action_cable_channel.rb +1 -1
  38. data/lib/activity_notification/orm/active_record.rb +1 -1
  39. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  40. data/lib/activity_notification/orm/dynamoid.rb +10 -3
  41. data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
  42. data/lib/activity_notification/orm/dynamoid/subscription.rb +2 -2
  43. data/lib/activity_notification/orm/mongoid.rb +10 -3
  44. data/lib/activity_notification/orm/mongoid/notification.rb +8 -6
  45. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  46. data/lib/activity_notification/renderable.rb +2 -2
  47. data/lib/activity_notification/roles/acts_as_notifiable.rb +13 -16
  48. data/lib/activity_notification/version.rb +1 -1
  49. data/lib/generators/templates/activity_notification.rb +11 -1
  50. data/lib/generators/templates/migrations/migration.rb +1 -1
  51. data/spec/channels/notification_api_channel_spec.rb +42 -44
  52. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  53. data/spec/channels/notification_channel_spec.rb +41 -43
  54. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  55. data/spec/concerns/apis/subscription_api_spec.rb +144 -2
  56. data/spec/concerns/common_spec.rb +25 -3
  57. data/spec/concerns/models/notifiable_spec.rb +35 -35
  58. data/spec/concerns/models/subscriber_spec.rb +179 -6
  59. data/spec/concerns/models/target_spec.rb +10 -12
  60. data/spec/concerns/renderable_spec.rb +5 -5
  61. data/spec/config_spec.rb +26 -15
  62. data/spec/controllers/controller_spec_utility.rb +15 -51
  63. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  64. data/spec/helpers/view_helpers_spec.rb +1 -1
  65. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  66. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  67. data/spec/rails_app/app/controllers/users_controller.rb +5 -0
  68. data/spec/rails_app/app/javascript/App.vue +8 -72
  69. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +3 -4
  70. data/spec/rails_app/app/javascript/components/Top.vue +2 -3
  71. data/spec/rails_app/app/javascript/packs/spa.js +6 -3
  72. data/spec/rails_app/app/javascript/router/index.js +73 -0
  73. data/spec/rails_app/app/javascript/store/{auth.js → index.js} +0 -0
  74. data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
  75. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
  76. data/spec/rails_app/app/models/user.rb +2 -1
  77. data/spec/rails_app/config/application.rb +6 -7
  78. data/spec/rails_app/config/dynamoid.rb +11 -3
  79. data/spec/rails_app/config/environments/production.rb +3 -0
  80. data/spec/rails_app/config/environments/test.rb +2 -11
  81. data/spec/rails_app/config/initializers/activity_notification.rb +13 -3
  82. data/spec/rails_app/config/routes.rb +5 -1
  83. data/spec/rails_app/db/seeds.rb +9 -2
  84. data/spec/rails_app/package.json +14 -14
  85. data/spec/roles/acts_as_notifiable_spec.rb +5 -5
  86. data/spec/spec_helper.rb +1 -5
  87. metadata +12 -12
  88. data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f21c6ee444304e1291b2f032fe3d8bc485741a89c73123b781ba6f69a883c3d9
4
- data.tar.gz: 6b80e107e1c256c8fa4acdbe08ba7b62d96b9b6d61f0f912186aac73db720535
3
+ metadata.gz: d29e3ff0106686c4b32231c8ffcd70fe1046f8eb02c0740c81c814d21eb969ef
4
+ data.tar.gz: '0886dc334077573da144b5929dbf623a289796f9a576fe3a0abd04b1bb7ce759'
5
5
  SHA512:
6
- metadata.gz: 1d4a6f4da5491d589d7f0b4433323f270465e35edd758122b5e58fcd30a30e9cada9cc7a5b129246ba114b755940dea5e6550d7e5b7d00ff23d8673bbceafbcf
7
- data.tar.gz: f240f26d35c835babf447d4b22d2b7acdb1853970a2b50967e9fc3131ec52f73a6dfad86875dc191d69c4993bdca41133dc0005ffcc7f1e6ca8c995ab003d912
6
+ metadata.gz: db72a6b3d2babc00e7ae2e6062952719f267ff5c1254e3a187bda52fab18e216f4792fe5de8a4d4ff576bbc2ca6221ef566b559b2916e33f290afa0b5b291961
7
+ data.tar.gz: 3e17d6dcae61a97efdfd7ca586503d29c84abd1e137c6ff6ecbf682a78e3ee99132037949f3d44c17c6e8a1ad1f6ddf0a283bf35b325b619aa7e12f37d0c63e7
data/.travis.yml CHANGED
@@ -5,18 +5,18 @@ branches:
5
5
  - images
6
6
 
7
7
  rvm:
8
- # - 2.7.0 # Need to respond to warnings for Ruby 3.0
9
- - 2.6.5
10
- # - 2.5.7
11
- # - 2.4.9
8
+ - 2.7.2
9
+ # - 2.6.6
10
+ # - 2.5.8
11
+ # - 2.4.10 #EOL
12
12
  # - 2.3.8 #EOL
13
13
 
14
14
  gemfile:
15
- - gemfiles/Gemfile.rails-4.2
16
15
  - gemfiles/Gemfile.rails-5.0
17
16
  - gemfiles/Gemfile.rails-5.1
18
17
  - gemfiles/Gemfile.rails-5.2
19
18
  - gemfiles/Gemfile.rails-6.0
19
+ - gemfiles/Gemfile.rails-6.1
20
20
 
21
21
  env:
22
22
  - AN_ORM=active_record
@@ -27,9 +27,6 @@ env:
27
27
  - AN_ORM=dynamoid
28
28
 
29
29
  matrix:
30
- exclude:
31
- - gemfile: gemfiles/Gemfile.rails-4.2
32
- env: AN_ORM=dynamoid
33
30
  include:
34
31
  - rvm: ruby-head
35
32
  gemfile: Gemfile
@@ -40,6 +37,9 @@ matrix:
40
37
  - rvm: ruby-head
41
38
  gemfile: Gemfile
42
39
  env: AN_ORM=dynamoid
40
+ exclude:
41
+ - gemfile: gemfiles/Gemfile.rails-6.1
42
+ env: AN_ORM=dynamoid
43
43
  allow_failures:
44
44
  - rvm: ruby-head
45
45
  fast_finish: true
@@ -53,18 +53,12 @@ sudo: false
53
53
 
54
54
  cache: bundler
55
55
 
56
- before_install:
57
- # Specify bundler version as '< 2.0' for Rails 4.2
58
- - gem install bundler --no-document -v '1.17.3'
59
-
60
56
  install:
61
- # Specify bundler version as '< 2.0' for Rails 4.2
62
- - bundle _1.17.3_ install
57
+ - bundle install
63
58
  - if [ "$AN_ORM" = "dynamoid" ]; then bin/install_dynamodblocal.sh; fi
64
59
 
65
60
  before_script:
66
- # Specify bundler version as '< 2.0' for Rails 4.2
67
- - bundle _1.17.3_ update
61
+ - bundle update
68
62
  - if [ "$AN_TEST_DB" = "mysql" ]; then mysql -e 'create database activity_notification_test'; fi
69
63
  - if [ "$AN_TEST_DB" = "postgresql" ]; then psql -c 'create database activity_notification_test' -U postgres; fi
70
64
  - if [ "$AN_ORM" = "dynamoid" ]; then bin/start_dynamodblocal.sh; fi
data/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ ## 2.2.2 / 2021-04-18
2
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.2.1...v2.2.2)
3
+
4
+ Enhancements:
5
+
6
+ * Configure default subscriptions for emails and optional targets - [#159](https://github.com/simukappu/activity_notification/issues/159) [#160](https://github.com/simukappu/activity_notification/pull/160)
7
+ * Upgrade gem dependency in tests with Rails 6.1 - [#152](https://github.com/simukappu/activity_notification/issues/152)
8
+
9
+ ## 2.2.1 / 2021-01-24
10
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.2.0...v2.2.1)
11
+
12
+ Enhancements:
13
+
14
+ * Allow use with Rails 6.1 - [#152](https://github.com/simukappu/activity_notification/issues/152)
15
+
16
+ ## 2.2.0 / 2020-12-05
17
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.4...v2.2.0)
18
+
19
+ Enhancements:
20
+
21
+ * Remove support for Rails 4.2 - [#151](https://github.com/simukappu/activity_notification/issues/151)
22
+ * Turn on deprecation warnings in RSpec testing for Ruby 2.7 - [#122](https://github.com/simukappu/activity_notification/issues/122)
23
+ * Remove Ruby 2.7 deprecation warnings - [#122](https://github.com/simukappu/activity_notification/issues/122)
24
+
25
+ Breaking Changes:
26
+
27
+ * Specify DynamoDB global secondary index name
28
+ * Update additional fields to store into DynamoDB when *config.store_with_associated_records* is true
29
+
30
+ ## 2.1.4 / 2020-11-07
31
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.3...v2.1.4)
32
+
33
+ Enhancements:
34
+
35
+ * Make *Common#to_class_name* method return base_class name in order to work with STI models - [#89](https://github.com/simukappu/activity_notification/issues/89) [#139](https://github.com/simukappu/activity_notification/pull/139)
36
+
37
+ Bug Fixes:
38
+
39
+ * Rename *Notifiable#notification_action_cable_allowed?* to *notifiable_action_cable_allowed?* to fix duplicate method name error - [#138](https://github.com/simukappu/activity_notification/issues/138)
40
+ * Fix hash syntax in swagger schemas - [#146](https://github.com/simukappu/activity_notification/issues/146) [#147](https://github.com/simukappu/activity_notification/pull/147)
41
+
42
+ ## 2.1.3 / 2020-08-11
43
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.2...v2.1.3)
44
+
45
+ Enhancements:
46
+
47
+ * Enable to use namespaced model - [#132](https://github.com/simukappu/activity_notification/pull/132)
48
+
49
+ Bug Fixes:
50
+
51
+ * Fix mongoid any_of selector error in filtered_by_group scope - [MONGOID-4887](https://jira.mongodb.org/browse/MONGOID-4887)
52
+
1
53
  ## 2.1.2 / 2020-02-24
2
54
  [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.1...v2.1.2)
3
55
 
data/Gemfile CHANGED
@@ -16,14 +16,13 @@ group :development do
16
16
  end
17
17
 
18
18
  group :test do
19
- #TODO https://github.com/rails/rails/issues/35417
20
- gem 'rspec-rails', '4.0.0.beta4'
21
19
  gem 'rails-controller-testing'
22
20
  gem 'ammeter'
23
21
  gem 'timecop'
24
22
  gem 'committee'
25
23
  gem 'committee-rails'
26
- gem 'coveralls', require: false
24
+ # gem 'coveralls', require: false
25
+ gem 'coveralls_reborn', require: false
27
26
  end
28
27
 
29
28
  gem 'webpacker', groups: [:production, :development]
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActivityNotification
2
2
 
3
- [![Build Status](https://travis-ci.org/simukappu/activity_notification.svg?branch=master)](https://travis-ci.org/simukappu/activity_notification)
3
+ [![Build Status](https://travis-ci.com/simukappu/activity_notification.svg?branch=master)](https://travis-ci.com/simukappu/activity_notification)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/simukappu/activity_notification/badge.svg?branch=master)](https://coveralls.io/github/simukappu/activity_notification?branch=master)
5
5
  [![Dependency](https://img.shields.io/depfu/simukappu/activity_notification.svg)](https://depfu.com/repos/simukappu/activity_notification)
6
6
  [![Inline docs](http://inch-ci.org/github/simukappu/activity_notification.svg?branch=master)](http://inch-ci.org/github/simukappu/activity_notification)
@@ -10,7 +10,7 @@
10
10
 
11
11
  *activity_notification* provides integrated user activity notifications for [Ruby on Rails](https://rubyonrails.org). You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
12
12
 
13
- *activity_notification* supports Rails 4.2+ with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html), [Mongoid](https://mongoid.org) and [Dynamoid](https://github.com/Dynamoid/dynamoid) ORM. It is tested for [MySQL](https://www.mysql.com), [PostgreSQL](https://www.postgresql.org), [SQLite3](https://www.sqlite.org) with ActiveRecord, [MongoDB](https://www.mongodb.com) with Mongoid and [Amazon DynamoDB](https://aws.amazon.com/dynamodb) with Dynamoid. The latest *activity_notification* [v2](https://rubygems.org/gems/activity_notification) is almost compatible with [v1](https://rubygems.org/gems/activity_notification/versions/1.7.1).
13
+ *activity_notification* supports Rails 5.0+ with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html), [Mongoid](https://mongoid.org) and [Dynamoid](https://github.com/Dynamoid/dynamoid) ORM. It is tested for [MySQL](https://www.mysql.com), [PostgreSQL](https://www.postgresql.org), [SQLite3](https://www.sqlite.org) with ActiveRecord, [MongoDB](https://www.mongodb.com) with Mongoid and [Amazon DynamoDB](https://aws.amazon.com/dynamodb) with Dynamoid. If you are using Rails 4.2, use [v2.1.4](https://rubygems.org/gems/activity_notification/versions/2.1.4) or older version of *activity_notification*.
14
14
 
15
15
 
16
16
  ## About
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
  s.required_ruby_version = '>= 2.1.0'
22
22
 
23
- s.add_dependency 'railties', '>= 4.2.0', '< 6.1'
23
+ s.add_dependency 'railties', '>= 5.0.0', '< 6.2'
24
24
  s.add_dependency 'i18n', '>= 0.5.0'
25
25
  s.add_dependency 'jquery-rails', '>= 3.1.1'
26
26
  s.add_dependency 'swagger-blocks', '>= 3.0.0'
@@ -24,7 +24,7 @@ if defined?(ActionCable)
24
24
  # @return [Object] Target instance (Reject subscription when request parameters are not enough)
25
25
  def set_target
26
26
  reject and return if (target_type = params[:target_type]).blank?
27
- if params[:target_id].blank? && params["#{target_type.to_s.to_resource_name}_id"].blank?
27
+ if params[:target_id].blank? && params["#{target_type.to_s.to_resource_name[/([^\/]+)$/]}_id"].blank?
28
28
  reject and return if params[:devise_type].blank?
29
29
  current_target = find_current_target(params[:devise_type])
30
30
  params[:target_id] = target_type.to_model_class.resolve_current_devise_target(current_target)
@@ -22,7 +22,7 @@ if defined?(ActionCable)
22
22
  target_class = target_type.to_s.to_model_class
23
23
  @target = params[:target_id].present? ?
24
24
  target_class.find_by!(id: params[:target_id]) :
25
- target_class.find_by!(id: params["#{target_type.to_s.to_resource_name}_id"])
25
+ target_class.find_by!(id: params["#{target_type.to_s.to_resource_name[/([^\/]+)$/]}_id"])
26
26
  rescue
27
27
  reject
28
28
  end
@@ -29,7 +29,7 @@ if defined?(ActionCable)
29
29
  # @return [Object] Target instance (Reject subscription when request parameters are not enough)
30
30
  def set_target
31
31
  reject and return if (target_type = params[:target_type]).blank?
32
- if params[:target_id].blank? && params["#{target_type.to_s.to_resource_name}_id"].blank?
32
+ if params[:target_id].blank? && params["#{target_type.to_s.to_resource_name[/([^\/]+)$/]}_id"].blank?
33
33
  reject and return if params[:devise_type].blank?
34
34
  current_target = find_current_target(params[:devise_type])
35
35
  params[:target_id] = target_type.to_model_class.resolve_current_devise_target(current_target)
@@ -117,26 +117,6 @@ module ActivityNotification
117
117
  super
118
118
  end
119
119
 
120
- # :nocov:
121
- if Rails::VERSION::MAJOR == 4
122
- # Defines custom renderer class method for Rails 4.2
123
- def self.renderer
124
- view_context = ActionView::Base.new(ActionController::Base.view_paths, {})
125
- view_context.class_eval do
126
- include Rails.application.routes.url_helpers
127
- def default_url_options
128
- ActionMailer::Base.default_url_options
129
- end
130
- def render(params = {})
131
- assign(params[:assigns])
132
- super(params)
133
- end
134
- end
135
- view_context
136
- end
137
- end
138
- # :nocov:
139
-
140
120
  protected
141
121
 
142
122
  # Sets @notification instance variable from request parameters.
@@ -44,7 +44,7 @@ module ActivityNotification
44
44
  params[:subscription][:optional_targets]["subscribing_to_#{optional_target_name}"] = subscribing_param unless subscribing_param.nil?
45
45
  end
46
46
  super
47
- render status: 201, location: { action: :show, id: @subscription }, json: subscription_json
47
+ render status: 201, json: subscription_json if @subscription
48
48
  end
49
49
 
50
50
  # Finds and shows a subscription from specified key.
@@ -91,8 +91,8 @@ module ActivityNotification
91
91
  # @option params [String] :filtered_by_key (nil) Key of the subscription for filter
92
92
  # @return [Response] JavaScript view for ajax request or redirects to back as default
93
93
  def subscribe
94
- @subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(true),
95
- with_optional_targets: params[:with_optional_targets].to_s.to_boolean(true))
94
+ @subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(ActivityNotification.config.subscribe_to_email_as_default),
95
+ with_optional_targets: params[:with_optional_targets].to_s.to_boolean(ActivityNotification.config.subscribe_to_optional_targets_as_default))
96
96
  return_back_or_ajax
97
97
  end
98
98
 
@@ -37,7 +37,7 @@
37
37
  <div class="field">
38
38
  <div class="ui checkbox">
39
39
  <label>
40
- <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_as_default }, 'true', 'false' %>
40
+ <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_to_email_as_default }, 'true', 'false' %>
41
41
  <div class="slider"></div>
42
42
  </label>
43
43
  </div>
@@ -38,7 +38,7 @@
38
38
  <div class="field">
39
39
  <div class="ui checkbox">
40
40
  <label>
41
- <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_as_default }, 'true', 'false' %>
41
+ <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_to_email_as_default }, 'true', 'false' %>
42
42
  <div class="slider"></div>
43
43
  </label>
44
44
  </div>
@@ -56,7 +56,7 @@
56
56
  <div class="ui checkbox">
57
57
  <label>
58
58
  <%= hidden_field_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'false', id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_hidden" %>
59
- <%= check_box_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'true', ActivityNotification.config.subscribe_as_default, id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_check_box" %>
59
+ <%= check_box_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'true', ActivityNotification.config.subscribe_to_optional_targets_as_default, id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_check_box" %>
60
60
  <div class="slider"></div>
61
61
  </label>
62
62
  </div>
@@ -24,12 +24,12 @@
24
24
  <% end %>
25
25
  <% else %>
26
26
  <% if ActivityNotification.config.subscribe_as_default %>
27
- <%= link_to subscribe_path_for(subscription, option_params), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find("input").prop("checked", true);$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find("input").prop("checked", true);', method: :put, remote: true do %>
27
+ <%= link_to subscribe_path_for(subscription, option_params), onclick: "$(this).find(\"input\").prop(\"checked\", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_email_as_default.to_s});$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_optional_targets_as_default});", method: :put, remote: true do %>
28
28
  <%= check_box :subscribing, "", { checked: false }, 'true', 'false' %>
29
29
  <div class="slider"></div>
30
30
  <% end %>
31
31
  <% else %>
32
- <%= link_to subscribe_path_for(subscription, option_params.merge(with_email_subscription: false)), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %>
32
+ <%= link_to subscribe_path_for(subscription, option_params), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %>
33
33
  <%= check_box :subscribing, "", { checked: false }, 'true', 'false' %>
34
34
  <div class="slider"></div>
35
35
  <% end %>
@@ -189,9 +189,9 @@
189
189
  $thisFieldWrapper = $(this).parent().parent().parent().parent();
190
190
  if ($(this).prop('checked')) {
191
191
  $thisFieldWrapper.next().slideDown();
192
- $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
192
+ $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_email_as_default %>);
193
193
  $thisFieldWrapper.next().next().slideDown();
194
- $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
194
+ $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_optional_targets_as_default %>);
195
195
  } else {
196
196
  $thisFieldWrapper.next().slideUp();
197
197
  $thisFieldWrapper.next().next().slideUp();
@@ -165,9 +165,9 @@
165
165
  $thisFieldWrapper = $(this).parent().parent().parent().parent();
166
166
  if ($(this).prop('checked')) {
167
167
  $thisFieldWrapper.next().slideDown();
168
- $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
168
+ $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_email_as_default %>);
169
169
  $thisFieldWrapper.next().next().slideDown();
170
- $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
170
+ $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_optional_targets_as_default %>);
171
171
  } else {
172
172
  $thisFieldWrapper.next().slideUp();
173
173
  $thisFieldWrapper.next().next().slideUp();
data/bin/bundle_update.sh CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
3
  bundle update
4
- BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.2 bundle update
5
4
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0 bundle update
6
5
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.1 bundle update
7
6
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.2 bundle update
data/docs/Functions.md CHANGED
@@ -65,9 +65,9 @@ config.mailer_sender = ->(key){ key == 'inquiry.post' ? 'support@example.com' :
65
65
 
66
66
  #### Email templates
67
67
 
68
- *activity_notification* will look for email template in a similar way as notification views, but the view file name is not start with an underscore. For example, if you have a notification with *:key* set to *"notification.comment.reply"* and target_type *users*, the gem will look for a partial in *app/views/activity_notification/mailer/users/comment/reply.html.(|erb|haml|slim|something_else)*.
68
+ *activity_notification* will look for email template in a similar way as notification views, but the view file name does not start with an underscore. For example, if you have a notification with *:key* set to *"notification.comment.reply"* and target_type *users*, the gem will look for a partial in *app/views/activity_notification/mailer/users/comment/reply.html.(|erb|haml|slim|something_else)*.
69
69
 
70
- If this template is missing, the gem will look for a partial in *default* as the target type which means *activity_notification/mailer/default/_default.html.(|erb|haml|slim|something_else)*.
70
+ If this template is missing, the gem will use *default* as the target type which means *activity_notification/mailer/default/default.html.(|erb|haml|slim|something_else)*.
71
71
 
72
72
  #### Email subject
73
73
 
@@ -308,6 +308,8 @@ Subscriptions are managed by instances of **ActivityNotification::Subscription**
308
308
  *true* means the target will receive the notification email with this key including batch notification email with this *batch_key*.
309
309
  *false* means the target will not receive these notification email.
310
310
 
311
+ ##### Subscription defaults
312
+
311
313
  As default, all target subscribes to notification and notification email when subscription record does not exist in your database.
312
314
  You can change this **subscribe_as_default** parameter in initializer *activity_notification.rb*.
313
315
 
@@ -317,6 +319,20 @@ config.subscribe_as_default = false
317
319
 
318
320
  Then, all target does not subscribe to notification and notification email and will not receive any notifications as default.
319
321
 
322
+ As default, email and optional target subscriptions will use the same default subscription value as defined in **subscribe_as_default**.
323
+ You can disable them by providing **subscribe_to_email_as_default** or **subscribe_to_optional_targets_as_default** parameter(s) in initializer *activity_notification.rb*.
324
+
325
+ ```ruby
326
+ # Enable subscribe as default, but disable it for emails
327
+ config.subscribe_as_default = true
328
+ config.subscribe_to_email_as_default = false
329
+ config.subscribe_to_optional_targets_as_default = true
330
+ ```
331
+
332
+ However if **subscribe_as_default** is not enabled, **subscribe_to_email_as_default** and **subscribe_to_optional_targets_as_default** won't change anything.
333
+
334
+ ##### Creating and updating subscriptions
335
+
320
336
  You can create subscription record from subscription API in your target model like this:
321
337
 
322
338
  ```ruby
@@ -574,7 +590,7 @@ To sign in and get *access-token* from Devise Token Auth, call *sign_in* API whi
574
590
  ```console
575
591
  $ curl -X POST -H "Content-Type: application/json" -D - -d '{"email": "ichiro@example.com","password": "changeit"}' https://activity-notification-example.herokuapp.com/api/v2/auth/sign_in
576
592
 
577
-
593
+
578
594
  HTTP/1.1 200 OK
579
595
  ...
580
596
  Content-Type: application/json; charset=utf-8
data/docs/Setup.md CHANGED
@@ -109,76 +109,189 @@ When **store_with_associated_records** is set to *false* as default, *activity_n
109
109
 
110
110
  ```json
111
111
  {
112
- "id": {
113
- "S": "f05756ef-661e-4ef5-9e99-5af51243125c"
114
- },
115
- "target_key": {
116
- "S": "User#1"
117
- },
118
- "notifiable_key": {
119
- "S": "Comment#2"
120
- },
121
- "key": {
122
- "S": "comment.default"
123
- },
124
- "group_key": {
125
- "S": "Article#1"
126
- },
127
- "notifier_key": {
128
- "S": "User#2"
129
- },
130
- "created_at": {
131
- "N": "1560085332.689929"
132
- },
133
- "updated_at": {
134
- "N": "1560085332.695515"
135
- },
136
- "parameters": {
137
- "M": {}
138
- }
112
+ "id": {
113
+ "S": "f05756ef-661e-4ef5-9e99-5af51243125c"
114
+ },
115
+ "target_key": {
116
+ "S": "User#1"
117
+ },
118
+ "notifiable_key": {
119
+ "S": "Comment#2"
120
+ },
121
+ "key": {
122
+ "S": "comment.default"
123
+ },
124
+ "group_key": {
125
+ "S": "Article#1"
126
+ },
127
+ "notifier_key": {
128
+ "S": "User#2"
129
+ },
130
+ "created_at": {
131
+ "S": "2020-03-08T08:22:53+00:00"
132
+ },
133
+ "updated_at": {
134
+ "S": "2020-03-08T08:22:53+00:00"
135
+ },
136
+ "parameters": {
137
+ "M": {}
138
+ }
139
139
  }
140
140
  ```
141
141
 
142
- When you set **store_with_associated_records** to *true*, *activity_notification* stores notificaion records including associated target, notifiable and notifier like this:
142
+ When you set **store_with_associated_records** to *true*, *activity_notification* stores notificaion records including associated target, notifiable, notifier and several instance methods like this:
143
143
 
144
144
  ```json
145
145
  {
146
- "id": {
147
- "S": "f05756ef-661e-4ef5-9e99-5af51243125c"
148
- },
149
- "target_key": {
150
- "S": "User#1"
151
- },
152
- "target_record": {
153
- "S": "{\"id\":1,\"email\":\"ichiro@example.com\",\"name\":\"Ichiro\",\"created_at\":\"2019-06-09T13:10:44.853Z\",\"updated_at\":\"2019-06-09T13:10:44.853Z\"}"
154
- },
155
- "notifiable_key": {
156
- "S": "Comment#2"
157
- },
158
- "notifiable_record": {
159
- "S": "{\"id\":2,\"user_id\":2,\"article_id\":1,\"body\":\"This is the first Stephen's comment to Ichiro's article.\",\"created_at\":\"2019-06-09T13:10:45.677Z\",\"updated_at\":\"2019-06-09T13:10:45.677Z\"}"
160
- },
161
- "key": {
162
- "S": "comment.default"
163
- },
164
- "group_key": {
165
- "S": "Article#1"
166
- },
167
- "notifier_key": {
168
- "S": "User#2"
169
- },
170
- "notifier_record": {
171
- "S": "{\"id\":2,\"email\":\"stephen@example.com\",\"name\":\"Stephen\",\"created_at\":\"2019-06-09T13:10:45.006Z\",\"updated_at\":\"2019-06-09T13:10:45.006Z\"}"
172
- },
173
- "created_at": {
174
- "N": "1560085332.689929"
175
- },
176
- "updated_at": {
177
- "N": "1560085332.695515"
178
- },
179
- "parameters": {
180
- "M": {}
146
+ "id": {
147
+ "S": "f05756ef-661e-4ef5-9e99-5af51243125c"
148
+ },
149
+ "target_key": {
150
+ "S": "User#1"
151
+ },
152
+ "notifiable_key": {
153
+ "S": "Comment#2"
154
+ },
155
+ "key": {
156
+ "S": "comment.default"
157
+ },
158
+ "group_key": {
159
+ "S": "Article#1"
160
+ },
161
+ "notifier_key": {
162
+ "S": "User#2"
163
+ },
164
+ "created_at": {
165
+ "S": "2020-03-08T08:22:53+00:00"
166
+ },
167
+ "updated_at": {
168
+ "S": "2020-03-08T08:22:53+00:00"
169
+ },
170
+ "parameters": {
171
+ "M": {}
172
+ },
173
+ "stored_target": {
174
+ "M": {
175
+ "id": {
176
+ "N": "1"
177
+ },
178
+ "email": {
179
+ "S": "ichiro@example.com"
180
+ },
181
+ "name": {
182
+ "S": "Ichiro"
183
+ },
184
+ "created_at": {
185
+ "S": "2020-03-08T08:22:23.451Z"
186
+ },
187
+ "updated_at": {
188
+ "S": "2020-03-08T08:22:23.451Z"
189
+ },
190
+ // { ... },
191
+ "printable_type": {
192
+ "S": "User"
193
+ },
194
+ "printable_target_name": {
195
+ "S": "Ichiro"
196
+ },
197
+ }
198
+ },
199
+ "stored_notifiable": {
200
+ "M": {
201
+ "id": {
202
+ "N": "2"
203
+ },
204
+ "user_id": {
205
+ "N": "2"
206
+ },
207
+ "article_id": {
208
+ "N": "1"
209
+ },
210
+ "body": {
211
+ "S": "This is the first Stephen's comment to Ichiro's article."
212
+ },
213
+ "created_at": {
214
+ "S": "2020-03-08T08:22:47.683Z"
215
+ },
216
+ "updated_at": {
217
+ "S": "2020-03-08T08:22:47.683Z"
218
+ },
219
+ "printable_type": {
220
+ "S": "Comment"
221
+ }
222
+ }
223
+ },
224
+ "stored_notifier": {
225
+ "M": {
226
+ "id": {
227
+ "N": "2"
228
+ },
229
+ "email": {
230
+ "S": "stephen@example.com"
231
+ },
232
+ "name": {
233
+ "S": "Stephen"
234
+ },
235
+ "created_at": {
236
+ "S": "2020-03-08T08:22:23.573Z"
237
+ },
238
+ "updated_at": {
239
+ "S": "2020-03-08T08:22:23.573Z"
240
+ },
241
+ // { ... },
242
+ "printable_type": {
243
+ "S": "User"
244
+ },
245
+ "printable_notifier_name": {
246
+ "S": "Stephen"
247
+ }
248
+ }
249
+ },
250
+ "stored_group": {
251
+ "M": {
252
+ "id": {
253
+ "N": "1"
254
+ },
255
+ "user_id": {
256
+ "N": "1"
257
+ },
258
+ "title": {
259
+ "S": "Ichiro's first article"
260
+ },
261
+ "body": {
262
+ "S": "This is the first Ichiro's article. Please read it!"
263
+ },
264
+ "created_at": {
265
+ "S": "2020-03-08T08:22:23.952Z"
266
+ },
267
+ "updated_at": {
268
+ "S": "2020-03-08T08:22:23.952Z"
269
+ },
270
+ "printable_type": {
271
+ "S": "Article"
272
+ },
273
+ "printable_group_name": {
274
+ "S": "article \"Ichiro's first article\""
275
+ }
181
276
  }
277
+ },
278
+ "stored_notifiable_path": {
279
+ "S": "/articles/1"
280
+ },
281
+ "stored_printable_notifiable_name": {
282
+ "S": "comment \"This is the first Stephen's comment to Ichiro's article.\""
283
+ },
284
+ "stored_group_member_notifier_count": {
285
+ "N": "2"
286
+ },
287
+ "stored_group_notification_count": {
288
+ "N": "3"
289
+ },
290
+ "stored_group_members": {
291
+ "L": [
292
+ // { ... }, { ... }, ...
293
+ ]
294
+ }
182
295
  }
183
296
  ```
184
297
 
@@ -343,6 +456,20 @@ end
343
456
  Then, you can access several pages like */users/1/notifications* and manage open/unopen of notifications using *[ActivityNotification::NotificationsController](/app/controllers/activity_notification/notifications_controller.rb)*.
344
457
  If you use Devise integration and you want to configure simple default routes for authenticated users, see [Configuring simple default routes](#configuring-simple-default-routes).
345
458
 
459
+ #### Routes with namespaced model
460
+
461
+ It is possible to configure a target model as a submodule, e.g. if your target is `Entity::User`,
462
+ however by default the **ActivityNotification** controllers will be placed under the same namespace,
463
+ so it is mandatory to explicitly call the controllers this way
464
+
465
+ ```ruby
466
+ Rails.application.routes.draw do
467
+ notify_to :users, controller: '/activity_notification/notifications', target_type: 'entity/users'
468
+ end
469
+ ```
470
+
471
+ This will generate the necessary routes for the `Entity::User` target with parameters `:user_id`
472
+
346
473
  #### Routes with scope
347
474
 
348
475
  You can also configure *activity_notification* routes with scope like this: