activity_notification 1.0.2 → 1.1.0

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +33 -0
  3. data/.rubocop.yml +1157 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG.md +25 -0
  6. data/Gemfile.lock +15 -17
  7. data/README.md +154 -27
  8. data/activity_notification.gemspec +1 -1
  9. data/app/controllers/activity_notification/notifications_controller.rb +30 -104
  10. data/app/controllers/activity_notification/notifications_with_devise_controller.rb +1 -33
  11. data/app/controllers/activity_notification/subscriptions_controller.rb +184 -0
  12. data/app/controllers/activity_notification/subscriptions_with_devise_controller.rb +6 -0
  13. data/app/mailers/activity_notification/mailer.rb +3 -3
  14. data/app/views/activity_notification/notifications/default/_index.html.erb +3 -0
  15. data/app/views/activity_notification/notifications/default/index.html.erb +8 -10
  16. data/app/views/activity_notification/notifications/default/show.html.erb +24 -2
  17. data/app/views/activity_notification/subscriptions/default/_form.html.erb +52 -0
  18. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +89 -0
  19. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +73 -0
  20. data/app/views/activity_notification/subscriptions/default/_subscriptions.html.erb +13 -0
  21. data/app/views/activity_notification/subscriptions/default/create.js.erb +5 -0
  22. data/app/views/activity_notification/subscriptions/default/destroy.js.erb +5 -0
  23. data/app/views/activity_notification/subscriptions/default/index.html.erb +197 -0
  24. data/app/views/activity_notification/subscriptions/default/show.html.erb +177 -0
  25. data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +8 -0
  26. data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +6 -0
  27. data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +8 -0
  28. data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +6 -0
  29. data/gemfiles/Gemfile.rails-4.2.lock +18 -20
  30. data/gemfiles/Gemfile.rails-5.0.lock +18 -20
  31. data/lib/activity_notification.rb +7 -3
  32. data/lib/activity_notification/apis/notification_api.rb +95 -61
  33. data/lib/activity_notification/apis/subscription_api.rb +51 -0
  34. data/lib/activity_notification/common.rb +1 -1
  35. data/lib/activity_notification/config.rb +65 -17
  36. data/lib/activity_notification/controllers/common_controller.rb +118 -0
  37. data/lib/activity_notification/controllers/devise_authentication_controller.rb +41 -0
  38. data/lib/activity_notification/helpers/view_helpers.rb +131 -3
  39. data/lib/activity_notification/mailers/helpers.rb +6 -8
  40. data/lib/activity_notification/models/concerns/notifiable.rb +45 -27
  41. data/lib/activity_notification/models/concerns/subscriber.rb +149 -0
  42. data/lib/activity_notification/models/concerns/target.rb +100 -66
  43. data/lib/activity_notification/models/notification.rb +7 -5
  44. data/lib/activity_notification/models/subscription.rb +93 -0
  45. data/lib/activity_notification/rails/routes.rb +148 -33
  46. data/lib/activity_notification/renderable.rb +3 -4
  47. data/lib/activity_notification/roles/acts_as_notifiable.rb +14 -1
  48. data/lib/activity_notification/roles/acts_as_target.rb +11 -8
  49. data/lib/activity_notification/version.rb +1 -1
  50. data/lib/generators/activity_notification/controllers_generator.rb +2 -2
  51. data/lib/generators/activity_notification/install_generator.rb +0 -1
  52. data/lib/generators/activity_notification/migration/migration_generator.rb +8 -2
  53. data/lib/generators/activity_notification/models_generator.rb +53 -0
  54. data/lib/generators/activity_notification/views_generator.rb +7 -7
  55. data/lib/generators/templates/activity_notification.rb +17 -3
  56. data/lib/generators/templates/controllers/notifications_controller.rb +18 -17
  57. data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +18 -17
  58. data/lib/generators/templates/controllers/subscriptions_controller.rb +79 -0
  59. data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +87 -0
  60. data/lib/generators/templates/migrations/migration.rb +57 -0
  61. data/lib/generators/templates/models/README +10 -0
  62. data/lib/generators/templates/{notification → models}/notification.rb +1 -3
  63. data/lib/generators/templates/models/subscription.rb +4 -0
  64. data/spec/concerns/apis/notification_api_spec.rb +48 -11
  65. data/spec/concerns/apis/subscription_api_spec.rb +167 -0
  66. data/spec/concerns/models/notifiable_spec.rb +60 -0
  67. data/spec/concerns/models/subscriber_spec.rb +525 -0
  68. data/spec/concerns/models/target_spec.rb +271 -42
  69. data/spec/controllers/common_controller_spec.rb +25 -0
  70. data/spec/controllers/dummy_common_controller.rb +5 -0
  71. data/spec/controllers/notifications_controller_shared_examples.rb +2 -6
  72. data/spec/controllers/subscriptions_controller_shared_examples.rb +735 -0
  73. data/spec/controllers/subscriptions_controller_spec.rb +12 -0
  74. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +91 -0
  75. data/spec/factories/dummy/dummy_subscriber.rb +4 -0
  76. data/spec/factories/subscriptions.rb +8 -0
  77. data/spec/generators/controllers_generator_spec.rb +25 -2
  78. data/spec/generators/migration/migration_generator_spec.rb +3 -3
  79. data/spec/generators/models_generator_spec.rb +96 -0
  80. data/spec/generators/views_generator_spec.rb +84 -0
  81. data/spec/helpers/view_helpers_spec.rb +143 -0
  82. data/spec/mailers/mailer_spec.rb +5 -4
  83. data/spec/models/dummy/dummy_subscriber_spec.rb +5 -0
  84. data/spec/models/notification_spec.rb +7 -7
  85. data/spec/models/subscription_spec.rb +158 -0
  86. data/spec/rails_app/app/controllers/users/notifications_controller.rb +67 -0
  87. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +75 -0
  88. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +79 -0
  89. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +87 -0
  90. data/spec/rails_app/app/models/admin.rb +1 -0
  91. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +4 -0
  92. data/spec/rails_app/app/models/user.rb +2 -1
  93. data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +1 -0
  94. data/spec/rails_app/app/views/articles/index.html.erb +6 -0
  95. data/spec/rails_app/config/initializers/activity_notification.rb +17 -3
  96. data/spec/rails_app/config/routes.rb +2 -2
  97. data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +33 -0
  98. data/spec/rails_app/db/schema.rb +18 -0
  99. data/spec/roles/acts_as_notifiable_spec.rb +1 -1
  100. data/spec/roles/acts_as_target_spec.rb +1 -1
  101. metadata +70 -11
  102. data/lib/generators/activity_notification/notification/notification_generator.rb +0 -20
  103. data/lib/generators/templates/active_record/migration.rb +0 -18
  104. data/spec/generators/notification/notification_generator_spec.rb +0 -41
  105. data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +0 -18
