activity_notification 2.1.2 → 2.2.2
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 +4 -4
- data/.travis.yml +10 -16
- data/CHANGELOG.md +52 -0
- data/Gemfile +2 -3
- data/README.md +2 -2
- data/activity_notification.gemspec +1 -1
- data/app/channels/activity_notification/notification_api_with_devise_channel.rb +1 -1
- data/app/channels/activity_notification/notification_channel.rb +1 -1
- data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +0 -20
- data/app/controllers/activity_notification/subscriptions_api_controller.rb +1 -1
- data/app/controllers/activity_notification/subscriptions_controller.rb +2 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/index.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/show.html.erb +2 -2
- data/bin/bundle_update.sh +0 -1
- data/docs/Functions.md +19 -3
- data/docs/Setup.md +190 -63
- data/gemfiles/Gemfile.rails-5.0 +3 -1
- data/gemfiles/Gemfile.rails-5.1 +3 -1
- data/gemfiles/Gemfile.rails-5.2 +3 -1
- data/gemfiles/Gemfile.rails-6.0 +2 -3
- data/gemfiles/{Gemfile.rails-4.2 → Gemfile.rails-6.1} +4 -5
- data/lib/activity_notification/apis/notification_api.rb +7 -0
- data/lib/activity_notification/apis/subscription_api.rb +5 -5
- data/lib/activity_notification/common.rb +15 -4
- data/lib/activity_notification/config.rb +53 -23
- data/lib/activity_notification/controllers/common_controller.rb +2 -18
- data/lib/activity_notification/models/concerns/notifiable.rb +12 -12
- data/lib/activity_notification/models/concerns/subscriber.rb +6 -4
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +34 -34
- data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +17 -17
- data/lib/activity_notification/models/concerns/target.rb +8 -12
- data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +1 -1
- data/lib/activity_notification/optional_targets/action_cable_channel.rb +1 -1
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/active_record/notification.rb +3 -3
- data/lib/activity_notification/orm/dynamoid.rb +10 -3
- data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
- data/lib/activity_notification/orm/dynamoid/subscription.rb +2 -2
- data/lib/activity_notification/orm/mongoid.rb +10 -3
- data/lib/activity_notification/orm/mongoid/notification.rb +8 -6
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/renderable.rb +2 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +13 -16
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +11 -1
- data/lib/generators/templates/migrations/migration.rb +1 -1
- data/spec/channels/notification_api_channel_spec.rb +42 -44
- data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
- data/spec/channels/notification_channel_spec.rb +41 -43
- data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
- data/spec/concerns/apis/subscription_api_spec.rb +144 -2
- data/spec/concerns/common_spec.rb +25 -3
- data/spec/concerns/models/notifiable_spec.rb +35 -35
- data/spec/concerns/models/subscriber_spec.rb +179 -6
- data/spec/concerns/models/target_spec.rb +10 -12
- data/spec/concerns/renderable_spec.rb +5 -5
- data/spec/config_spec.rb +26 -15
- data/spec/controllers/controller_spec_utility.rb +15 -51
- data/spec/generators/migration/migration_generator_spec.rb +2 -10
- data/spec/helpers/view_helpers_spec.rb +1 -1
- data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
- data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
- data/spec/rails_app/app/controllers/users_controller.rb +5 -0
- data/spec/rails_app/app/javascript/App.vue +8 -72
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +3 -4
- data/spec/rails_app/app/javascript/components/Top.vue +2 -3
- data/spec/rails_app/app/javascript/packs/spa.js +6 -3
- data/spec/rails_app/app/javascript/router/index.js +73 -0
- data/spec/rails_app/app/javascript/store/{auth.js → index.js} +0 -0
- data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
- data/spec/rails_app/app/models/user.rb +2 -1
- data/spec/rails_app/config/application.rb +6 -7
- data/spec/rails_app/config/dynamoid.rb +11 -3
- data/spec/rails_app/config/environments/production.rb +3 -0
- data/spec/rails_app/config/environments/test.rb +2 -11
- data/spec/rails_app/config/initializers/activity_notification.rb +13 -3
- data/spec/rails_app/config/routes.rb +5 -1
- data/spec/rails_app/db/seeds.rb +9 -2
- data/spec/rails_app/package.json +14 -14
- data/spec/roles/acts_as_notifiable_spec.rb +5 -5
- data/spec/spec_helper.rb +1 -5
- metadata +12 -12
- data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
data/gemfiles/Gemfile.rails-5.0
CHANGED
|
@@ -11,13 +11,15 @@ group :development do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
group :test do
|
|
14
|
+
gem 'rspec-rails', '< 4.0.0'
|
|
14
15
|
gem 'rails-controller-testing'
|
|
15
16
|
gem 'action-cable-testing'
|
|
16
17
|
gem 'ammeter'
|
|
17
18
|
gem 'timecop'
|
|
18
19
|
gem 'committee'
|
|
19
20
|
gem 'committee-rails'
|
|
20
|
-
gem 'coveralls', require: false
|
|
21
|
+
# gem 'coveralls', require: false
|
|
22
|
+
gem 'coveralls_reborn', require: false
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
gem 'dotenv-rails', groups: [:development, :test]
|
data/gemfiles/Gemfile.rails-5.1
CHANGED
|
@@ -10,13 +10,15 @@ group :development do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
group :test do
|
|
13
|
+
gem 'rspec-rails', '< 4.0.0'
|
|
13
14
|
gem 'rails-controller-testing'
|
|
14
15
|
gem 'action-cable-testing'
|
|
15
16
|
gem 'ammeter'
|
|
16
17
|
gem 'timecop'
|
|
17
18
|
gem 'committee'
|
|
18
19
|
gem 'committee-rails'
|
|
19
|
-
gem 'coveralls', require: false
|
|
20
|
+
# gem 'coveralls', require: false
|
|
21
|
+
gem 'coveralls_reborn', require: false
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
gem 'dotenv-rails', groups: [:development, :test]
|
data/gemfiles/Gemfile.rails-5.2
CHANGED
|
@@ -10,13 +10,15 @@ group :development do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
group :test do
|
|
13
|
+
gem 'rspec-rails', '< 4.0.0'
|
|
13
14
|
gem 'rails-controller-testing'
|
|
14
15
|
gem 'action-cable-testing'
|
|
15
16
|
gem 'ammeter'
|
|
16
17
|
gem 'timecop'
|
|
17
18
|
gem 'committee'
|
|
18
19
|
gem 'committee-rails'
|
|
19
|
-
gem 'coveralls', require: false
|
|
20
|
+
# gem 'coveralls', require: false
|
|
21
|
+
gem 'coveralls_reborn', require: false
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
gem 'dotenv-rails', groups: [:development, :test]
|
data/gemfiles/Gemfile.rails-6.0
CHANGED
|
@@ -10,14 +10,13 @@ group :development do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
group :test do
|
|
13
|
-
#TODO https://github.com/rails/rails/issues/35417
|
|
14
|
-
gem 'rspec-rails', '4.0.0.beta4'
|
|
15
13
|
gem 'rails-controller-testing'
|
|
16
14
|
gem 'ammeter'
|
|
17
15
|
gem 'timecop'
|
|
18
16
|
gem 'committee'
|
|
19
17
|
gem 'committee-rails'
|
|
20
|
-
gem 'coveralls', require: false
|
|
18
|
+
# gem 'coveralls', require: false
|
|
19
|
+
gem 'coveralls_reborn', require: false
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
gem 'dotenv-rails', groups: [:development, :test]
|
|
@@ -2,10 +2,7 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec path: '../'
|
|
4
4
|
|
|
5
|
-
gem 'rails', '~>
|
|
6
|
-
gem 'sqlite3', '~> 1.3.13'
|
|
7
|
-
gem 'mysql2', '~> 0.4.10'
|
|
8
|
-
gem 'pg', '~> 0.21.0'
|
|
5
|
+
gem 'rails', '~> 6.1.0'
|
|
9
6
|
|
|
10
7
|
group :development do
|
|
11
8
|
gem 'bullet'
|
|
@@ -13,11 +10,13 @@ group :development do
|
|
|
13
10
|
end
|
|
14
11
|
|
|
15
12
|
group :test do
|
|
13
|
+
gem 'rails-controller-testing'
|
|
16
14
|
gem 'ammeter'
|
|
17
15
|
gem 'timecop'
|
|
18
16
|
gem 'committee'
|
|
19
17
|
gem 'committee-rails'
|
|
20
|
-
gem 'coveralls', require: false
|
|
18
|
+
# gem 'coveralls', require: false
|
|
19
|
+
gem 'coveralls_reborn', require: false
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
gem 'dotenv-rails', groups: [:development, :test]
|
|
@@ -495,16 +495,23 @@ module ActivityNotification
|
|
|
495
495
|
|
|
496
496
|
notification = new({ target: target, notifiable: notifiable, key: key, group: group, parameters: parameters, notifier: notifier, group_owner: group_owner })
|
|
497
497
|
notification.prepare_to_store.save
|
|
498
|
+
notification.after_store
|
|
498
499
|
notification
|
|
499
500
|
end
|
|
500
501
|
end
|
|
501
502
|
|
|
503
|
+
# :nocov:
|
|
502
504
|
# Returns prepared notification object to store
|
|
503
505
|
# @return [Object] prepared notification object to store
|
|
504
506
|
def prepare_to_store
|
|
505
507
|
self
|
|
506
508
|
end
|
|
507
509
|
|
|
510
|
+
# Call after store action with stored notification
|
|
511
|
+
def after_store
|
|
512
|
+
end
|
|
513
|
+
# :nocov:
|
|
514
|
+
|
|
508
515
|
# Sends notification email to the target.
|
|
509
516
|
#
|
|
510
517
|
# @param [Hash] options Options for notification email
|
|
@@ -21,7 +21,7 @@ module ActivityNotification
|
|
|
21
21
|
# @subscriptions = @user.subscriptions.filtered_by_options({ custom_filter: ["created_at >= ?", time.hour.ago] })
|
|
22
22
|
# @scope class
|
|
23
23
|
# @param [Hash] options Options for filter
|
|
24
|
-
# @option options [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
24
|
+
# @option options [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
25
25
|
# @option options [Array|Hash] :custom_filter (nil) Custom subscription filter (e.g. ["created_at >= ?", time.hour.ago] or ['created_at.gt': time.hour.ago])
|
|
26
26
|
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of filtered subscriptions
|
|
27
27
|
scope :filtered_by_options, ->(options = {}) {
|
|
@@ -127,8 +127,8 @@ module ActivityNotification
|
|
|
127
127
|
# @return [Boolean] If successfully updated subscription instance
|
|
128
128
|
def subscribe(options = {})
|
|
129
129
|
subscribed_at = options[:subscribed_at] || Time.current
|
|
130
|
-
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] :
|
|
131
|
-
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] :
|
|
130
|
+
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : ActivityNotification.config.subscribe_to_email_as_default
|
|
131
|
+
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : ActivityNotification.config.subscribe_to_optional_targets_as_default
|
|
132
132
|
new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
|
|
133
133
|
new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
|
|
134
134
|
if with_optional_targets
|
|
@@ -184,7 +184,7 @@ module ActivityNotification
|
|
|
184
184
|
# @param [Symbol] optional_target_name Symbol class name of the optional target implementation (e.g. :amazon_sns, :slack)
|
|
185
185
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
186
186
|
# @return [Boolean] If the target subscribes to the specified optional target
|
|
187
|
-
def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.
|
|
187
|
+
def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
|
|
188
188
|
optional_target_key = Subscription.to_optional_target_key(optional_target_name)
|
|
189
189
|
subscribe_as_default ?
|
|
190
190
|
!optional_targets.has_key?(optional_target_key) || optional_targets[optional_target_key] :
|
|
@@ -244,4 +244,4 @@ module ActivityNotification
|
|
|
244
244
|
end
|
|
245
245
|
|
|
246
246
|
end
|
|
247
|
-
end
|
|
247
|
+
end
|
|
@@ -16,7 +16,11 @@ module ActivityNotification
|
|
|
16
16
|
when Symbol
|
|
17
17
|
symbol_method = context.method(thing)
|
|
18
18
|
if symbol_method.arity > 1
|
|
19
|
-
|
|
19
|
+
if args.last.kind_of?(Hash)
|
|
20
|
+
symbol_method.call(ActivityNotification.get_controller, *args[0...-1], **args[-1])
|
|
21
|
+
else
|
|
22
|
+
symbol_method.call(ActivityNotification.get_controller, *args)
|
|
23
|
+
end
|
|
20
24
|
elsif symbol_method.arity > 0
|
|
21
25
|
symbol_method.call(ActivityNotification.get_controller)
|
|
22
26
|
else
|
|
@@ -74,7 +78,11 @@ module ActivityNotification
|
|
|
74
78
|
when Symbol
|
|
75
79
|
symbol_method = method(thing)
|
|
76
80
|
if symbol_method.arity > 0
|
|
77
|
-
|
|
81
|
+
if args.last.kind_of?(Hash)
|
|
82
|
+
symbol_method.call(*args[0...-1], **args[-1])
|
|
83
|
+
else
|
|
84
|
+
symbol_method.call(*args)
|
|
85
|
+
end
|
|
78
86
|
else
|
|
79
87
|
symbol_method.call
|
|
80
88
|
end
|
|
@@ -98,9 +106,12 @@ module ActivityNotification
|
|
|
98
106
|
end
|
|
99
107
|
|
|
100
108
|
# Convets to class name.
|
|
109
|
+
# This function returns base_class name for STI models if the class responds to base_class method.
|
|
110
|
+
# @see https://github.com/simukappu/activity_notification/issues/89
|
|
111
|
+
# @see https://github.com/simukappu/activity_notification/pull/139
|
|
101
112
|
# @return [String] Class name
|
|
102
113
|
def to_class_name
|
|
103
|
-
self.class.name
|
|
114
|
+
self.class.respond_to?(:base_class) ? self.class.base_class.name : self.class.name
|
|
104
115
|
end
|
|
105
116
|
|
|
106
117
|
# Convets to singularized model name (resource name).
|
|
@@ -128,4 +139,4 @@ module ActivityNotification
|
|
|
128
139
|
"#{self.printable_type} (#{id})"
|
|
129
140
|
end
|
|
130
141
|
end
|
|
131
|
-
end
|
|
142
|
+
end
|
|
@@ -61,6 +61,18 @@ module ActivityNotification
|
|
|
61
61
|
# @return [Boolean] Default subscription value to use when the subscription record does not configured.
|
|
62
62
|
attr_accessor :subscribe_as_default
|
|
63
63
|
|
|
64
|
+
# @overload subscribe_to_email_as_default=(value)
|
|
65
|
+
# Sets default email subscription value to use when the subscription record does not configured
|
|
66
|
+
# @param [Boolean] subscribe_to_email_as_default The new subscribe_to_email_as_default
|
|
67
|
+
# @return [Boolean] Default email subscription value to use when the subscription record does not configured.
|
|
68
|
+
attr_writer :subscribe_to_email_as_default
|
|
69
|
+
|
|
70
|
+
# @overload subscribe_to_optional_targets_as_default=(value)
|
|
71
|
+
# Sets default optional target subscription value to use when the subscription record does not configured
|
|
72
|
+
# @param [Boolean] subscribe_to_optional_targets_as_default The new subscribe_to_optional_targets_as_default
|
|
73
|
+
# @return [Boolean] Default optional target subscription value to use when the subscription record does not configured.
|
|
74
|
+
attr_writer :subscribe_to_optional_targets_as_default
|
|
75
|
+
|
|
64
76
|
# @overload mailer_sender
|
|
65
77
|
# Returns email address as sender of notification email
|
|
66
78
|
# @return [String] Email address as sender of notification email.
|
|
@@ -205,29 +217,31 @@ module ActivityNotification
|
|
|
205
217
|
# These configuration can be overridden in initializer.
|
|
206
218
|
# @return [Config] A new instance of Config
|
|
207
219
|
def initialize
|
|
208
|
-
@enabled
|
|
209
|
-
@orm
|
|
210
|
-
@notification_table_name
|
|
211
|
-
@subscription_table_name
|
|
212
|
-
@email_enabled
|
|
213
|
-
@subscription_enabled
|
|
214
|
-
@subscribe_as_default
|
|
215
|
-
@
|
|
216
|
-
@
|
|
217
|
-
@
|
|
218
|
-
@
|
|
219
|
-
@
|
|
220
|
-
@
|
|
221
|
-
@
|
|
222
|
-
@
|
|
223
|
-
@
|
|
224
|
-
@
|
|
225
|
-
@
|
|
226
|
-
@
|
|
227
|
-
@
|
|
228
|
-
@
|
|
229
|
-
@
|
|
230
|
-
@
|
|
220
|
+
@enabled = true
|
|
221
|
+
@orm = :active_record
|
|
222
|
+
@notification_table_name = 'notifications'
|
|
223
|
+
@subscription_table_name = 'subscriptions'
|
|
224
|
+
@email_enabled = false
|
|
225
|
+
@subscription_enabled = false
|
|
226
|
+
@subscribe_as_default = true
|
|
227
|
+
@subscribe_to_email_as_default = nil
|
|
228
|
+
@subscribe_to_optional_targets_as_default = nil
|
|
229
|
+
@mailer_sender = nil
|
|
230
|
+
@mailer = 'ActivityNotification::Mailer'
|
|
231
|
+
@parent_mailer = 'ActionMailer::Base'
|
|
232
|
+
@parent_job = 'ActiveJob::Base'
|
|
233
|
+
@parent_controller = 'ApplicationController'
|
|
234
|
+
@parent_channel = 'ActionCable::Channel::Base'
|
|
235
|
+
@mailer_templates_dir = 'activity_notification/mailer'
|
|
236
|
+
@opened_index_limit = 10
|
|
237
|
+
@active_job_queue = :activity_notification
|
|
238
|
+
@composite_key_delimiter = '#'
|
|
239
|
+
@store_with_associated_records = false
|
|
240
|
+
@action_cable_enabled = false
|
|
241
|
+
@action_cable_api_enabled = false
|
|
242
|
+
@action_cable_with_devise = false
|
|
243
|
+
@notification_channel_prefix = 'activity_notification_channel'
|
|
244
|
+
@notification_api_channel_prefix = 'activity_notification_api_channel'
|
|
231
245
|
end
|
|
232
246
|
|
|
233
247
|
# Sets ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb)
|
|
@@ -245,5 +259,21 @@ module ActivityNotification
|
|
|
245
259
|
if store_with_associated_records && [:mongoid, :dynamoid].exclude?(@orm) then raise ActivityNotification::ConfigError, "config.store_with_associated_records can be set true only when you use mongoid or dynamoid ORM." end
|
|
246
260
|
@store_with_associated_records = store_with_associated_records
|
|
247
261
|
end
|
|
262
|
+
|
|
263
|
+
# Returns default email subscription value to use when the subscription record does not configured
|
|
264
|
+
# @return [Boolean] Default email subscription value to use when the subscription record does not configured.
|
|
265
|
+
def subscribe_to_email_as_default
|
|
266
|
+
return false unless @subscribe_as_default
|
|
267
|
+
|
|
268
|
+
@subscribe_to_email_as_default.nil? ? @subscribe_as_default : @subscribe_to_email_as_default
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Returns default optional target subscription value to use when the subscription record does not configured
|
|
272
|
+
# @return [Boolean] Default optinal target subscription value to use when the subscription record does not configured.
|
|
273
|
+
def subscribe_to_optional_targets_as_default
|
|
274
|
+
return false unless @subscribe_as_default
|
|
275
|
+
|
|
276
|
+
@subscribe_to_optional_targets_as_default.nil? ? @subscribe_as_default : @subscribe_to_optional_targets_as_default
|
|
277
|
+
end
|
|
248
278
|
end
|
|
249
279
|
end
|
|
@@ -26,7 +26,7 @@ module ActivityNotification
|
|
|
26
26
|
target_class = target_type.to_model_class
|
|
27
27
|
@target = params[:target_id].present? ?
|
|
28
28
|
target_class.find_by!(id: params[:target_id]) :
|
|
29
|
-
target_class.find_by!(id: params["#{target_type.to_resource_name}_id"])
|
|
29
|
+
target_class.find_by!(id: params["#{target_type.to_resource_name[/([^\/]+)$/]}_id"])
|
|
30
30
|
else
|
|
31
31
|
render status: 400, json: error_response(code: 400, message: "Invalid parameter", type: "Parameter is missing or the value is empty: target_type")
|
|
32
32
|
end
|
|
@@ -130,25 +130,9 @@ module ActivityNotification
|
|
|
130
130
|
load_index if params[:reload].to_s.to_boolean(true)
|
|
131
131
|
format.js
|
|
132
132
|
else
|
|
133
|
-
|
|
133
|
+
redirect_back(fallback_location: { action: :index }, **@index_options) and return
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
|
-
|
|
138
|
-
# Redirect to back.
|
|
139
|
-
# @api protected
|
|
140
|
-
# @return [Boolean] True
|
|
141
|
-
def compatibly_redirect_back(request_params = {})
|
|
142
|
-
# :nocov:
|
|
143
|
-
if Rails::VERSION::MAJOR >= 5
|
|
144
|
-
redirect_back fallback_location: { action: :index }, **request_params
|
|
145
|
-
elsif request.referer
|
|
146
|
-
redirect_to :back, **request_params
|
|
147
|
-
else
|
|
148
|
-
redirect_to action: :index, **request_params
|
|
149
|
-
end
|
|
150
|
-
# :nocov:
|
|
151
|
-
true
|
|
152
|
-
end
|
|
153
137
|
end
|
|
154
138
|
end
|
|
@@ -25,8 +25,8 @@ module ActivityNotification
|
|
|
25
25
|
:_notifier,
|
|
26
26
|
:_notification_parameters,
|
|
27
27
|
:_notification_email_allowed,
|
|
28
|
-
:
|
|
29
|
-
:
|
|
28
|
+
:_notifiable_action_cable_allowed,
|
|
29
|
+
:_notifiable_action_cable_api_allowed,
|
|
30
30
|
:_notifiable_path,
|
|
31
31
|
:_printable_notifiable_name,
|
|
32
32
|
:_optional_targets
|
|
@@ -55,8 +55,8 @@ module ActivityNotification
|
|
|
55
55
|
self._notifier = {}
|
|
56
56
|
self._notification_parameters = {}
|
|
57
57
|
self._notification_email_allowed = {}
|
|
58
|
-
self.
|
|
59
|
-
self.
|
|
58
|
+
self._notifiable_action_cable_allowed = {}
|
|
59
|
+
self._notifiable_action_cable_api_allowed = {}
|
|
60
60
|
self._notifiable_path = {}
|
|
61
61
|
self._printable_notifiable_name = {}
|
|
62
62
|
self._optional_targets = {}
|
|
@@ -162,10 +162,10 @@ module ActivityNotification
|
|
|
162
162
|
# @param [Object] target Target instance to notify
|
|
163
163
|
# @param [String] key Key of the notification
|
|
164
164
|
# @return [Boolean] If publishing WebSocket using ActionCable is allowed for the notifiable
|
|
165
|
-
def
|
|
165
|
+
def notifiable_action_cable_allowed?(target, key = nil)
|
|
166
166
|
resolve_parameter(
|
|
167
|
-
"
|
|
168
|
-
|
|
167
|
+
"notifiable_action_cable_allowed_for_#{cast_to_resources_name(target.class)}?",
|
|
168
|
+
_notifiable_action_cable_allowed[cast_to_resources_sym(target.class)],
|
|
169
169
|
ActivityNotification.config.action_cable_enabled,
|
|
170
170
|
target, key)
|
|
171
171
|
end
|
|
@@ -176,10 +176,10 @@ module ActivityNotification
|
|
|
176
176
|
# @param [Object] target Target instance to notify
|
|
177
177
|
# @param [String] key Key of the notification
|
|
178
178
|
# @return [Boolean] If publishing WebSocket API using ActionCable is allowed for the notifiable
|
|
179
|
-
def
|
|
179
|
+
def notifiable_action_cable_api_allowed?(target, key = nil)
|
|
180
180
|
resolve_parameter(
|
|
181
|
-
"
|
|
182
|
-
|
|
181
|
+
"notifiable_action_cable_api_allowed_for_#{cast_to_resources_name(target.class)}?",
|
|
182
|
+
_notifiable_action_cable_api_allowed[cast_to_resources_sym(target.class)],
|
|
183
183
|
ActivityNotification.config.action_cable_api_enabled,
|
|
184
184
|
target, key)
|
|
185
185
|
end
|
|
@@ -456,7 +456,7 @@ module ActivityNotification
|
|
|
456
456
|
unless generated_notifications.to_a.empty?
|
|
457
457
|
record = self.class.human_attribute_name("generated_notifications_as_notifiable_for_#{target_type.to_s.pluralize.underscore}").downcase
|
|
458
458
|
self.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record)
|
|
459
|
-
|
|
459
|
+
throw(:abort)
|
|
460
460
|
end
|
|
461
461
|
when :destroy
|
|
462
462
|
generated_notifications.each { |n| n.destroy }
|
|
@@ -482,7 +482,7 @@ module ActivityNotification
|
|
|
482
482
|
# Casts to symbol of resources name.
|
|
483
483
|
# @api private
|
|
484
484
|
def cast_to_resources_sym(target_type)
|
|
485
|
-
target_type.
|
|
485
|
+
cast_to_resources_name(target_type).to_sym
|
|
486
486
|
end
|
|
487
487
|
end
|
|
488
488
|
end
|
|
@@ -61,7 +61,9 @@ module ActivityNotification
|
|
|
61
61
|
def build_subscription(subscription_params = {})
|
|
62
62
|
created_at = Time.current
|
|
63
63
|
if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
|
|
64
|
-
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
|
|
64
|
+
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
|
|
65
|
+
elsif subscription_params[:subscribing_to_email].nil?
|
|
66
|
+
subscription_params[:subscribing_to_email] = ActivityNotification.config.subscribe_to_email_as_default
|
|
65
67
|
end
|
|
66
68
|
subscription = Subscription.new(subscription_params)
|
|
67
69
|
subscription.assign_attributes(target: self)
|
|
@@ -157,7 +159,7 @@ module ActivityNotification
|
|
|
157
159
|
# @param [String] key Key of the notification
|
|
158
160
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
159
161
|
# @return [Boolean] If the target subscribes to the notification
|
|
160
|
-
def _subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.
|
|
162
|
+
def _subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.subscribe_to_email_as_default)
|
|
161
163
|
evaluate_subscription(subscriptions.where(key: key).first, :subscribing_to_email?, subscribe_as_default)
|
|
162
164
|
end
|
|
163
165
|
alias_method :_subscribes_to_email?, :_subscribes_to_notification_email?
|
|
@@ -170,7 +172,7 @@ module ActivityNotification
|
|
|
170
172
|
# @param [String, Symbol] optional_target_name Class name of the optional target implementation (e.g. :amazon_sns, :slack)
|
|
171
173
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
172
174
|
# @return [Boolean] If the target subscribes to the specified optional target
|
|
173
|
-
def _subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.
|
|
175
|
+
def _subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
|
|
174
176
|
_subscribes_to_notification?(key, subscribe_as_default) &&
|
|
175
177
|
evaluate_subscription(subscriptions.where(key: key).first, :subscribing_to_optional_target?, subscribe_as_default, optional_target_name, subscribe_as_default)
|
|
176
178
|
end
|
|
@@ -189,4 +191,4 @@ module ActivityNotification
|
|
|
189
191
|
end
|
|
190
192
|
|
|
191
193
|
end
|
|
192
|
-
end
|
|
194
|
+
end
|
|
@@ -90,7 +90,7 @@ module ActivityNotification
|
|
|
90
90
|
type: :string
|
|
91
91
|
}
|
|
92
92
|
key :example, {
|
|
93
|
-
|
|
93
|
+
test_default_param: "1"
|
|
94
94
|
}
|
|
95
95
|
end
|
|
96
96
|
property :opened_at do
|
|
@@ -139,28 +139,28 @@ module ActivityNotification
|
|
|
139
139
|
key :type, :object
|
|
140
140
|
key :description, "Associated target model in your application"
|
|
141
141
|
key :example, {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
id: 1,
|
|
143
|
+
email: "ichiro@example.com",
|
|
144
|
+
name: "Ichiro",
|
|
145
|
+
created_at: Time.current,
|
|
146
|
+
updated_at: Time.current,
|
|
147
|
+
provider: "email",
|
|
148
|
+
uid: "",
|
|
149
|
+
printable_type: "User",
|
|
150
|
+
printable_target_name: "Ichiro"
|
|
151
151
|
}
|
|
152
152
|
end
|
|
153
153
|
property :notifiable do
|
|
154
154
|
key :type, :object
|
|
155
155
|
key :description, "Associated notifiable model in your application"
|
|
156
156
|
key :example, {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
id: 22,
|
|
158
|
+
user_id: 2,
|
|
159
|
+
article_id: 11,
|
|
160
|
+
body: "This is the first Stephen's comment to Ichiro's article.",
|
|
161
|
+
created_at: Time.current,
|
|
162
|
+
updated_at: Time.current,
|
|
163
|
+
printable_type: "Comment"
|
|
164
164
|
}
|
|
165
165
|
end
|
|
166
166
|
property :group do
|
|
@@ -168,14 +168,14 @@ module ActivityNotification
|
|
|
168
168
|
key :description, "Associated group model in your application"
|
|
169
169
|
key :nullable, true
|
|
170
170
|
key :example, {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
id: 11,
|
|
172
|
+
user_id: 4,
|
|
173
|
+
title: "Ichiro's great article",
|
|
174
|
+
body: "This is Ichiro's great article. Please read it!",
|
|
175
|
+
created_at: Time.current,
|
|
176
|
+
updated_at: Time.current,
|
|
177
|
+
printable_type: "Article",
|
|
178
|
+
printable_group_name: "article \"Ichiro's great article\""
|
|
179
179
|
}
|
|
180
180
|
end
|
|
181
181
|
property :notifier do
|
|
@@ -183,15 +183,15 @@ module ActivityNotification
|
|
|
183
183
|
key :description, "Associated notifier model in your application"
|
|
184
184
|
key :nullable, true
|
|
185
185
|
key :example, {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
id: 2,
|
|
187
|
+
email: "stephen@example.com",
|
|
188
|
+
name: "Stephen",
|
|
189
|
+
created_at: Time.current,
|
|
190
|
+
updated_at: Time.current,
|
|
191
|
+
provider: "email",
|
|
192
|
+
uid: "",
|
|
193
|
+
printable_type: "User",
|
|
194
|
+
printable_notifier_name: "Stephen"
|
|
195
195
|
}
|
|
196
196
|
end
|
|
197
197
|
property :group_members do
|