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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +33 -0
- data/.rubocop.yml +1157 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +15 -17
- data/README.md +154 -27
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +30 -104
- data/app/controllers/activity_notification/notifications_with_devise_controller.rb +1 -33
- data/app/controllers/activity_notification/subscriptions_controller.rb +184 -0
- data/app/controllers/activity_notification/subscriptions_with_devise_controller.rb +6 -0
- data/app/mailers/activity_notification/mailer.rb +3 -3
- data/app/views/activity_notification/notifications/default/_index.html.erb +3 -0
- data/app/views/activity_notification/notifications/default/index.html.erb +8 -10
- data/app/views/activity_notification/notifications/default/show.html.erb +24 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +52 -0
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +89 -0
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +73 -0
- data/app/views/activity_notification/subscriptions/default/_subscriptions.html.erb +13 -0
- data/app/views/activity_notification/subscriptions/default/create.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/destroy.js.erb +5 -0
- data/app/views/activity_notification/subscriptions/default/index.html.erb +197 -0
- data/app/views/activity_notification/subscriptions/default/show.html.erb +177 -0
- data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +6 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +8 -0
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +6 -0
- data/gemfiles/Gemfile.rails-4.2.lock +18 -20
- data/gemfiles/Gemfile.rails-5.0.lock +18 -20
- data/lib/activity_notification.rb +7 -3
- data/lib/activity_notification/apis/notification_api.rb +95 -61
- data/lib/activity_notification/apis/subscription_api.rb +51 -0
- data/lib/activity_notification/common.rb +1 -1
- data/lib/activity_notification/config.rb +65 -17
- data/lib/activity_notification/controllers/common_controller.rb +118 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +41 -0
- data/lib/activity_notification/helpers/view_helpers.rb +131 -3
- data/lib/activity_notification/mailers/helpers.rb +6 -8
- data/lib/activity_notification/models/concerns/notifiable.rb +45 -27
- data/lib/activity_notification/models/concerns/subscriber.rb +149 -0
- data/lib/activity_notification/models/concerns/target.rb +100 -66
- data/lib/activity_notification/models/notification.rb +7 -5
- data/lib/activity_notification/models/subscription.rb +93 -0
- data/lib/activity_notification/rails/routes.rb +148 -33
- data/lib/activity_notification/renderable.rb +3 -4
- data/lib/activity_notification/roles/acts_as_notifiable.rb +14 -1
- data/lib/activity_notification/roles/acts_as_target.rb +11 -8
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -2
- data/lib/generators/activity_notification/install_generator.rb +0 -1
- data/lib/generators/activity_notification/migration/migration_generator.rb +8 -2
- data/lib/generators/activity_notification/models_generator.rb +53 -0
- data/lib/generators/activity_notification/views_generator.rb +7 -7
- data/lib/generators/templates/activity_notification.rb +17 -3
- data/lib/generators/templates/controllers/notifications_controller.rb +18 -17
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +18 -17
- data/lib/generators/templates/controllers/subscriptions_controller.rb +79 -0
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +87 -0
- data/lib/generators/templates/migrations/migration.rb +57 -0
- data/lib/generators/templates/models/README +10 -0
- data/lib/generators/templates/{notification → models}/notification.rb +1 -3
- data/lib/generators/templates/models/subscription.rb +4 -0
- data/spec/concerns/apis/notification_api_spec.rb +48 -11
- data/spec/concerns/apis/subscription_api_spec.rb +167 -0
- data/spec/concerns/models/notifiable_spec.rb +60 -0
- data/spec/concerns/models/subscriber_spec.rb +525 -0
- data/spec/concerns/models/target_spec.rb +271 -42
- data/spec/controllers/common_controller_spec.rb +25 -0
- data/spec/controllers/dummy_common_controller.rb +5 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +2 -6
- data/spec/controllers/subscriptions_controller_shared_examples.rb +735 -0
- data/spec/controllers/subscriptions_controller_spec.rb +12 -0
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +91 -0
- data/spec/factories/dummy/dummy_subscriber.rb +4 -0
- data/spec/factories/subscriptions.rb +8 -0
- data/spec/generators/controllers_generator_spec.rb +25 -2
- data/spec/generators/migration/migration_generator_spec.rb +3 -3
- data/spec/generators/models_generator_spec.rb +96 -0
- data/spec/generators/views_generator_spec.rb +84 -0
- data/spec/helpers/view_helpers_spec.rb +143 -0
- data/spec/mailers/mailer_spec.rb +5 -4
- data/spec/models/dummy/dummy_subscriber_spec.rb +5 -0
- data/spec/models/notification_spec.rb +7 -7
- data/spec/models/subscription_spec.rb +158 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +67 -0
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +75 -0
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +79 -0
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +87 -0
- data/spec/rails_app/app/models/admin.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +4 -0
- data/spec/rails_app/app/models/user.rb +2 -1
- data/spec/rails_app/app/views/activity_notification/mailer/dummy_subscribers/test_key.text.erb +1 -0
- data/spec/rails_app/app/views/articles/index.html.erb +6 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +17 -3
- data/spec/rails_app/config/routes.rb +2 -2
- data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +33 -0
- data/spec/rails_app/db/schema.rb +18 -0
- data/spec/roles/acts_as_notifiable_spec.rb +1 -1
- data/spec/roles/acts_as_target_spec.rb +1 -1
- metadata +70 -11
- data/lib/generators/activity_notification/notification/notification_generator.rb +0 -20
- data/lib/generators/templates/active_record/migration.rb +0 -18
- data/spec/generators/notification/notification_generator_spec.rb +0 -41
- data/spec/rails_app/db/migrate/20160715050420_create_notifications.rb +0 -18
@@ -24,12 +24,13 @@ module ActivityNotification
|
|
24
24
|
# @param [Symbol, String, Class] target_type Type of target
|
25
25
|
# @param [Object] notifiable Notifiable instance
|
26
26
|
# @param [Hash] options Options for notifications
|
27
|
-
# @option options [String]
|
28
|
-
# @option options [Object]
|
29
|
-
# @option options [
|
30
|
-
# @option options [
|
31
|
-
# @option options [
|
32
|
-
# @option options [Boolean]
|
27
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
28
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
29
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
30
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
31
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
32
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
33
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
33
34
|
# @return [Array<Notificaion>] Array of generated notifications
|
34
35
|
def notify(target_type, notifiable, options = {})
|
35
36
|
targets = notifiable.notification_targets(target_type, options[:key])
|
@@ -46,12 +47,13 @@ module ActivityNotification
|
|
46
47
|
# @param [Array<Object>] targets Targets to send notifications
|
47
48
|
# @param [Object] notifiable Notifiable instance
|
48
49
|
# @param [Hash] options Options for notifications
|
49
|
-
# @option options [String]
|
50
|
-
# @option options [Object]
|
51
|
-
# @option options [
|
52
|
-
# @option options [
|
53
|
-
# @option options [
|
54
|
-
# @option options [Boolean]
|
50
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
51
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
52
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
53
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
54
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
55
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
56
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
55
57
|
# @return [Array<Notificaion>] Array of generated notifications
|
56
58
|
def notify_all(targets, notifiable, options = {})
|
57
59
|
targets.map { |target| target.notify_to(notifiable, options) }
|
@@ -65,48 +67,67 @@ module ActivityNotification
|
|
65
67
|
# @param [Object] target Target to send notifications
|
66
68
|
# @param [Object] notifiable Notifiable instance
|
67
69
|
# @param [Hash] options Options for notifications
|
68
|
-
# @option options [String]
|
69
|
-
# @option options [Object]
|
70
|
-
# @option options [
|
71
|
-
# @option options [
|
72
|
-
# @option options [
|
73
|
-
# @option options [Boolean]
|
70
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
71
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
72
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
73
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
74
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
75
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
76
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
74
77
|
# @return [Notification] Generated notification instance
|
75
78
|
def notify_to(target, notifiable, options = {})
|
76
79
|
send_email = options.has_key?(:send_email) ? options[:send_email] : true
|
77
80
|
send_later = options.has_key?(:send_later) ? options[:send_later] : true
|
78
|
-
#
|
79
|
-
notification =
|
81
|
+
# Generate notification
|
82
|
+
notification = generate_notification(target, notifiable, options)
|
80
83
|
# Send notification email
|
81
|
-
notification.
|
82
|
-
|
84
|
+
if notification.present? && send_email
|
85
|
+
notification.send_notification_email({ send_later: send_later })
|
86
|
+
end
|
87
|
+
# Return generated notification
|
83
88
|
notification
|
84
89
|
end
|
85
90
|
|
91
|
+
# Generates a notification
|
92
|
+
# @param [Object] target Target to send notification
|
93
|
+
# @param [Object] notifiable Notifiable instance
|
94
|
+
# @param [Hash] options Options for notification
|
95
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
96
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
97
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
98
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
99
|
+
def generate_notification(target, notifiable, options = {})
|
100
|
+
key = options[:key] || notifiable.default_notification_key
|
101
|
+
if target.subscribes_to_notification?(key)
|
102
|
+
# Store notification
|
103
|
+
store_notification(target, notifiable, key, options)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
86
107
|
# Opens all notifications of the target.
|
87
108
|
#
|
88
109
|
# @param [Object] target Target of the notifications to open
|
89
110
|
# @param [Hash] options Options for opening notifications
|
90
|
-
# @option options [DateTime] :opened_at
|
91
|
-
# @option options [String] :filtered_by_type (nil)
|
92
|
-
# @option options [Object] :filtered_by_group (nil)
|
93
|
-
# @option options [String] :filtered_by_group_type (nil)
|
94
|
-
# @option options [String] :filtered_by_group_id (nil)
|
95
|
-
# @option options [String] :filtered_by_key (nil)
|
111
|
+
# @option options [DateTime] :opened_at (Time.current) Time to set to opened_at of the notification record
|
112
|
+
# @option options [String] :filtered_by_type (nil) Notifiable type for filter
|
113
|
+
# @option options [Object] :filtered_by_group (nil) Group instance for filter
|
114
|
+
# @option options [String] :filtered_by_group_type (nil) Group type for filter, valid with :filtered_by_group_id
|
115
|
+
# @option options [String] :filtered_by_group_id (nil) Group instance id for filter, valid with :filtered_by_group_type
|
116
|
+
# @option options [String] :filtered_by_key (nil) Key of the notification for filter
|
96
117
|
# @return [Integer] Number of opened notification records
|
97
118
|
# @todo Add filter option
|
98
119
|
def open_all_of(target, options = {})
|
99
|
-
opened_at = options[:opened_at] ||
|
120
|
+
opened_at = options[:opened_at] || Time.current
|
100
121
|
target.notifications.unopened_only.filtered_by_options(options).update_all(opened_at: opened_at)
|
101
122
|
end
|
102
123
|
|
103
124
|
# Returns if group member of the notifications exists.
|
104
125
|
# This method is designed to be called from controllers or views to avoid N+1.
|
105
126
|
#
|
106
|
-
# @param [Array<Notificaion
|
127
|
+
# @param [Array<Notificaion>, ActiveRecord_AssociationRelation<Notificaion>] notifications Array or database query of the notifications to test member exists
|
107
128
|
# @return [Boolean] If group member of the notifications exists
|
108
129
|
def group_member_exists?(notifications)
|
109
|
-
notifications.present?
|
130
|
+
notifications.present? && where(group_owner_id: notifications.map(&:id)).exists?
|
110
131
|
end
|
111
132
|
|
112
133
|
# Sends batch notification email to the target.
|
@@ -117,16 +138,16 @@ module ActivityNotification
|
|
117
138
|
# @option options [Boolean] :send_later (false) If it sends notification email asynchronously
|
118
139
|
# @option options [String, Symbol] :fallback (:batch_default) Fallback template to use when MissingTemplate is raised
|
119
140
|
# @option options [String] :batch_key (nil) Key of the batch notification email, a key of the first notification will be used if not specified
|
120
|
-
# @return [Mail::Message
|
141
|
+
# @return [Mail::Message, ActionMailer::DeliveryJob|NilClass] Email message or its delivery job, return NilClass for wrong target
|
121
142
|
def send_batch_notification_email(target, notifications, options = {})
|
122
|
-
|
123
|
-
|
143
|
+
notifications.blank? and return
|
144
|
+
batch_key = options[:batch_key] || notifications.first.key
|
145
|
+
if target.batch_notification_email_allowed?(batch_key) &&
|
146
|
+
target.subscribes_to_notification_email?(batch_key)
|
124
147
|
send_later = options.has_key?(:send_later) ? options[:send_later] : true
|
125
|
-
|
126
|
-
Mailer.send_batch_notification_email(target, notifications, options).deliver_later
|
127
|
-
|
128
|
-
Mailer.send_batch_notification_email(target, notifications, options).deliver_now
|
129
|
-
end
|
148
|
+
send_later ?
|
149
|
+
Mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_later :
|
150
|
+
Mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_now
|
130
151
|
end
|
131
152
|
end
|
132
153
|
|
@@ -139,24 +160,26 @@ module ActivityNotification
|
|
139
160
|
|
140
161
|
# Stores notifications to datastore
|
141
162
|
# @api private
|
142
|
-
def store_notification(target, notifiable, options = {})
|
143
|
-
target_type
|
144
|
-
|
145
|
-
|
146
|
-
notifier
|
147
|
-
parameters
|
163
|
+
def store_notification(target, notifiable, key, options = {})
|
164
|
+
target_type = target.to_class_name
|
165
|
+
group = options[:group] || notifiable.notification_group(target_type, key)
|
166
|
+
group_expiry_delay = options[:group_expiry_delay] || notifiable.notification_group_expiry_delay(target_type, key)
|
167
|
+
notifier = options[:notifier] || notifiable.notifier(target_type, key)
|
168
|
+
parameters = options[:parameters] || {}
|
148
169
|
parameters.merge!(options.except(*available_options))
|
149
170
|
parameters.merge!(notifiable.notification_parameters(target_type, key))
|
150
171
|
|
151
172
|
# Bundle notification group by target, notifiable_type, group and key
|
152
173
|
# Defferent notifiable.id can be made in a same group
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
174
|
+
group_owner_notifications = filtered_by_target(target).filtered_by_type(notifiable.to_class_name).filtered_by_key(key)
|
175
|
+
.filtered_by_group(group).group_owners_only.unopened_only
|
176
|
+
group_owner = group_expiry_delay.present? ?
|
177
|
+
group_owner_notifications.where("created_at > ?", group_expiry_delay.ago).earliest :
|
178
|
+
group_owner_notifications.earliest
|
179
|
+
notification_fields = { target: target, notifiable: notifiable, key: key, group: group, parameters: parameters, notifier: notifier }
|
180
|
+
group.present? && group_owner.present? ?
|
181
|
+
create(notification_fields.merge(group_owner: group_owner)) :
|
182
|
+
create(notification_fields)
|
160
183
|
end
|
161
184
|
end
|
162
185
|
|
@@ -166,27 +189,26 @@ module ActivityNotification
|
|
166
189
|
# @param [Hash] options Options for notification email
|
167
190
|
# @option options [Boolean] :send_later If it sends notification email asynchronously
|
168
191
|
# @option options [String, Symbol] :fallback (:default) Fallback template to use when MissingTemplate is raised
|
169
|
-
# @return [Mail::Message
|
192
|
+
# @return [Mail::Message, ActionMailer::DeliveryJob] Email message or its delivery job
|
170
193
|
def send_notification_email(options = {})
|
171
|
-
if target.notification_email_allowed?(notifiable, key)
|
194
|
+
if target.notification_email_allowed?(notifiable, key) &&
|
195
|
+
email_subscribed?(key) &&
|
172
196
|
notifiable.notification_email_allowed?(target, key)
|
173
197
|
send_later = options.has_key?(:send_later) ? options[:send_later] : true
|
174
|
-
|
175
|
-
Mailer.send_notification_email(self, options).deliver_later
|
176
|
-
else
|
198
|
+
send_later ?
|
199
|
+
Mailer.send_notification_email(self, options).deliver_later :
|
177
200
|
Mailer.send_notification_email(self, options).deliver_now
|
178
|
-
end
|
179
201
|
end
|
180
202
|
end
|
181
203
|
|
182
204
|
# Opens the notification.
|
183
205
|
#
|
184
206
|
# @param [Hash] options Options for opening notifications
|
185
|
-
# @option options [DateTime] :opened_at
|
186
|
-
# @option options [Boolean] :with_members (true)
|
207
|
+
# @option options [DateTime] :opened_at (Time.current) Time to set to opened_at of the notification record
|
208
|
+
# @option options [Boolean] :with_members (true) If it opens notifications including group members
|
187
209
|
# @return [Integer] Number of opened notification records
|
188
210
|
def open!(options = {})
|
189
|
-
opened_at = options[:opened_at] ||
|
211
|
+
opened_at = options[:opened_at] || Time.current
|
190
212
|
with_members = options.has_key?(:with_members) ? options[:with_members] : true
|
191
213
|
update(opened_at: opened_at)
|
192
214
|
with_members ? group_members.update_all(opened_at: opened_at) + 1 : 1
|
@@ -297,6 +319,18 @@ module ActivityNotification
|
|
297
319
|
notifiable.notifiable_path(target_type, key)
|
298
320
|
end
|
299
321
|
|
322
|
+
# Returns if the target subscribes this notification.
|
323
|
+
# @return [Boolean] If the target subscribes the notification
|
324
|
+
def subscribed?
|
325
|
+
target.subscribes_to_notification?(key)
|
326
|
+
end
|
327
|
+
|
328
|
+
# Returns if the target subscribes this notification email.
|
329
|
+
# @return [Boolean] If the target subscribes the notification
|
330
|
+
def email_subscribed?(key)
|
331
|
+
target.subscribes_to_notification_email?(key)
|
332
|
+
end
|
333
|
+
|
300
334
|
|
301
335
|
protected
|
302
336
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
# Defines API for subscription included in Subscription model.
|
3
|
+
module SubscriptionApi
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# Subscribes to the notification and notification email.
|
7
|
+
#
|
8
|
+
# @param [Hash] options Options for subscribing notification
|
9
|
+
# @option options [DateTime] :subscribed_at (Time.current) Time to set to subscribed_at and subscribed_to_email_at of the subscription record
|
10
|
+
# @option options [Boolean] :with_email_subscription (true) If the subscriber also subscribes notification email
|
11
|
+
# @return [Boolean] If successfully updated subscription instance
|
12
|
+
def subscribe(options = {})
|
13
|
+
subscribed_at = options[:subscribed_at] || Time.current
|
14
|
+
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : true
|
15
|
+
with_email_subscription ?
|
16
|
+
update(subscribing: true, subscribing_to_email: true, subscribed_at: subscribed_at, subscribed_to_email_at: subscribed_at) :
|
17
|
+
update(subscribing: true, subscribed_at: subscribed_at)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Unsubscribes to the notification and notification email.
|
21
|
+
#
|
22
|
+
# @param [Hash] options Options for unsubscribing notification
|
23
|
+
# @option options [DateTime] :unsubscribed_at (Time.current) Time to set to unsubscribed_at and unsubscribed_to_email_at of the subscription record
|
24
|
+
# @return [Boolean] If successfully updated subscription instance
|
25
|
+
def unsubscribe(options = {})
|
26
|
+
unsubscribed_at = options[:unsubscribed_at] || Time.current
|
27
|
+
update(subscribing: false, subscribing_to_email: false, unsubscribed_at: unsubscribed_at, unsubscribed_to_email_at: unsubscribed_at)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Subscribes to the notification email.
|
31
|
+
#
|
32
|
+
# @param [Hash] options Options for subscribing notification email
|
33
|
+
# @option options [DateTime] :subscribed_to_email_at (Time.current) Time to set to subscribed_to_email_at of the subscription record
|
34
|
+
# @return [Boolean] If successfully updated subscription instance
|
35
|
+
def subscribe_to_email(options = {})
|
36
|
+
subscribed_to_email_at = options[:subscribed_to_email_at] || Time.current
|
37
|
+
update(subscribing_to_email: true, subscribed_to_email_at: subscribed_to_email_at)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Unsubscribes to the notification email.
|
41
|
+
#
|
42
|
+
# @param [Hash] options Options for unsubscribing notification email
|
43
|
+
# @option options [DateTime] :subscribed_to_email_at (Time.current) Time to set to subscribed_to_email_at of the subscription record
|
44
|
+
# @return [Boolean] If successfully updated subscription instance
|
45
|
+
def unsubscribe_to_email(options = {})
|
46
|
+
unsubscribed_to_email_at = options[:unsubscribed_to_email_at] || Time.current
|
47
|
+
update(subscribing_to_email: false, unsubscribed_to_email_at: unsubscribed_to_email_at)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -42,7 +42,7 @@ module ActivityNotification
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Casts to indifferent hash
|
45
|
-
# @param [ActionController::Parameters, Hash]
|
45
|
+
# @param [ActionController::Parameters, Hash] hash
|
46
46
|
# @return [HashWithIndifferentAccess] Converted indifferent hash
|
47
47
|
def self.cast_to_indifferent_hash(hash = {})
|
48
48
|
# This is the typical (not-ActionView::TestCase) code path.
|
@@ -2,65 +2,110 @@ module ActivityNotification
|
|
2
2
|
# Class used to initialize configuration object.
|
3
3
|
class Config
|
4
4
|
# @overload enabled
|
5
|
+
# Returns whether ActivityNotification is enabled
|
5
6
|
# @return [Boolean] Whether ActivityNotification is enabled.
|
6
7
|
# @overload enabled=(value)
|
7
|
-
# Sets
|
8
|
+
# Sets whether ActivityNotification is enabled
|
8
9
|
# @param [Boolean] enabled The new enabled
|
9
10
|
# @return [Boolean] Whether ActivityNotification is enabled.
|
10
11
|
attr_accessor :enabled
|
11
12
|
|
13
|
+
# @deprecated as of 1.1.0
|
12
14
|
# @overload table_name
|
15
|
+
# Returns table name to store notifications
|
13
16
|
# @return [String] Table name to store notifications.
|
14
17
|
# @overload table_name=(value)
|
15
|
-
# Sets
|
16
|
-
# @param [String] table_name The new
|
18
|
+
# Sets table name to store notifications
|
19
|
+
# @param [String] table_name The new notification_table_name
|
17
20
|
# @return [String] Table name to store notifications.
|
18
21
|
attr_accessor :table_name
|
19
22
|
|
23
|
+
# @overload notification_table_name
|
24
|
+
# Returns table name to store notifications
|
25
|
+
# @return [String] Table name to store notifications.
|
26
|
+
# @overload notification_table_name=(value)
|
27
|
+
# Sets table name to store notifications
|
28
|
+
# @param [String] notification_table_name The new notification_table_name
|
29
|
+
# @return [String] Table name to store notifications.
|
30
|
+
attr_accessor :notification_table_name
|
31
|
+
|
32
|
+
# @overload subscription_table_name
|
33
|
+
# Returns table name to store subscriptions
|
34
|
+
# @return [String] Table name to store subscriptions.
|
35
|
+
# @overload subscription_table_name=(value)
|
36
|
+
# Sets table name to store subscriptions
|
37
|
+
# @param [String] notification_table_name The new subscription_table_name
|
38
|
+
# @return [String] Table name to store subscriptions.
|
39
|
+
attr_accessor :subscription_table_name
|
40
|
+
|
20
41
|
# @overload email_enabled
|
42
|
+
# Returns whether activity_notification sends notification email
|
21
43
|
# @return [Boolean] Whether activity_notification sends notification email.
|
22
44
|
# @overload email_enabled=(value)
|
23
|
-
# Sets
|
45
|
+
# Sets whether activity_notification sends notification email
|
24
46
|
# @param [Boolean] email_enabled The new email_enabled
|
25
47
|
# @return [Boolean] Whether activity_notification sends notification email.
|
26
48
|
attr_accessor :email_enabled
|
27
49
|
|
50
|
+
# @overload subscription_enabled
|
51
|
+
# Returns whether activity_notification manages subscriptions
|
52
|
+
# @return [Boolean] Whether activity_notification manages subscriptions.
|
53
|
+
# @overload subscription_enabled=(value)
|
54
|
+
# Sets whether activity_notification manages subscriptions
|
55
|
+
# @param [Boolean] subscription_enabled The new subscription_enabled
|
56
|
+
# @return [Boolean] Whether activity_notification manages subscriptions.
|
57
|
+
attr_accessor :subscription_enabled
|
58
|
+
|
59
|
+
# @overload subscribe_as_default
|
60
|
+
# Returns default subscription value to use when the subscription record does not configured
|
61
|
+
# @return [Boolean] Default subscription value to use when the subscription record does not configured.
|
62
|
+
# @overload default_subscription=(value)
|
63
|
+
# Sets default subscription value to use when the subscription record does not configured
|
64
|
+
# @param [Boolean] subscribe_as_default The new subscribe_as_default
|
65
|
+
# @return [Boolean] Default subscription value to use when the subscription record does not configured.
|
66
|
+
attr_accessor :subscribe_as_default
|
67
|
+
|
28
68
|
# @overload mailer_sender
|
69
|
+
# Returns email address as sender of notification email
|
29
70
|
# @return [String] Email address as sender of notification email.
|
30
71
|
# @overload mailer_sender=(value)
|
31
|
-
# Sets
|
72
|
+
# Sets email address as sender of notification email
|
32
73
|
# @param [String] mailer_sender The new mailer_sender
|
33
74
|
# @return [String] Email address as sender of notification email.
|
34
75
|
attr_accessor :mailer_sender
|
35
76
|
|
36
77
|
# @overload mailer
|
78
|
+
# Returns mailer class for email notification
|
37
79
|
# @return [String] Mailer class for email notification.
|
38
80
|
# @overload mailer=(value)
|
39
|
-
# Sets
|
81
|
+
# Sets mailer class for email notification
|
40
82
|
# @param [String] mailer The new mailer
|
41
83
|
# @return [String] Mailer class for email notification.
|
42
84
|
attr_accessor :mailer
|
43
85
|
|
44
86
|
# @overload parent_mailer
|
87
|
+
# Returns base mailer class for email notification
|
45
88
|
# @return [String] Base mailer class for email notification.
|
46
89
|
# @overload parent_mailer=(value)
|
47
|
-
# Sets
|
90
|
+
# Sets base mailer class for email notification
|
48
91
|
# @param [String] parent_mailer The new parent_mailer
|
49
92
|
# @return [String] Base mailer class for email notification.
|
50
93
|
attr_accessor :parent_mailer
|
51
94
|
|
52
95
|
# @overload parent_controller
|
96
|
+
# Returns base controller class for notifications_controller
|
53
97
|
# @return [String] Base controller class for notifications_controller.
|
54
98
|
# @overload parent_controller=(value)
|
55
|
-
# Sets
|
99
|
+
# Sets base controller class for notifications_controller
|
56
100
|
# @param [String] parent_controller The new parent_controller
|
57
101
|
# @return [String] Base controller class for notifications_controller.
|
58
102
|
attr_accessor :parent_controller
|
59
103
|
|
60
104
|
# @overload opened_index_limit
|
105
|
+
# Returns default limit to query for opened notifications
|
61
106
|
# @return [Integer] Default limit to query for opened notifications.
|
62
107
|
# @overload opened_index_limit=(value)
|
63
|
-
# Sets
|
108
|
+
# Sets default limit to query for opened notifications
|
64
109
|
# @param [Integer] opened_index_limit The new opened_index_limit
|
65
110
|
# @return [Integer] Default limit to query for opened notifications.
|
66
111
|
attr_accessor :opened_index_limit
|
@@ -69,14 +114,17 @@ module ActivityNotification
|
|
69
114
|
# These configuration can be overriden in initializer.
|
70
115
|
# @return [Config] A new instance of Config
|
71
116
|
def initialize
|
72
|
-
@enabled
|
73
|
-
@
|
74
|
-
@
|
75
|
-
@
|
76
|
-
@
|
77
|
-
@
|
78
|
-
@
|
79
|
-
@
|
117
|
+
@enabled = true
|
118
|
+
@notification_table_name = 'notifications'
|
119
|
+
@subscription_table_name = 'subscriptions'
|
120
|
+
@email_enabled = false
|
121
|
+
@subscription_enabled = false
|
122
|
+
@subscribe_as_default = true
|
123
|
+
@mailer_sender = nil
|
124
|
+
@mailer = 'ActivityNotification::Mailer'
|
125
|
+
@parent_mailer = 'ActionMailer::Base'
|
126
|
+
@parent_controller = 'ApplicationController'
|
127
|
+
@opened_index_limit = 10
|
80
128
|
end
|
81
129
|
|
82
130
|
end
|