@@ -0,0 +1,118 @@
1
+ module ActivityNotification
2
+ # Module included in controllers to select target
3
+ module CommonController
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Include StoreController to allow ActivityNotification access to controller instance
8
+ include StoreController
9
+ # Include PolymorphicHelpers to resolve string extentions
10
+ include PolymorphicHelpers
11
+
12
+ prepend_before_action :set_target
13
+ before_action :set_view_prefixes
14
+ end
15
+
16
+ DEFAULT_VIEW_DIRECTORY = "default"
17
+
18
+ protected
19
+
20
+ # Sets @target instance variable from request parameters.
21
+ # @api protected
22
+ # @return [Object] Target instance (Returns HTTP 400 when request parameters are not enough)
23
+ def set_target
24
+ if (target_type = params[:target_type]).present?
25
+ target_class = target_type.to_model_class
26
+ @target = params[:target_id].present? ?
27
+ target_class.find_by_id!(params[:target_id]) :
28
+ target_class.find_by_id!(params["#{target_type.to_resource_name}_id"])
29
+ else
30
+ render plain: "400 Bad Request: Missing parameter", status: 400
31
+ end
32
+ end
33
+
34
+ # Validate target with belonging model (e.g. Notification and Subscription)
35
+ # @api protected
36
+ # @param [Object] belonging_model belonging model (e.g. Notification and Subscription)
37
+ # @return Nil or render HTTP 403 status
38
+ def validate_target(belonging_model)
39
+ if @target.present? && belonging_model.target != @target
40
+ render plain: "403 Forbidden: Wrong target", status: 403
41
+ end
42
+ end
43
+
44
+ # Sets options to load resource index from request parameters.
45
+ # This method is to be overriden.
46
+ # @api protected
47
+ # @return [Hash] options to load resource index
48
+ def set_index_options
49
+ raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
50
+ end
51
+
52
+ # Loads resource index with request parameters.
53
+ # This method is to be overriden.
54
+ # @api protected
55
+ # @return [Array] Array of resource index
56
+ def load_index
57
+ raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
58
+ end
59
+
60
+ # Returns controller path.
61
+ # This method is called from target_view_path method and can be overriden.
62
+ # @api protected
63
+ # @return [String] "activity_notification" as controller path
64
+ def controller_path
65
+ raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
66
+ end
67
+
68
+ # Returns path of the target view templates.
69
+ # Do not make this method public unless Rendarable module calls controller's target_view_path method to render resources.
70
+ # @api protected
71
+ def target_view_path
72
+ target_type = @target.to_resources_name
73
+ view_path = [controller_path, target_type].join('/')
74
+ lookup_context.exists?(action_name, view_path) ?
75
+ view_path :
76
+ [controller_path, DEFAULT_VIEW_DIRECTORY].join('/')
77
+ end
78
+
79
+ # Sets view prefixes for target view path.
80
+ # @api protected
81
+ def set_view_prefixes
82
+ lookup_context.prefixes.prepend(target_view_path)
83
+ end
84
+
85
+ # Returns JavaScript view for ajax request or redirects to back as default.
86
+ # @api protected
87
+ # @return [Responce] JavaScript view for ajax request or redirects to back as default
88
+ def return_back_or_ajax
89
+ set_index_options
90
+ respond_to do |format|
91
+ if request.xhr?
92
+ load_index if params[:reload].to_s.to_boolean(true)
93
+ format.js
94
+ else
95
+ compatibly_redirect_back(@index_options) and return
96
+ end
97
+ end
98
+ end
99
+
100
+ # Redirect to back.
101
+ # @api protected
102
+ # @return [Boolean] True
103
+ def compatibly_redirect_back(request_params = {})
104
+ # :skip-rails4:
105
+ if Rails::VERSION::MAJOR >= 5
106
+ redirect_back fallback_location: { action: :index }, **request_params
107
+ # :skip-rails4:
108
+ # :skip-rails5:
109
+ elsif request.referer
110
+ redirect_to :back, **request_params
111
+ else
112
+ redirect_to action: :index, **request_params
113
+ end
114
+ # :skip-rails5:
115
+ true
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,41 @@
1
+ module ActivityNotification
2
+ # Module included in controllers to authenticate with Devise module
3
+ module DeviceAuthenticationController
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ prepend_before_action :authenticate_devise_resource!
8
+ before_action :authenticate_target!
9
+ end
10
+
11
+ protected
12
+
13
+ # Authenticate devise resource by Devise (e.g. calling authenticate_user! method).
14
+ # @api protected
15
+ # @todo Needs to call authenticate method by more secure way
16
+ # @return [Responce] Redirects for unsigned in target by Devise, returns HTTP 403 without neccesary target method or returns 400 when request parameters are not enough
17
+ def authenticate_devise_resource!
18
+ if params[:devise_type].present?
19
+ authenticate_method_name = "authenticate_#{params[:devise_type].to_resource_name}!"
20
+ if respond_to?(authenticate_method_name)
21
+ send(authenticate_method_name)
22
+ else
23
+ render plain: "403 Forbidden: Unauthenticated", status: 403
24
+ end
25
+ else
26
+ render plain: "400 Bad Request: Missing parameter", status: 400
27
+ end
28
+ end
29
+
30
+ # Authenticate the target of requested notification with authenticated devise resource.
31
+ # @api protected
32
+ # @todo Needs to call authenticate method by more secure way
33
+ # @return [Responce] Returns HTTP 403 for unauthorized target
34
+ def authenticate_target!
35
+ current_resource_method_name = "current_#{params[:devise_type].to_resource_name}"
36
+ unless @target.authenticated_with_devise?(send(current_resource_method_name))
37
+ render plain: "403 Forbidden: Unauthorized target", status: 403
38
+ end
39
+ end
40
+ end
41
+ end
@@ -5,7 +5,7 @@ module ActivityNotification
5
5
  # View helper for rendering an notification, calls {Notification#render} internally.
6
6
  # @see Notification#render
7
7
  #
8
- # @param [Notification, Array<Notificaion>] Array or single instance of notifications to render
8
+ # @param [Notification, Array<Notificaion>] notifications Array or single instance of notifications to render
9
9
  # @param [Hash] options Options for rendering notifications
10
10
  # @option options [String, Symbol] :target (nil) Target type name to find template or i18n text
11
11
  # @option options [String] :partial ("activity_notification/notifications/#{target}", controller.target_view_path, 'activity_notification/notifications/default') Partial template name
@@ -170,7 +170,7 @@ module ActivityNotification
170
170
 
171
171
  # Returns open_all_notifications_url for the target of specified notification
172
172
  #
173
- # @param [Notification] notification Notification instance
173
+ # @param [Target] target Target instance
174
174
  # @param [Hash] params Request parameters
175
175
  # @return [String] open_all_notifications_url for the target
176
176
  # @todo Needs any other better implementation
@@ -179,6 +179,134 @@ module ActivityNotification
179
179
  send("open_all_#{target.to_resource_name}_notifications_url", target, params)
180
180
  end
181
181
 
182
+ # Returns subscriptions_path for the target
183
+ #
184
+ # @param [Object] target Target instance
185
+ # @param [Hash] params Request parameters
186
+ # @return [String] subscriptions_path for the target
187
+ # @todo Needs any other better implementation
188
+ def subscriptions_path_for(target, params = {})
189
+ send("#{target.to_resource_name}_subscriptions_path", target, params)
190
+ end
191
+
192
+ # Returns subscription_path for the subscription
193
+ #
194
+ # @param [Subscription] subscription Subscription instance
195
+ # @param [Hash] params Request parameters
196
+ # @return [String] subscription_path for the subscription
197
+ # @todo Needs any other better implementation
198
+ def subscription_path_for(subscription, params = {})
199
+ send("#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
200
+ end
201
+
202
+ # Returns subscribe_subscription_path for the target of specified subscription
203
+ #
204
+ # @param [Subscription] subscription Subscription instance
205
+ # @param [Hash] params Request parameters
206
+ # @return [String] subscription_path for the subscription
207
+ # @todo Needs any other better implementation
208
+ def subscribe_subscription_path_for(subscription, params = {})
209
+ send("subscribe_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
210
+ end
211
+ alias_method :subscribe_path_for, :subscribe_subscription_path_for
212
+
213
+ # Returns unsubscribe_subscription_path for the target of specified subscription
214
+ #
215
+ # @param [Subscription] subscription Subscription instance
216
+ # @param [Hash] params Request parameters
217
+ # @return [String] subscription_path for the subscription
218
+ # @todo Needs any other better implementation
219
+ def unsubscribe_subscription_path_for(subscription, params = {})
220
+ send("unsubscribe_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
221
+ end
222
+ alias_method :unsubscribe_path_for, :unsubscribe_subscription_path_for
223
+
224
+ # Returns subscribe_to_email_subscription_path for the target of specified subscription
225
+ #
226
+ # @param [Subscription] subscription Subscription instance
227
+ # @param [Hash] params Request parameters
228
+ # @return [String] subscription_path for the subscription
229
+ # @todo Needs any other better implementation
230
+ def subscribe_to_email_subscription_path_for(subscription, params = {})
231
+ send("subscribe_to_email_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
232
+ end
233
+ alias_method :subscribe_to_email_path_for, :subscribe_to_email_subscription_path_for
234
+
235
+ # Returns unsubscribe_to_email_subscription_path for the target of specified subscription
236
+ #
237
+ # @param [Subscription] subscription Subscription instance
238
+ # @param [Hash] params Request parameters
239
+ # @return [String] subscription_path for the subscription
240
+ # @todo Needs any other better implementation
241
+ def unsubscribe_to_email_subscription_path_for(subscription, params = {})
242
+ send("unsubscribe_to_email_#{subscription.target.to_resource_name}_subscription_path", subscription.target, subscription, params)
243
+ end
244
+ alias_method :unsubscribe_to_email_path_for, :unsubscribe_to_email_subscription_path_for
245
+
246
+ # Returns subscriptions_url for the target
247
+ #
248
+ # @param [Object] target Target instance
249
+ # @param [Hash] params Request parameters
250
+ # @return [String] subscriptions_url for the target
251
+ # @todo Needs any other better implementation
252
+ def subscriptions_url_for(target, params = {})
253
+ send("#{target.to_resource_name}_subscriptions_url", target, params)
254
+ end
255
+
256
+ # Returns subscription_url for the subscription
257
+ #
258
+ # @param [Subscription] subscription Subscription instance
259
+ # @param [Hash] params Request parameters
260
+ # @return [String] subscription_url for the subscription
261
+ # @todo Needs any other better implementation
262
+ def subscription_url_for(subscription, params = {})
263
+ send("#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
264
+ end
265
+
266
+ # Returns subscribe_subscription_url for the target of specified subscription
267
+ #
268
+ # @param [Subscription] subscription Subscription instance
269
+ # @param [Hash] params Request parameters
270
+ # @return [String] subscription_url for the subscription
271
+ # @todo Needs any other better implementation
272
+ def subscribe_subscription_url_for(subscription, params = {})
273
+ send("subscribe_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
274
+ end
275
+ alias_method :subscribe_url_for, :subscribe_subscription_url_for
276
+
277
+ # Returns unsubscribe_subscription_url for the target of specified subscription
278
+ #
279
+ # @param [Subscription] subscription Subscription instance
280
+ # @param [Hash] params Request parameters
281
+ # @return [String] subscription_url for the subscription
282
+ # @todo Needs any other better implementation
283
+ def unsubscribe_subscription_url_for(subscription, params = {})
284
+ send("unsubscribe_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
285
+ end
286
+ alias_method :unsubscribe_url_for, :unsubscribe_subscription_url_for
287
+
288
+ # Returns subscribe_to_email_subscription_url for the target of specified subscription
289
+ #
290
+ # @param [Subscription] subscription Subscription instance
291
+ # @param [Hash] params Request parameters
292
+ # @return [String] subscription_url for the subscription
293
+ # @todo Needs any other better implementation
294
+ def subscribe_to_email_subscription_url_for(subscription, params = {})
295
+ send("subscribe_to_email_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
296
+ end
297
+ alias_method :subscribe_to_email_url_for, :subscribe_to_email_subscription_url_for
298
+
299
+ # Returns unsubscribe_to_email_subscription_url for the target of specified subscription
300
+ #
301
+ # @param [Subscription] subscription Subscription instance
302
+ # @param [Hash] params Request parameters
303
+ # @return [String] subscription_url for the subscription
304
+ # @todo Needs any other better implementation
305
+ def unsubscribe_to_email_subscription_url_for(subscription, params = {})
306
+ send("unsubscribe_to_email_#{subscription.target.to_resource_name}_subscription_url", subscription.target, subscription, params)
307
+ end
308
+ alias_method :unsubscribe_to_email_url_for, :unsubscribe_to_email_subscription_url_for
309
+
182
310
 
183
311
  private
184
312
 
@@ -187,7 +315,7 @@ module ActivityNotification
187
315
  #
188
316
  # @param [Object] target Notification target instance
189
317
  # @param [Symbol] index_content Method to load target notification index, [:simple, :unopened_simple, :opened_simple, :with_attributes, :unopened_with_attributes, :opened_with_attributes, :none] are available
190
- # @param [Hash] params Option parameter to load notification index
318
+ # @param [Hash] options Option parameter to load notification index
191
319
  # @return [Array<Notification>] Array of notification index
192
320
  def load_notification_index(target, index_content, options = {})
193
321
  case index_content
@@ -23,13 +23,11 @@ module ActivityNotification
23
23
  #
24
24
  # @param [Object] target Target of batch notification email
25
25
  # @param [Array<Notification>] notifications Target notifications to send batch notification email
26
+ # @param [String] batch_key Key of the batch notification email
26
27
  # @param [Hash] options Options for notification email
27
- # @option options [String, Symbol] :fallback (:batch_default) Fallback template to use when MissingTemplate is raised
28
- # @option options [String] :batch_key (nil) Key of the batch notification email, a key of the first notification will be used if not specified
29
- def batch_notification_mail(target, notifications, options = {})
28
+ # @option options [String, Symbol] :fallback (:batch_default) Fallback template to use when MissingTemplate is raised
29
+ def batch_notification_mail(target, notifications, batch_key, options = {})
30
30
  initialize_from_notifications(target, notifications)
31
- batch_key = options.delete(:batch_key)
32
- batch_key ||= @notification.key
33
31
  headers = headers_for(batch_key, options)
34
32
  @notification = nil
35
33
  send_mail(headers, options[:fallback])
@@ -55,8 +53,8 @@ module ActivityNotification
55
53
  # @param [String] key Key of the notification
56
54
  # @param [Hash] options Options for email notification
57
55
  def headers_for(key, options)
58
- if !@batch_email and
59
- @notification.notifiable.respond_to?(:overriding_notification_email_key) and
56
+ if !@batch_email &&
57
+ @notification.notifiable.respond_to?(:overriding_notification_email_key) &&
60
58
  @notification.notifiable.overriding_notification_email_key(@target, key).present?
61
59
  key = @notification.notifiable.overriding_notification_email_key(@target, key)
62
60
  end
@@ -126,7 +124,7 @@ module ActivityNotification
126
124
  # @param [String] key Key of the notification
127
125
  # @return [String] Template name
128
126
  def template_name(key)
129
- key.gsub('.', '/')
127
+ key.tr('.', '/')
130
128
  end
131
129
 
132
130
 
@@ -20,6 +20,7 @@ module ActivityNotification
20
20
 
21
21
  class_attribute :_notification_targets,
22
22
  :_notification_group,
23
+ :_notification_group_expiry_delay,
23
24
  :_notifier,
24
25
  :_notification_parameters,
25
26
  :_notification_email_allowed,
@@ -44,13 +45,14 @@ module ActivityNotification
44
45
  # Sets default values to notifiable class fields.
45
46
  # @return [NilClass] nil
46
47
  def set_notifiable_class_defaults
47
- self._notification_targets = {}
48
- self._notification_group = {}
49
- self._notifier = {}
50
- self._notification_parameters = {}
51
- self._notification_email_allowed = {}
52
- self._notifiable_path = {}
53
- self._printable_notifiable_name = {}
48
+ self._notification_targets = {}
49
+ self._notification_group = {}
50
+ self._notification_group_expiry_delay = {}
51
+ self._notifier = {}
52
+ self._notification_parameters = {}
53
+ self._notification_email_allowed = {}
54
+ self._notifiable_path = {}
55
+ self._printable_notifiable_name = {}
54
56
  nil
55
57
  end
56
58
  end
@@ -74,12 +76,12 @@ module ActivityNotification
74
76
  resolved_parameter
75
77
  end
76
78
 
77
- # Returns group owner of the notification from configured field or overriden method.
79
+ # Returns group unit of the notifications from configured field or overriden method.
78
80
  # This method is able to be overriden.
79
81
  #
80
82
  # @param [String] target_type Target type to notify
81
83
  # @param [String] key Key of the notification
82
- # @return [Object] Group owner of the notification
84
+ # @return [Object] Group unit of the notifications
83
85
  def notification_group(target_type, key = nil)
84
86
  resolve_parameter(
85
87
  "notification_group_for_#{cast_to_resources_name(target_type)}",
@@ -87,6 +89,19 @@ module ActivityNotification
87
89
  nil, key)
88
90
  end
89
91
 
92
+ # Returns group expiry period of the notifications from configured field or overriden method.
93
+ # This method is able to be overriden.
94
+ #
95
+ # @param [String] target_type Target type to notify
96
+ # @param [String] key Key of the notification
97
+ # @return [Object] Group expiry period of the notifications
98
+ def notification_group_expiry_delay(target_type, key = nil)
99
+ resolve_parameter(
100
+ "notification_group_expiry_delay_for_#{cast_to_resources_name(target_type)}",
101
+ _notification_group_expiry_delay[cast_to_resources_sym(target_type)],
102
+ nil, key)
103
+ end
104
+
90
105
  # Returns additional notification parameters from configured field or overriden method.
91
106
  # This method is able to be overriden.
92
107
  #
@@ -173,12 +188,13 @@ module ActivityNotification
173
188
  #
174
189
  # @param [Symbol, String, Class] target_type Type of target
175
190
  # @param [Hash] options Options for notifications
176
- # @option options [String] :key (notifiable.default_notification_key) Key of the notification
177
- # @option options [Object] :group (nil) Group unit of the notifications
178
- # @option options [Object] :notifier (nil) Notifier of the notifications
179
- # @option options [Hash] :parameters ({}) Additional parameters of the notifications
180
- # @option options [Boolean] :send_email (true) If it sends notification email
181
- # @option options [Boolean] :send_later (true) If it sends notification email asynchronously
191
+ # @option options [String] :key (notifiable.default_notification_key) Key of the notification
192
+ # @option options [Object] :group (nil) Group unit of the notifications
193
+ # @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
194
+ # @option options [Object] :notifier (nil) Notifier of the notifications
195
+ # @option options [Hash] :parameters ({}) Additional parameters of the notifications
196
+ # @option options [Boolean] :send_email (true) Whether it sends notification email
197
+ # @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
182
198
  # @return [Array<Notificaion>] Array of generated notifications
183
199
  def notify(target_type, options = {})
184
200
  Notification.notify(target_type, self, options)
@@ -190,12 +206,13 @@ module ActivityNotification
190
206
  #
191
207
  # @param [Array<Object>] targets Targets to send notifications
192
208
  # @param [Hash] options Options for notifications
193
- # @option options [String] :key (notifiable.default_notification_key) Key of the notification
194
- # @option options [Object] :group (nil) Group unit of the notifications
195
- # @option options [Object] :notifier (nil) Notifier of the notifications
196
- # @option options [Hash] :parameters ({}) Additional parameters of the notifications
197
- # @option options [Boolean] :send_email (true) Whether it sends notification email
198
- # @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
209
+ # @option options [String] :key (notifiable.default_notification_key) Key of the notification
210
+ # @option options [Object] :group (nil) Group unit of the notifications
211
+ # @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
212
+ # @option options [Object] :notifier (nil) Notifier of the notifications
213
+ # @option options [Hash] :parameters ({}) Additional parameters of the notifications
214
+ # @option options [Boolean] :send_email (true) Whether it sends notification email
215
+ # @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
199
216
  # @return [Array<Notificaion>] Array of generated notifications
200
217
  def notify_all(targets, options = {})
201
218
  Notification.notify_all(targets, self, options)
@@ -207,12 +224,13 @@ module ActivityNotification
207
224
  #
208
225
  # @param [Object] target Target to send notifications
209
226
  # @param [Hash] options Options for notifications
210
- # @option options [String] :key (notifiable.default_notification_key) Key of the notification
211
- # @option options [Object] :group (nil) Group unit of the notifications
212
- # @option options [Object] :notifier (nil) Notifier of the notifications
213
- # @option options [Hash] :parameters ({}) Additional parameters of the notifications
214
- # @option options [Boolean] :send_email (true) Whether it sends notification email
215
- # @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
227
+ # @option options [String] :key (notifiable.default_notification_key) Key of the notification
228
+ # @option options [Object] :group (nil) Group unit of the notifications
229
+ # @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
230
+ # @option options [Object] :notifier (nil) Notifier of the notifications
231
+ # @option options [Hash] :parameters ({}) Additional parameters of the notifications
232
+ # @option options [Boolean] :send_email (true) Whether it sends notification email
233
+ # @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
216
234
  # @return [Notification] Generated notification instance
217
235
  def notify_to(target, options = {})
218
236
  Notification.notify_to(target, self, options)