activity_notification 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -32
- data/Gemfile +0 -3
- data/Gemfile.lock +66 -73
- data/README.md +190 -184
- data/activity_notification.gemspec +2 -3
- data/gemfiles/Gemfile.rails-4.2 +7 -1
- data/gemfiles/Gemfile.rails-4.2.lock +35 -26
- data/gemfiles/Gemfile.rails-5.0 +7 -1
- data/gemfiles/Gemfile.rails-5.0.lock +73 -64
- data/gemfiles/Gemfile.rails-5.1 +6 -3
- data/gemfiles/Gemfile.rails-5.1.lock +77 -74
- data/lib/activity_notification/apis/notification_api.rb +3 -3
- data/lib/activity_notification/models.rb +1 -1
- data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
- data/lib/activity_notification/models/concerns/target.rb +1 -1
- data/lib/activity_notification/orm/active_record/notification.rb +7 -0
- data/lib/activity_notification/orm/mongoid.rb +11 -1
- data/lib/activity_notification/orm/mongoid/notification.rb +9 -2
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/roles/acts_as_notifiable.rb +30 -15
- data/lib/activity_notification/version.rb +1 -1
- data/spec/rails_app/app/models/admin.rb +1 -1
- data/spec/rails_app/app/models/article.rb +1 -1
- data/spec/rails_app/app/models/comment.rb +1 -1
- data/spec/rails_app/app/models/dummy/dummy_base.rb +10 -2
- data/spec/rails_app/app/models/dummy/dummy_group.rb +13 -3
- data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +13 -3
- data/spec/rails_app/app/models/dummy/dummy_notifier.rb +13 -3
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +12 -3
- data/spec/rails_app/app/models/dummy/dummy_target.rb +14 -3
- data/spec/rails_app/app/models/user.rb +1 -1
- data/spec/rails_app/config/application.rb +7 -3
- data/spec/rails_app/config/environment.rb +1 -1
- data/spec/rails_app/config/environments/development.rb +3 -1
- data/spec/rails_app/config/environments/test.rb +4 -1
- data/spec/roles/acts_as_notifiable_spec.rb +10 -6
- data/spec/spec_helper.rb +0 -3
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1233ff17443dc741c5c016057dc8c8f86e9c8ae0
|
4
|
+
data.tar.gz: e5a4f6930f8ecdd5789a49e082a8ac570bfb43a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c10ba18583a79dff88da3b12ab4e491f96d1906b9ebf448e31ec3d0e3139abf20d46bef8994b112b0794c20c072f02013f3ebfaa5804c266c59fd8368f6df3
|
7
|
+
data.tar.gz: 7f885776939b37d430638fb7a6b84937b7c86dfbcae5c2060e84b5f36b98b557c5497c823567d9f220f052e04d9e82c4450fa6c444129c13c7f5a2636476b659
|
data/CHANGELOG.md
CHANGED
@@ -1,31 +1,38 @@
|
|
1
|
+
## 1.4.1 / 2017-05-17
|
2
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.4.0...v1.4.1)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Remove dependency on *activerecord* from gem runtime dependency
|
7
|
+
|
1
8
|
## 1.4.0 / 2017-05-10
|
2
9
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.3.0...v1.4.0)
|
3
10
|
|
4
11
|
Enhancements:
|
5
12
|
|
6
13
|
* Allow use with Rails 5.1
|
7
|
-
* Allow mongoid models as
|
14
|
+
* Allow mongoid models as *Target* and *Notifiable* models
|
8
15
|
* Add functions for automatic tracked notifications
|
9
|
-
* Enable
|
16
|
+
* Enable *render_notification_of* view helper method to use *:as_latest_group_member* option
|
10
17
|
|
11
18
|
Bug Fixes:
|
12
19
|
|
13
|
-
* Fix illegal ActiveRecord query for MySQL and PostgreSQL database
|
20
|
+
* Fix illegal ActiveRecord query in *Notification#uniq_keys* and *Subscription#uniq_keys* for MySQL and PostgreSQL database
|
14
21
|
|
15
22
|
Breaking Changes:
|
16
23
|
|
17
|
-
* Update type of
|
24
|
+
* Update type of polymorphic id field in *Notification* and *Subscription* models from Integer to String
|
18
25
|
|
19
26
|
## 1.3.0 / 2017-04-07
|
20
27
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.2.1...v1.3.0)
|
21
28
|
|
22
29
|
Enhancements:
|
23
30
|
|
24
|
-
* Suport Mongoid ORM to store
|
25
|
-
* Separate
|
26
|
-
* Update query logic in
|
27
|
-
* Make
|
28
|
-
* Add
|
31
|
+
* Suport Mongoid ORM to store *Notification* and *Subscription* records
|
32
|
+
* Separate *Notification* and *Subscription* models into ORMs and make them load from ORM selector
|
33
|
+
* Update query logic in *Notification* and *Subscription* models for Mongoid
|
34
|
+
* Make *:dependent_notifications* option in *acts_as_notifiable* separate into each target configuration
|
35
|
+
* Add *overriding_notification_template_key* to *Notifiable* model for *Renderable*
|
29
36
|
* Enable Devise integration to use models with single table inheritance
|
30
37
|
|
31
38
|
## 1.2.1 / 2017-01-06
|
@@ -33,11 +40,11 @@ Enhancements:
|
|
33
40
|
|
34
41
|
Enhancements:
|
35
42
|
|
36
|
-
* Support default Slack optional target with
|
43
|
+
* Support default Slack optional target with *slack-notifier* 2.0.0
|
37
44
|
|
38
45
|
Breaking Changes:
|
39
46
|
|
40
|
-
* Rename
|
47
|
+
* Rename *:slack_name* initializing parameter and template parameter of default Slack optional target to *:target_username*
|
41
48
|
|
42
49
|
## 1.2.0 / 2017-01-06
|
43
50
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.1.0...v1.2.0)
|
@@ -49,7 +56,7 @@ Enhancements:
|
|
49
56
|
* Subscription management for optional targets
|
50
57
|
* Amazon SNS client as default optional target implementation
|
51
58
|
* Slack client as default optional target implementation
|
52
|
-
* Add
|
59
|
+
* Add *:restrict_with_+* and *:update_group_and_+* options to *:dependent_notifications* of *acts_as_notifiable*
|
53
60
|
|
54
61
|
## 1.1.0 / 2016-12-18
|
55
62
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.0.2...v1.1.0)
|
@@ -59,17 +66,17 @@ Enhancements:
|
|
59
66
|
* Add subscription management framework
|
60
67
|
* Subscription management model and API
|
61
68
|
* Default subscription controllers, routing and views
|
62
|
-
* Add
|
63
|
-
* Add
|
64
|
-
* Add
|
69
|
+
* Add *Subscriber* role configuration to *Target* role
|
70
|
+
* Add *:as_latest_group_member* option to batch mailer API
|
71
|
+
* Add *:group_expiry_delay* option to notification API
|
65
72
|
|
66
73
|
Bug Fixes:
|
67
74
|
|
68
|
-
* Fix unserializable error in
|
75
|
+
* Fix unserializable error in *Target#send_batch_unopened_notification_email* since unnecessary options are passed to mailer
|
69
76
|
|
70
77
|
Breaking Changes:
|
71
78
|
|
72
|
-
* Remove
|
79
|
+
* Remove *notifiable_type* from the argument of overriden method or configured lambda function with *:batch_email_allowed* option in *acts_as_target* role
|
73
80
|
|
74
81
|
## 1.0.2 / 2016-11-14
|
75
82
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.0.1...v1.0.2)
|
@@ -86,10 +93,10 @@ Enhancements:
|
|
86
93
|
* Add function to send batch email notification
|
87
94
|
* Batch mailer API
|
88
95
|
* Default batch notification email templates
|
89
|
-
*
|
96
|
+
* *Target* role configuration for batch email notification
|
90
97
|
* Improve target API
|
91
|
-
* Add
|
92
|
-
* Add methods to get notifications for specified target type grouped by targets like
|
98
|
+
* Add *:reverse*, *:with_group_members*, *:as_latest_group_member* and *:custom_filter* options to API loading notification index
|
99
|
+
* Add methods to get notifications for specified target type grouped by targets like *Target#notification_index_map*
|
93
100
|
* Arrange default notification email view templates
|
94
101
|
|
95
102
|
Breaking Changes:
|
@@ -102,14 +109,14 @@ Breaking Changes:
|
|
102
109
|
Enhancements:
|
103
110
|
|
104
111
|
* Improve notification API
|
105
|
-
* Add methods to count distinct group members or notifiers like
|
106
|
-
* Update
|
112
|
+
* Add methods to count distinct group members or notifiers like *group_member_notifier_count*
|
113
|
+
* Update *send_later* argument of *send_notification_email* method to options hash argument
|
107
114
|
* Improve target API
|
108
|
-
* Update
|
115
|
+
* Update *notification_index* API to automatically load opened notifications with unopend notifications
|
109
116
|
* Improve acts_as roles
|
110
|
-
* Add
|
111
|
-
* Add
|
112
|
-
* Add
|
117
|
+
* Add *acts_as_group* role
|
118
|
+
* Add *printable_name* configuration for all roles
|
119
|
+
* Add *:dependent_notifications* option to *acts_as_notifiable* to make handle notifications with deleted notifiables
|
113
120
|
* Arrange default notification view templates
|
114
121
|
* Arrange bundled test application
|
115
122
|
* Make default rails version 5.0 and update gem dependency
|
@@ -125,14 +132,14 @@ Breaking Changes:
|
|
125
132
|
Enhancements:
|
126
133
|
|
127
134
|
* Improve controller action and notification API
|
128
|
-
* Add filter options to
|
135
|
+
* Add filter options to *NotificationsController#open_all* action and *Target#open_all_of* method
|
129
136
|
* Add source documentation with YARD
|
130
137
|
* Support rails 5.0 and update gem dependency
|
131
138
|
|
132
139
|
Bug Fixes:
|
133
140
|
|
134
|
-
* Fix
|
135
|
-
* Add including
|
141
|
+
* Fix *Notification#notifiable_path* method to be called with key
|
142
|
+
* Add including *PolymorphicHelpers* statement to *seed.rb* in test application to resolve String extention
|
136
143
|
|
137
144
|
## 0.0.9 / 2016-08-19
|
138
145
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v0.0.8...v0.0.9)
|
@@ -142,12 +149,12 @@ Enhancements:
|
|
142
149
|
* Improve acts_as roles
|
143
150
|
* Enable models to be configured by acts_as role without including statement
|
144
151
|
* Disable email notification as default and add email configurations to acts_as roles
|
145
|
-
* Remove
|
146
|
-
* Update
|
152
|
+
* Remove *:skip_email* option from *acts_as_target*
|
153
|
+
* Update *Renderable#text* method to use `"#{key}.text"` field in i18n properties
|
147
154
|
|
148
155
|
Bug Fixes:
|
149
156
|
|
150
|
-
* Fix wrong method name of
|
157
|
+
* Fix wrong method name of *Notification#notifiable_path*
|
151
158
|
|
152
159
|
## 0.0.8 / 2016-07-31
|
153
160
|
* First release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,7 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/plataformatec/devise.git
|
3
|
-
revision: 83002017ea4761e30796f3b288be9c7d9b870fcd
|
4
|
-
ref: 83002017
|
5
|
-
specs:
|
6
|
-
devise (4.2.1)
|
7
|
-
bcrypt (~> 3.0)
|
8
|
-
orm_adapter (~> 0.1)
|
9
|
-
railties (>= 4.1.0, < 5.2)
|
10
|
-
responders
|
11
|
-
warden (~> 1.2.3)
|
12
|
-
|
13
1
|
PATH
|
14
2
|
remote: .
|
15
3
|
specs:
|
16
|
-
activity_notification (1.4.
|
17
|
-
activerecord (>= 4.2.0)
|
4
|
+
activity_notification (1.4.1)
|
18
5
|
i18n (>= 0.5.0)
|
19
6
|
jquery-rails (>= 3.1.1)
|
20
7
|
railties (>= 4.2.0, < 5.2)
|
@@ -22,39 +9,39 @@ PATH
|
|
22
9
|
GEM
|
23
10
|
remote: https://rubygems.org/
|
24
11
|
specs:
|
25
|
-
actioncable (5.1.
|
26
|
-
actionpack (= 5.1.
|
12
|
+
actioncable (5.1.1)
|
13
|
+
actionpack (= 5.1.1)
|
27
14
|
nio4r (~> 2.0)
|
28
15
|
websocket-driver (~> 0.6.1)
|
29
|
-
actionmailer (5.1.
|
30
|
-
actionpack (= 5.1.
|
31
|
-
actionview (= 5.1.
|
32
|
-
activejob (= 5.1.
|
16
|
+
actionmailer (5.1.1)
|
17
|
+
actionpack (= 5.1.1)
|
18
|
+
actionview (= 5.1.1)
|
19
|
+
activejob (= 5.1.1)
|
33
20
|
mail (~> 2.5, >= 2.5.4)
|
34
21
|
rails-dom-testing (~> 2.0)
|
35
|
-
actionpack (5.1.
|
36
|
-
actionview (= 5.1.
|
37
|
-
activesupport (= 5.1.
|
22
|
+
actionpack (5.1.1)
|
23
|
+
actionview (= 5.1.1)
|
24
|
+
activesupport (= 5.1.1)
|
38
25
|
rack (~> 2.0)
|
39
26
|
rack-test (~> 0.6.3)
|
40
27
|
rails-dom-testing (~> 2.0)
|
41
28
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
42
|
-
actionview (5.1.
|
43
|
-
activesupport (= 5.1.
|
29
|
+
actionview (5.1.1)
|
30
|
+
activesupport (= 5.1.1)
|
44
31
|
builder (~> 3.1)
|
45
32
|
erubi (~> 1.4)
|
46
33
|
rails-dom-testing (~> 2.0)
|
47
34
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
48
|
-
activejob (5.1.
|
49
|
-
activesupport (= 5.1.
|
35
|
+
activejob (5.1.1)
|
36
|
+
activesupport (= 5.1.1)
|
50
37
|
globalid (>= 0.3.6)
|
51
|
-
activemodel (5.1.
|
52
|
-
activesupport (= 5.1.
|
53
|
-
activerecord (5.1.
|
54
|
-
activemodel (= 5.1.
|
55
|
-
activesupport (= 5.1.
|
38
|
+
activemodel (5.1.1)
|
39
|
+
activesupport (= 5.1.1)
|
40
|
+
activerecord (5.1.1)
|
41
|
+
activemodel (= 5.1.1)
|
42
|
+
activesupport (= 5.1.1)
|
56
43
|
arel (~> 8.0)
|
57
|
-
activesupport (5.1.
|
44
|
+
activesupport (5.1.1)
|
58
45
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
59
46
|
i18n (~> 0.7)
|
60
47
|
minitest (~> 5.1)
|
@@ -64,13 +51,13 @@ GEM
|
|
64
51
|
railties (>= 3.0)
|
65
52
|
rspec-rails (>= 2.2)
|
66
53
|
arel (8.0.0)
|
67
|
-
aws-sdk (2.9.
|
68
|
-
aws-sdk-resources (= 2.9.
|
69
|
-
aws-sdk-core (2.9.
|
54
|
+
aws-sdk (2.9.19)
|
55
|
+
aws-sdk-resources (= 2.9.19)
|
56
|
+
aws-sdk-core (2.9.19)
|
70
57
|
aws-sigv4 (~> 1.0)
|
71
58
|
jmespath (~> 1.0)
|
72
|
-
aws-sdk-resources (2.9.
|
73
|
-
aws-sdk-core (= 2.9.
|
59
|
+
aws-sdk-resources (2.9.19)
|
60
|
+
aws-sdk-core (= 2.9.19)
|
74
61
|
aws-sigv4 (1.0.0)
|
75
62
|
bcrypt (3.1.11)
|
76
63
|
bson (4.2.1)
|
@@ -85,6 +72,12 @@ GEM
|
|
85
72
|
term-ansicolor (~> 1.3)
|
86
73
|
thor (~> 0.19.4)
|
87
74
|
tins (~> 1.6)
|
75
|
+
devise (4.3.0)
|
76
|
+
bcrypt (~> 3.0)
|
77
|
+
orm_adapter (~> 0.1)
|
78
|
+
railties (>= 4.1.0, < 5.2)
|
79
|
+
responders
|
80
|
+
warden (~> 1.2.3)
|
88
81
|
diff-lcs (1.3)
|
89
82
|
docile (1.1.5)
|
90
83
|
dotenv (2.2.1)
|
@@ -127,33 +120,33 @@ GEM
|
|
127
120
|
mini_portile2 (~> 2.1.0)
|
128
121
|
orm_adapter (0.5.0)
|
129
122
|
pg (0.20.0)
|
130
|
-
rack (2.0.
|
123
|
+
rack (2.0.3)
|
131
124
|
rack-test (0.6.3)
|
132
125
|
rack (>= 1.0)
|
133
|
-
rails (5.1.
|
134
|
-
actioncable (= 5.1.
|
135
|
-
actionmailer (= 5.1.
|
136
|
-
actionpack (= 5.1.
|
137
|
-
actionview (= 5.1.
|
138
|
-
activejob (= 5.1.
|
139
|
-
activemodel (= 5.1.
|
140
|
-
activerecord (= 5.1.
|
141
|
-
activesupport (= 5.1.
|
126
|
+
rails (5.1.1)
|
127
|
+
actioncable (= 5.1.1)
|
128
|
+
actionmailer (= 5.1.1)
|
129
|
+
actionpack (= 5.1.1)
|
130
|
+
actionview (= 5.1.1)
|
131
|
+
activejob (= 5.1.1)
|
132
|
+
activemodel (= 5.1.1)
|
133
|
+
activerecord (= 5.1.1)
|
134
|
+
activesupport (= 5.1.1)
|
142
135
|
bundler (>= 1.3.0, < 2.0)
|
143
|
-
railties (= 5.1.
|
136
|
+
railties (= 5.1.1)
|
144
137
|
sprockets-rails (>= 2.0.0)
|
145
|
-
rails-controller-testing (1.0.
|
146
|
-
actionpack (~> 5.x)
|
147
|
-
actionview (~> 5.x)
|
138
|
+
rails-controller-testing (1.0.2)
|
139
|
+
actionpack (~> 5.x, >= 5.0.1)
|
140
|
+
actionview (~> 5.x, >= 5.0.1)
|
148
141
|
activesupport (~> 5.x)
|
149
|
-
rails-dom-testing (2.0.
|
150
|
-
activesupport (>= 4.2.0
|
151
|
-
nokogiri (
|
142
|
+
rails-dom-testing (2.0.3)
|
143
|
+
activesupport (>= 4.2.0)
|
144
|
+
nokogiri (>= 1.6)
|
152
145
|
rails-html-sanitizer (1.0.3)
|
153
146
|
loofah (~> 2.0)
|
154
|
-
railties (5.1.
|
155
|
-
actionpack (= 5.1.
|
156
|
-
activesupport (= 5.1.
|
147
|
+
railties (5.1.1)
|
148
|
+
actionpack (= 5.1.1)
|
149
|
+
activesupport (= 5.1.1)
|
157
150
|
method_source
|
158
151
|
rake (>= 0.8.7)
|
159
152
|
thor (>= 0.18.1, < 2.0)
|
@@ -161,23 +154,23 @@ GEM
|
|
161
154
|
responders (2.4.0)
|
162
155
|
actionpack (>= 4.2.0, < 5.3)
|
163
156
|
railties (>= 4.2.0, < 5.3)
|
164
|
-
rspec-core (3.
|
165
|
-
rspec-support (~> 3.
|
166
|
-
rspec-expectations (3.
|
157
|
+
rspec-core (3.6.0)
|
158
|
+
rspec-support (~> 3.6.0)
|
159
|
+
rspec-expectations (3.6.0)
|
167
160
|
diff-lcs (>= 1.2.0, < 2.0)
|
168
|
-
rspec-support (~> 3.
|
169
|
-
rspec-mocks (3.
|
161
|
+
rspec-support (~> 3.6.0)
|
162
|
+
rspec-mocks (3.6.0)
|
170
163
|
diff-lcs (>= 1.2.0, < 2.0)
|
171
|
-
rspec-support (~> 3.
|
172
|
-
rspec-rails (3.
|
164
|
+
rspec-support (~> 3.6.0)
|
165
|
+
rspec-rails (3.6.0)
|
173
166
|
actionpack (>= 3.0)
|
174
167
|
activesupport (>= 3.0)
|
175
168
|
railties (>= 3.0)
|
176
|
-
rspec-core (~> 3.
|
177
|
-
rspec-expectations (~> 3.
|
178
|
-
rspec-mocks (~> 3.
|
179
|
-
rspec-support (~> 3.
|
180
|
-
rspec-support (3.
|
169
|
+
rspec-core (~> 3.6.0)
|
170
|
+
rspec-expectations (~> 3.6.0)
|
171
|
+
rspec-mocks (~> 3.6.0)
|
172
|
+
rspec-support (~> 3.6.0)
|
173
|
+
rspec-support (3.6.0)
|
181
174
|
simplecov (0.14.1)
|
182
175
|
docile (~> 1.1.0)
|
183
176
|
json (>= 1.8, < 3)
|
@@ -197,7 +190,7 @@ GEM
|
|
197
190
|
thor (0.19.4)
|
198
191
|
thread_safe (0.3.6)
|
199
192
|
timecop (0.8.1)
|
200
|
-
tins (1.
|
193
|
+
tins (1.14.0)
|
201
194
|
tzinfo (1.2.3)
|
202
195
|
thread_safe (~> 0.1)
|
203
196
|
uniform_notifier (1.10.0)
|
@@ -219,7 +212,7 @@ DEPENDENCIES
|
|
219
212
|
aws-sdk (~> 2)
|
220
213
|
bullet
|
221
214
|
coveralls
|
222
|
-
devise
|
215
|
+
devise (~> 4.3.0)
|
223
216
|
dotenv-rails
|
224
217
|
factory_girl_rails (~> 4.8.0)
|
225
218
|
mongoid (>= 4.0.0)
|
@@ -227,7 +220,7 @@ DEPENDENCIES
|
|
227
220
|
pg (~> 0.20.0)
|
228
221
|
rails (~> 5.1)
|
229
222
|
rails-controller-testing
|
230
|
-
rspec-rails (~> 3.
|
223
|
+
rspec-rails (~> 3.6.0)
|
231
224
|
simplecov (~> 0.14.1)
|
232
225
|
slack-notifier (>= 1.5.1)
|
233
226
|
sqlite3 (~> 1.3.13)
|
data/README.md
CHANGED
@@ -8,30 +8,30 @@
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/activity_notification.svg)](https://badge.fury.io/rb/activity_notification)
|
9
9
|
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](MIT-LICENSE)
|
10
10
|
|
11
|
-
|
11
|
+
*activity_notification* provides integrated user activity notifications for Ruby on Rails. You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
|
12
12
|
|
13
|
-
|
13
|
+
*activity_notification* supports Rails 4.2+ with ActiveRecord and [Mongoid](http://mongoid.org) ORM. It is tested for MySQL, PostgreSQL, SQLite with ActiveRecord and MongoDB with Mongoid.
|
14
14
|
|
15
15
|
|
16
16
|
## About
|
17
17
|
|
18
|
-
|
18
|
+
*activity_notification* provides following functions:
|
19
19
|
* Notification API (creating notifications, query for notifications and managing notification parameters)
|
20
|
-
* Notification models (stored with ActiveRecord or
|
20
|
+
* Notification models (stored with ActiveRecord or Mongoid ORM)
|
21
21
|
* Notification controllers (managing open/unopen of notifications, providing link to notifiable activity page)
|
22
22
|
* Notification views (presentation of notifications)
|
23
23
|
* Automatic tracked notifications (generating notifications along with the lifecycle of notifiable models)
|
24
|
-
* Grouping notifications (grouping like
|
24
|
+
* Grouping notifications (grouping like *"Kevin and 7 other users posted comments to this article"*)
|
25
25
|
* Email notification
|
26
26
|
* Batch email notification (event driven or periodical email notification, daily or weekly etc)
|
27
|
-
* Subscription management (
|
27
|
+
* Subscription management (subscribing and unsubscribing for each target and notification type)
|
28
28
|
* Integration with [Devise](https://github.com/plataformatec/devise) authentication
|
29
29
|
* Optional notification targets (Configurable optional notification targets like Amazon SNS, Slack, SMS and so on)
|
30
30
|
|
31
31
|
### Notification index and plugin notifications
|
32
32
|
<kbd>![plugin-notifications-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_plugin_focus_with_subscription.png)</kbd>
|
33
33
|
|
34
|
-
|
34
|
+
*activity_notification* deeply uses [PublicActivity](https://github.com/pokonski/public_activity) as reference in presentation layer.
|
35
35
|
|
36
36
|
### Subscription management of notifications
|
37
37
|
<kbd>![subscription-management-image](https://raw.githubusercontent.com/simukappu/activity_notification/images/activity_notification_subscription_management_with_optional_targets.png)</kbd>
|
@@ -55,7 +55,6 @@
|
|
55
55
|
- [Configuring target model](#configuring-target-model)
|
56
56
|
- [Configuring notifiable model](#configuring-notifiable-model)
|
57
57
|
- [Configuring views](#configuring-views)
|
58
|
-
- [Configuring controllers](#configuring-controllers)
|
59
58
|
- [Configuring routes](#configuring-routes)
|
60
59
|
- [Creating notifications](#creating-notifications)
|
61
60
|
- [Notification API](#notification-api)
|
@@ -65,6 +64,7 @@
|
|
65
64
|
- [Rendering notifications](#rendering-notifications)
|
66
65
|
- [Notification views](#notification-views)
|
67
66
|
- [i18n for notifications](#i18n-for-notifications)
|
67
|
+
- [Customizing controllers (optional)](#customizing-controllers-optional-)
|
68
68
|
- [Functions](#functions)
|
69
69
|
- [Email notification](#email-notification)
|
70
70
|
- [Mailer setup](#mailer-setup)
|
@@ -87,6 +87,8 @@
|
|
87
87
|
- [Slack as optional target](#slack-as-optional-target)
|
88
88
|
- [Developing custom optional targets](#developing-custom-optional-targets)
|
89
89
|
- [Testing](#testing)
|
90
|
+
- [Testing your application](#testing-your-application)
|
91
|
+
- [Testing gem alone](#testing-gem-alone)
|
90
92
|
- [Documentation](#documentation)
|
91
93
|
- **[Common examples](#common-examples)**
|
92
94
|
|
@@ -95,7 +97,7 @@
|
|
95
97
|
|
96
98
|
### Gem installation
|
97
99
|
|
98
|
-
You can install
|
100
|
+
You can install *activity_notification* as you would any other gem:
|
99
101
|
|
100
102
|
```console
|
101
103
|
$ gem install activity_notification
|
@@ -106,20 +108,20 @@ or in your Gemfile:
|
|
106
108
|
gem 'activity_notification'
|
107
109
|
```
|
108
110
|
|
109
|
-
After you install
|
111
|
+
After you install *activity_notification* and add it to your Gemfile, you need to run the generator:
|
110
112
|
|
111
113
|
```console
|
112
114
|
$ bin/rails generate activity_notification:install
|
113
115
|
```
|
114
116
|
|
115
|
-
The generator will install an initializer which describes all configuration options of
|
117
|
+
The generator will install an initializer which describes all configuration options of *activity_notification*.
|
116
118
|
It also generates a i18n based translation file which we can configure the presentation of notifications.
|
117
119
|
|
118
120
|
### Database setup
|
119
121
|
|
120
122
|
#### Using ActiveRecord ORM
|
121
123
|
|
122
|
-
When you use
|
124
|
+
When you use *activity_notification* with ActiveRecord ORM as default configuration,
|
123
125
|
create migration for notifications and migrate the database in your Rails project:
|
124
126
|
|
125
127
|
```console
|
@@ -129,13 +131,13 @@ $ bin/rake db:migrate
|
|
129
131
|
|
130
132
|
#### Using Mongoid ORM
|
131
133
|
|
132
|
-
When you use
|
134
|
+
When you use *activity_notification* with [Mongoid](http://mongoid.org) ORM, set **AN_ORM** environment variable to **mongoid**:
|
133
135
|
|
134
136
|
```console
|
135
137
|
$ export AN_ORM=mongoid
|
136
138
|
```
|
137
139
|
|
138
|
-
You can also configure ORM in initializer
|
140
|
+
You can also configure ORM in initializer **activity_notification.rb**:
|
139
141
|
|
140
142
|
```ruby
|
141
143
|
config.orm = :mongoid
|
@@ -147,8 +149,8 @@ You need to configure Mongoid in your Rails application for your MongoDB environ
|
|
147
149
|
|
148
150
|
#### Configuring target model
|
149
151
|
|
150
|
-
Configure your target model (e.g. app/models/user.rb).
|
151
|
-
Add
|
152
|
+
Configure your target model (e.g. *app/models/user.rb*).
|
153
|
+
Add **acts_as_target** configuration to your target model to get notifications.
|
152
154
|
|
153
155
|
##### Target as ActiveRecord model
|
154
156
|
|
@@ -170,19 +172,19 @@ class User
|
|
170
172
|
include Mongoid::Timestamps
|
171
173
|
include GlobalID::Identification
|
172
174
|
|
173
|
-
# You need include ActivityNotification::Models except ActiveRecord
|
175
|
+
# You need include ActivityNotification::Models except models which extends ActiveRecord::Base
|
174
176
|
include ActivityNotification::Models
|
175
177
|
acts_as_target
|
176
178
|
end
|
177
179
|
```
|
178
180
|
|
179
|
-
*Note*:
|
181
|
+
*Note*: *acts_as_notification_target* is an alias for *acts_as_target* and does the same.
|
180
182
|
|
181
183
|
#### Configuring notifiable model
|
182
184
|
|
183
|
-
Configure your notifiable model (e.g. app/models/comment.rb).
|
184
|
-
Add
|
185
|
-
You have to define notification targets for all notifications from this notifiable model by
|
185
|
+
Configure your notifiable model (e.g. *app/models/comment.rb*).
|
186
|
+
Add **acts_as_notifiable** configuration to your notifiable model representing activity to notify for each of your target model.
|
187
|
+
You have to define notification targets for all notifications from this notifiable model by *:targets* option. Other configurations are options. *:notifiable_path* option is a path to move when the notification is opened by the target user.
|
186
188
|
|
187
189
|
##### Notifiable as ActiveRecord model
|
188
190
|
|
@@ -238,7 +240,7 @@ class Comment
|
|
238
240
|
include Mongoid::Timestamps
|
239
241
|
include GlobalID::Identification
|
240
242
|
|
241
|
-
# You need include ActivityNotification::Models except ActiveRecord
|
243
|
+
# You need include ActivityNotification::Models except models which extends ActiveRecord::Base
|
242
244
|
include ActivityNotification::Models
|
243
245
|
acts_as_notifiable :users,
|
244
246
|
targets: ->(comment, key) {
|
@@ -254,83 +256,28 @@ end
|
|
254
256
|
|
255
257
|
### Configuring views
|
256
258
|
|
257
|
-
|
259
|
+
*activity_notification* provides view templates to customize your notification views. The view generator can generate default views for all targets.
|
258
260
|
|
259
261
|
```console
|
260
262
|
$ bin/rails generate activity_notification:views
|
261
263
|
```
|
262
264
|
|
263
|
-
If you have multiple target models in your application, such as
|
265
|
+
If you have multiple target models in your application, such as *User* and *Admin*, you will be able to have views based on the target like *notifications/users/index* and *notifications/admins/index*. If no view is found for the target, *activity_notification* will use the default view at *notifications/default/index*. You can also use the generator to generate views for the specified target:
|
264
266
|
|
265
267
|
```console
|
266
268
|
$ bin/rails generate activity_notification:views users
|
267
269
|
```
|
268
270
|
|
269
|
-
If you would like to generate only a few sets of views, like the ones for the
|
270
|
-
you can pass a list of modules to the generator with the
|
271
|
+
If you would like to generate only a few sets of views, like the ones for the *notifications* (for notification views) and *mailer* (for notification email views),
|
272
|
+
you can pass a list of modules to the generator with the *-v* flag.
|
271
273
|
|
272
274
|
```console
|
273
275
|
$ bin/rails generate activity_notification:views -v notifications
|
274
276
|
```
|
275
277
|
|
276
|
-
### Configuring controllers
|
277
|
-
|
278
|
-
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
279
|
-
|
280
|
-
1. Create your custom controllers using the generator with a target:
|
281
|
-
|
282
|
-
```console
|
283
|
-
$ bin/rails generate activity_notification:controllers users
|
284
|
-
```
|
285
|
-
|
286
|
-
If you specify `users` as the target, controllers will be created in `app/controllers/users/`.
|
287
|
-
And the notifications controller will look like this:
|
288
|
-
|
289
|
-
```ruby
|
290
|
-
class Users::NotificationsController < ActivityNotification::NotificationsController
|
291
|
-
# GET /:target_type/:target_id/notifications
|
292
|
-
# def index
|
293
|
-
# super
|
294
|
-
# end
|
295
|
-
|
296
|
-
# ...
|
297
|
-
|
298
|
-
# POST /:target_type/:target_id/notifications/:id/open
|
299
|
-
# def open
|
300
|
-
# super
|
301
|
-
# end
|
302
|
-
|
303
|
-
# ...
|
304
|
-
end
|
305
|
-
```
|
306
|
-
|
307
|
-
2. Tell the router to use this controller:
|
308
|
-
|
309
|
-
```ruby
|
310
|
-
notify_to :users, controller: 'users/notifications'
|
311
|
-
```
|
312
|
-
|
313
|
-
3. Finally, change or extend the desired controller actions.
|
314
|
-
|
315
|
-
You can completely override a controller action
|
316
|
-
```ruby
|
317
|
-
class Users::NotificationsController < ActivityNotification::NotificationsController
|
318
|
-
# ...
|
319
|
-
|
320
|
-
# POST /:target_type/:target_id/notifications/:id/open
|
321
|
-
def open
|
322
|
-
# Custom code to open notification here
|
323
|
-
|
324
|
-
# super
|
325
|
-
end
|
326
|
-
|
327
|
-
# ...
|
328
|
-
end
|
329
|
-
```
|
330
|
-
|
331
278
|
### Configuring routes
|
332
279
|
|
333
|
-
|
280
|
+
*activity_notification* also provides routing helper for notifications. Add **notify_to** method to *config/routes.rb* for the target (e.g. *:users*):
|
334
281
|
|
335
282
|
```ruby
|
336
283
|
Rails.application.routes.draw do
|
@@ -338,33 +285,36 @@ Rails.application.routes.draw do
|
|
338
285
|
end
|
339
286
|
```
|
340
287
|
|
288
|
+
Then, you can access several pages like *users/1/notifications* and manage open/unopen of notifications using **notifications_controller**.
|
289
|
+
|
341
290
|
### Creating notifications
|
342
291
|
|
343
292
|
#### Notification API
|
344
293
|
|
345
|
-
You can trigger notifications by setting all your required parameters and triggering
|
294
|
+
You can trigger notifications by setting all your required parameters and triggering **notify**
|
346
295
|
on the notifiable model, like this:
|
347
296
|
|
348
297
|
```ruby
|
349
298
|
@comment.notify :users, key: "comment.reply"
|
350
299
|
```
|
351
300
|
|
352
|
-
Or, you can call public API as
|
301
|
+
Or, you can call public API as **ActivityNotification::Notification.notify**
|
353
302
|
|
354
303
|
```ruby
|
355
304
|
ActivityNotification::Notification.notify :users, @comment, key: "comment.reply"
|
356
305
|
```
|
357
306
|
|
358
|
-
The first argument is the plural symbol name of your target model, which is configured in notifiable model by
|
307
|
+
The first argument is the plural symbol name of your target model, which is configured in notifiable model by *acts_as_notifiable*.
|
308
|
+
The new instances of **ActivityNotification::Notification** model will be generated for the specified targets.
|
359
309
|
|
360
|
-
*Hint*:
|
361
|
-
You can override it by
|
310
|
+
*Hint*: *:key* is a option. Default key `#{notifiable_type}.default` which means *comment.default* will be used without specified key.
|
311
|
+
You can override it by *Notifiable#default_notification_key*.
|
362
312
|
|
363
313
|
#### Automatic tracked notifications
|
364
314
|
|
365
|
-
You can also generate automatic tracked notifications by
|
366
|
-
|
367
|
-
Set true to
|
315
|
+
You can also generate automatic tracked notifications by **:tracked** option in *acts_as_notifiable*.
|
316
|
+
*:tracked* option adds required callbacks to generate notifications for creation and update of the notifiable model.
|
317
|
+
Set true to *:tracked* option to generate all tracked notifications, like this:
|
368
318
|
|
369
319
|
```ruby
|
370
320
|
class Comment < ActiveRecord::Base
|
@@ -378,7 +328,7 @@ class Comment < ActiveRecord::Base
|
|
378
328
|
end
|
379
329
|
```
|
380
330
|
|
381
|
-
Or, set
|
331
|
+
Or, set *:only* or *:except* option to generate specified tracked notifications, like this:
|
382
332
|
|
383
333
|
```ruby
|
384
334
|
class Comment < ActiveRecord::Base
|
@@ -400,18 +350,19 @@ class Comment < ActiveRecord::Base
|
|
400
350
|
},
|
401
351
|
# Set { except: [:update] } to :tracked option to generate tracked notifications except update (creation only).
|
402
352
|
# It adds required callbacks to generate notifications for creation of the notifiable model.
|
403
|
-
tracked: { except: [:update] }
|
353
|
+
tracked: { except: [:update], key: 'comment.edit', send_later: false }
|
404
354
|
end
|
405
355
|
```
|
406
356
|
|
407
357
|
*Hint*: `#{notifiable_type}.create` and `#{notifiable_type}.update` will be used as the key of tracked notifications.
|
408
|
-
You can override them by
|
358
|
+
You can override them by *Notifiable#notification_key_for_tracked_creation* and *Notifiable#notification_key_for_tracked_update*.
|
359
|
+
You can also specify key option in the *:tracked* statement.
|
409
360
|
|
410
361
|
### Displaying notifications
|
411
362
|
|
412
363
|
#### Preparing target notifications
|
413
364
|
|
414
|
-
To display notifications, you can use
|
365
|
+
To display notifications, you can use **notifications** association of the target model:
|
415
366
|
|
416
367
|
```ruby
|
417
368
|
# custom_notifications_controller.rb
|
@@ -420,7 +371,7 @@ def index
|
|
420
371
|
end
|
421
372
|
```
|
422
373
|
|
423
|
-
You can also use several scope to filter notifications. For example,
|
374
|
+
You can also use several scope to filter notifications. For example, **unopened_only** to filter them unopened notifications only.
|
424
375
|
|
425
376
|
```ruby
|
426
377
|
# custom_notifications_controller.rb
|
@@ -429,7 +380,7 @@ def index
|
|
429
380
|
end
|
430
381
|
```
|
431
382
|
|
432
|
-
Moreover, you can use
|
383
|
+
Moreover, you can use **notification_index** or **notification_index_with_attributes** methods to automatically prepare notification index for the target.
|
433
384
|
|
434
385
|
```ruby
|
435
386
|
# custom_notifications_controller.rb
|
@@ -440,27 +391,27 @@ end
|
|
440
391
|
|
441
392
|
#### Rendering notifications
|
442
393
|
|
443
|
-
You can use
|
394
|
+
You can use **render_notifications** helper in your views to show the notification index:
|
444
395
|
|
445
396
|
```erb
|
446
397
|
<%= render_notifications(@notifications) %>
|
447
398
|
```
|
448
399
|
|
449
|
-
We can set
|
400
|
+
We can set *:target* option to specify the target type of notifications:
|
450
401
|
|
451
402
|
```erb
|
452
403
|
<%= render_notifications(@notifications, target: :users) %>
|
453
404
|
```
|
454
405
|
|
455
|
-
*Note*:
|
406
|
+
*Note*: *render_notifications* is an alias for *render_notification* and does the same.
|
456
407
|
|
457
|
-
If you want to set notification index in the common layout, such as common header, you can use
|
408
|
+
If you want to set notification index in the common layout, such as common header, you can use **render_notifications_of** helper like this:
|
458
409
|
|
459
410
|
```shared/_header.html.erb
|
460
411
|
<%= render_notifications_of current_user, index_content: :with_attributes %>
|
461
412
|
```
|
462
413
|
|
463
|
-
Then, content named
|
414
|
+
Then, content named **:notification_index** will be prepared and you can use it in your partial template.
|
464
415
|
|
465
416
|
```activity_notifications/notifications/users/_index.html.erb
|
466
417
|
...
|
@@ -476,35 +427,35 @@ Sometimes, it's desirable to pass additional local variables to partials. It can
|
|
476
427
|
|
477
428
|
#### Notification views
|
478
429
|
|
479
|
-
|
430
|
+
*activity_notification* looks for views in *app/views/activity_notification/notifications/:target* with **:key** of the notifications.
|
480
431
|
|
481
|
-
For example, if you have a notification with
|
432
|
+
For example, if you have a notification with *:key* set to *"notification.comment.reply"* and rendered it with *:target* set to *:users*, the gem will look for a partial in *app/views/activity_notification/notifications/users/comment/_reply.html.(|erb|haml|slim|something_else)*.
|
482
433
|
|
483
|
-
*Hint*: the
|
434
|
+
*Hint*: the *"notification."* prefix in *:key* is completely optional, you can skip it in your projects or use this prefix only to make namespace.
|
484
435
|
|
485
|
-
If you would like to fallback to a partial, you can utilize the
|
436
|
+
If you would like to fallback to a partial, you can utilize the **:fallback** parameter to specify the path of a partial to use when one is missing:
|
486
437
|
|
487
438
|
```erb
|
488
439
|
<%= render_notification(@notification, target: :users, fallback: :default) %>
|
489
440
|
```
|
490
441
|
|
491
|
-
When used in this manner, if a partial with the specified
|
442
|
+
When used in this manner, if a partial with the specified *:key* cannot be located, it will use the partial defined in the *:fallback* instead. In the example above this would resolve to *activity_notification/notifications/users/_default.html.(|erb|haml|slim|something_else)*.
|
492
443
|
|
493
|
-
If you do not specify
|
444
|
+
If you do not specify *:target* option like this,
|
494
445
|
|
495
446
|
```erb
|
496
447
|
<%= render_notification(@notification, fallback: :default) %>
|
497
448
|
```
|
498
449
|
|
499
|
-
the gem will look for a partial in
|
450
|
+
the gem will look for a partial in *default* as the target type which means *activity_notification/notifications/default/_default.html.(|erb|haml|slim|something_else)*.
|
500
451
|
|
501
|
-
If a view file does not exist then ActionView::MisingTemplate will be raised. If you wish to fallback to the old behaviour and use an i18n based translation in this situation you can specify a
|
452
|
+
If a view file does not exist then *ActionView::MisingTemplate* will be raised. If you wish to fallback to the old behaviour and use an i18n based translation in this situation you can specify a *:fallback* parameter of *:text* to fallback to this mechanism like such:
|
502
453
|
|
503
454
|
```erb
|
504
455
|
<%= render_notification(@notification, fallback: :text) %>
|
505
456
|
```
|
506
457
|
|
507
|
-
Finally, default views of
|
458
|
+
Finally, default views of *activity_notification* depends on jQuery and you have to add requirements to *application.js* in your apps:
|
508
459
|
|
509
460
|
```app/assets/javascripts/application.js
|
510
461
|
//= require jquery
|
@@ -513,9 +464,9 @@ Finally, default views of `activity_notification` depends on jQuery and you have
|
|
513
464
|
|
514
465
|
#### i18n for notifications
|
515
466
|
|
516
|
-
Translations are used by the
|
467
|
+
Translations are used by the *#text* method, to which you can pass additional options in form of a hash. *#render* method uses translations when view templates have not been provided. You can render pure i18n strings by passing `{ i18n: true }` to *#render_notification* or *#render*.
|
517
468
|
|
518
|
-
Translations should be put in your locale
|
469
|
+
Translations should be put in your locale *.yml* files as **text** field. To render pure strings from I18n example structure:
|
519
470
|
|
520
471
|
```yaml
|
521
472
|
notification:
|
@@ -536,31 +487,86 @@ notification:
|
|
536
487
|
text: '[Admin] Article has been created'
|
537
488
|
```
|
538
489
|
|
539
|
-
This structure is valid for notifications with keys
|
490
|
+
This structure is valid for notifications with keys *"notification.comment.reply"* or *"comment.reply"*. As mentioned before, *"notification."* part of the key is optional. In addition for above example, `%{notifier_name}` and `%{article_title}` are used from parameter field in the notification record.
|
491
|
+
|
492
|
+
### Customizing controllers (optional)
|
493
|
+
|
494
|
+
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
495
|
+
|
496
|
+
1. Create your custom controllers using the generator with a target:
|
497
|
+
|
498
|
+
```console
|
499
|
+
$ bin/rails generate activity_notification:controllers users
|
500
|
+
```
|
501
|
+
|
502
|
+
If you specify *users* as the target, controllers will be created in *app/controllers/users*.
|
503
|
+
And the notifications controller will look like this:
|
504
|
+
|
505
|
+
```ruby
|
506
|
+
class Users::NotificationsController < ActivityNotification::NotificationsController
|
507
|
+
# GET /:target_type/:target_id/notifications
|
508
|
+
# def index
|
509
|
+
# super
|
510
|
+
# end
|
511
|
+
|
512
|
+
# ...
|
513
|
+
|
514
|
+
# POST /:target_type/:target_id/notifications/:id/open
|
515
|
+
# def open
|
516
|
+
# super
|
517
|
+
# end
|
518
|
+
|
519
|
+
# ...
|
520
|
+
end
|
521
|
+
```
|
522
|
+
|
523
|
+
2. Tell the router to use this controller:
|
524
|
+
|
525
|
+
```ruby
|
526
|
+
notify_to :users, controller: 'users/notifications'
|
527
|
+
```
|
528
|
+
|
529
|
+
3. Finally, change or extend the desired controller actions.
|
530
|
+
|
531
|
+
You can completely override a controller action
|
532
|
+
```ruby
|
533
|
+
class Users::NotificationsController < ActivityNotification::NotificationsController
|
534
|
+
# ...
|
535
|
+
|
536
|
+
# POST /:target_type/:target_id/notifications/:id/open
|
537
|
+
def open
|
538
|
+
# Custom code to open notification here
|
539
|
+
|
540
|
+
# super
|
541
|
+
end
|
542
|
+
|
543
|
+
# ...
|
544
|
+
end
|
545
|
+
```
|
540
546
|
|
541
547
|
|
542
548
|
## Functions
|
543
549
|
|
544
550
|
### Email notification
|
545
551
|
|
546
|
-
|
552
|
+
*activity_notification* provides email notification to the notification targets.
|
547
553
|
|
548
554
|
#### Mailer setup
|
549
555
|
|
550
|
-
Set up SMTP server configuration for
|
556
|
+
Set up SMTP server configuration for *ActionMailer*. Then, you need to set up the default URL options for the *activity_notification* mailer in each environment. Here is a possible configuration for *config/environments/development.rb*:
|
551
557
|
|
552
558
|
```ruby
|
553
559
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
554
560
|
```
|
555
561
|
|
556
|
-
Email notification is disabled as default. You can configure to enable email notification in initializer
|
562
|
+
Email notification is disabled as default. You can configure to enable email notification in initializer *activity_notification.rb*.
|
557
563
|
|
558
564
|
```ruby
|
559
565
|
config.email_enabled = true
|
560
566
|
config.mailer_sender = 'your_notification_sender@example.com'
|
561
567
|
```
|
562
568
|
|
563
|
-
You can also configure them for each model by acts_as roles like these.
|
569
|
+
You can also configure them for each model by *acts_as roles* like these.
|
564
570
|
|
565
571
|
```ruby
|
566
572
|
class User < ActiveRecord::Base
|
@@ -591,13 +597,13 @@ end
|
|
591
597
|
|
592
598
|
#### Email templates
|
593
599
|
|
594
|
-
|
600
|
+
*activity_notification* will look for email template in the same way as notification views. For example, if you have a notification with *:key* set to *"notification.comment.reply"* and target_type *users*, the gem will look for a partial in *app/views/activity_notification/mailer/users/comment/_reply.html.(|erb|haml|slim|something_else)*.
|
595
601
|
|
596
|
-
If this template is missing, the gem will look for a partial in
|
602
|
+
If this template is missing, the gem will look for a partial in *default* as the target type which means *activity_notification/mailer/default/_default.html.(|erb|haml|slim|something_else)*.
|
597
603
|
|
598
604
|
#### i18n for email
|
599
605
|
|
600
|
-
The subject of notification email can be put in your locale
|
606
|
+
The subject of notification email can be put in your locale *.yml* files as **mail_subject** field:
|
601
607
|
|
602
608
|
```yaml
|
603
609
|
notification:
|
@@ -610,20 +616,20 @@ notification:
|
|
610
616
|
|
611
617
|
### Batch email notification
|
612
618
|
|
613
|
-
|
619
|
+
*activity_notification* provides batch email notification to the notification targets. You can send notification email daily, hourly or weekly and so on with a scheduler like *whenever*.
|
614
620
|
|
615
621
|
#### Batch mailer setup
|
616
622
|
|
617
|
-
Set up SMTP server configuration for
|
623
|
+
Set up SMTP server configuration for *ActionMailer* and the default URL options for the *activity_notification* mailer in each environment.
|
618
624
|
|
619
|
-
Batch email notification is disabled as default. You can configure to enable email notification in initializer
|
625
|
+
Batch email notification is disabled as default. You can configure to enable email notification in initializer *activity_notification.rb* like single email notification.
|
620
626
|
|
621
627
|
```ruby
|
622
628
|
config.email_enabled = true
|
623
629
|
config.mailer_sender = 'your_notification_sender@example.com'
|
624
630
|
```
|
625
631
|
|
626
|
-
You can also configure them for each target model by
|
632
|
+
You can also configure them for each target model by *acts_as_target* role like this.
|
627
633
|
|
628
634
|
```ruby
|
629
635
|
class User < ActiveRecord::Base
|
@@ -633,7 +639,7 @@ class User < ActiveRecord::Base
|
|
633
639
|
end
|
634
640
|
```
|
635
641
|
|
636
|
-
Then, you can send batch notification email for unopened notifications only to the all specified targets with
|
642
|
+
Then, you can send batch notification email for unopened notifications only to the all specified targets with *batch_key*.
|
637
643
|
|
638
644
|
```ruby
|
639
645
|
# Send batch notification email to the users with unopened notifications
|
@@ -649,12 +655,12 @@ User.send_batch_unopened_notification_email(batch_key: 'batch.comment.post', fil
|
|
649
655
|
|
650
656
|
#### Batch email templates
|
651
657
|
|
652
|
-
|
653
|
-
|
658
|
+
*activity_notification* will look for batch email template in the same way as email notification using *batch_key*.
|
659
|
+
*batch_key* is specified by **:batch_key** option. If this option is not specified, the key of the first notification will be used as *batch_key*.
|
654
660
|
|
655
661
|
#### i18n for batch email
|
656
662
|
|
657
|
-
The subject of batch notification email also can be put in your locale
|
663
|
+
The subject of batch notification email also can be put in your locale *.yml* files as **mail_subject** field for *batch_key*.
|
658
664
|
|
659
665
|
```yaml
|
660
666
|
notification:
|
@@ -667,13 +673,13 @@ notification:
|
|
667
673
|
|
668
674
|
### Grouping notifications
|
669
675
|
|
670
|
-
|
676
|
+
*activity_notification* provides the function for automatically grouping notifications. When you created a notification like this, all *unopened* notifications to the same target will be grouped by *article* set as **:group** options:
|
671
677
|
|
672
678
|
```ruby
|
673
679
|
@comment.notify :users key: 'comment.post', group: @comment.article
|
674
680
|
```
|
675
681
|
|
676
|
-
When you use default notification view, it is helpful to configure
|
682
|
+
When you use default notification view, it is helpful to configure **acts_as_notification_group** (or *acts_as_group*) with *:printable_name* option to render group instance.
|
677
683
|
|
678
684
|
```ruby
|
679
685
|
class Article < ActiveRecord::Base
|
@@ -682,7 +688,7 @@ class Article < ActiveRecord::Base
|
|
682
688
|
end
|
683
689
|
```
|
684
690
|
|
685
|
-
You can use
|
691
|
+
You can use **group_owners_only** scope to filter owner notifications representing each group:
|
686
692
|
|
687
693
|
```ruby
|
688
694
|
# custom_notifications_controller.rb
|
@@ -690,7 +696,7 @@ def index
|
|
690
696
|
@notifications = @target.notifications.group_owners_only
|
691
697
|
end
|
692
698
|
```
|
693
|
-
|
699
|
+
*notification_index* and *notification_index_with_attributes* methods also use *group_owners_only* scope internally.
|
694
700
|
|
695
701
|
And you can render them in a view like this:
|
696
702
|
```erb
|
@@ -702,7 +708,7 @@ And you can render them in a view like this:
|
|
702
708
|
<%= "posted comments to your article \"#{notification.group.title}\"" %>
|
703
709
|
```
|
704
710
|
|
705
|
-
This presentation will be shown to target users as
|
711
|
+
This presentation will be shown to target users as *Kevin and 7 other users posted comments to your article "Let's use Ruby"*.
|
706
712
|
|
707
713
|
You can also use `%{group_member_count}`, `%{group_notification_count}`, `%{group_member_notifier_count}` and `%{group_notifier_count}` in i18n text as a field:
|
708
714
|
|
@@ -715,22 +721,22 @@ notification:
|
|
715
721
|
mail_subject: 'New comment to your article'
|
716
722
|
```
|
717
723
|
|
718
|
-
Then, you will see
|
724
|
+
Then, you will see *"Kevin and 7 other users posted 10 comments to your article"*.
|
719
725
|
|
720
726
|
|
721
727
|
### Subscription management
|
722
728
|
|
723
|
-
|
729
|
+
*activity_notification* provides the function for subscription management of notifications and notification email.
|
724
730
|
|
725
731
|
#### Configuring subscriptions
|
726
732
|
|
727
|
-
Subscription management is disabled as default. You can configure to enable subscription management in initializer
|
733
|
+
Subscription management is disabled as default. You can configure to enable subscription management in initializer *activity_notification.rb*.
|
728
734
|
|
729
735
|
```ruby
|
730
736
|
config.subscription_enabled = true
|
731
737
|
```
|
732
738
|
|
733
|
-
This makes all target model subscribers. You can also configure them for each target model by acts_as_target role like this.
|
739
|
+
This makes all target model subscribers. You can also configure them for each target model by *acts_as_target* role like this.
|
734
740
|
|
735
741
|
```ruby
|
736
742
|
class User < ActiveRecord::Base
|
@@ -750,16 +756,16 @@ $ bin/rake db:migrate
|
|
750
756
|
|
751
757
|
#### Managing subscriptions
|
752
758
|
|
753
|
-
Subscriptions are managed by
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
759
|
+
Subscriptions are managed by instances of **ActivityNotification::Subscription** model which belongs to *target* and *key* of the notification.
|
760
|
+
*Subscription#subscribing* manages subscription of notifications.
|
761
|
+
*true* means the target will receive the notifications with this key.
|
762
|
+
*false* means the target will not receive these notifications.
|
763
|
+
*Subscription#subscribing_to_email* manages subscription of notification email.
|
764
|
+
*true* means the target will receive the notification email with this key including batch notification email with this *batch_key*.
|
765
|
+
*false* means the target will not receive these notification email.
|
760
766
|
|
761
767
|
As default, all target subscribes to notification and notification email when subscription record does not exist in your database.
|
762
|
-
You can change this
|
768
|
+
You can change this **subscribe_as_default** parameter in initializer *activity_notification.rb*.
|
763
769
|
|
764
770
|
```ruby
|
765
771
|
config.subscribe_as_default = false
|
@@ -795,9 +801,9 @@ user.find_or_create_subscription('comment.reply').unsubscribe_to_email
|
|
795
801
|
|
796
802
|
#### Customizing subscriptions
|
797
803
|
|
798
|
-
|
804
|
+
*activity_notification* provides basic controllers and views to manage the subscriptions.
|
799
805
|
|
800
|
-
Add subscription routing to
|
806
|
+
Add subscription routing to *config/routes.rb* for the target (e.g. *:users*):
|
801
807
|
|
802
808
|
```ruby
|
803
809
|
Rails.application.routes.draw do
|
@@ -813,7 +819,7 @@ Rails.application.routes.draw do
|
|
813
819
|
end
|
814
820
|
```
|
815
821
|
|
816
|
-
Then, you can access
|
822
|
+
Then, you can access *users/1/subscriptions* and use **subscriptions_controller** or **subscriptions_with_devise_controller** to manage the subscriptions.
|
817
823
|
|
818
824
|
If you would like to customize subscription controllers or views, you can use generators like notifications:
|
819
825
|
|
@@ -840,9 +846,9 @@ If you would like to customize subscription controllers or views, you can use ge
|
|
840
846
|
|
841
847
|
### Integration with Devise
|
842
848
|
|
843
|
-
|
849
|
+
*activity_notification* supports to integrate with devise authentication.
|
844
850
|
|
845
|
-
First, add
|
851
|
+
First, add **:with_devise** option in notification routing to *config/routes.rb* for the target:
|
846
852
|
|
847
853
|
```ruby
|
848
854
|
Rails.application.routes.draw do
|
@@ -852,11 +858,11 @@ Rails.application.routes.draw do
|
|
852
858
|
end
|
853
859
|
```
|
854
860
|
|
855
|
-
Then
|
861
|
+
Then *activity_notification* will use **notifications_with_devise_controller** as a notification controller. The controller actions automatically call *authenticate_user!* and the user will be restricted to access and operate own notifications only, not others'.
|
856
862
|
|
857
863
|
*Hint*: HTTP 403 Forbidden will be returned for unauthorized notifications.
|
858
864
|
|
859
|
-
You can also use different model from Devise resource as a target. When you will add this to
|
865
|
+
You can also use different model from Devise resource as a target. When you will add this to *config/routes.rb*:
|
860
866
|
|
861
867
|
```ruby
|
862
868
|
Rails.application.routes.draw do
|
@@ -866,7 +872,7 @@ Rails.application.routes.draw do
|
|
866
872
|
end
|
867
873
|
```
|
868
874
|
|
869
|
-
and add
|
875
|
+
and add **:devise_resource** option to *acts_as_target* in the target model:
|
870
876
|
|
871
877
|
```ruby
|
872
878
|
class Admin < ActiveRecord::Base
|
@@ -875,18 +881,18 @@ class Admin < ActiveRecord::Base
|
|
875
881
|
end
|
876
882
|
```
|
877
883
|
|
878
|
-
|
879
|
-
In this example
|
884
|
+
*activity_notification* will authenticate *:admins* notifications with devise authentication for *:users*.
|
885
|
+
In this example *activity_notification* will confirm the *user* who *admin* belongs to with authenticated user by devise.
|
880
886
|
|
881
887
|
|
882
888
|
### Optional notification targets
|
883
889
|
|
884
|
-
|
890
|
+
*activity_notification* supports configurable optional notification targets like Amazon SNS, Slack, SMS and so on.
|
885
891
|
|
886
892
|
#### Configuring optional targets
|
887
893
|
|
888
|
-
|
889
|
-
You can develop any optional target classes which extends
|
894
|
+
*activity_notification* provides default optional target implementation for Amazon SNS and Slack.
|
895
|
+
You can develop any optional target classes which extends *ActivityNotification::OptionalTarget::Base*, and configure them to notifiable model by *acts_as_notifiable* like this.
|
890
896
|
|
891
897
|
```ruby
|
892
898
|
class Comment < ActiveRecord::Base
|
@@ -914,22 +920,22 @@ class Comment < ActiveRecord::Base
|
|
914
920
|
end
|
915
921
|
```
|
916
922
|
|
917
|
-
Write
|
918
|
-
|
923
|
+
Write *require* statement for optional target implementation classes and set them with initializing parameters to *acts_as_notifiable*.
|
924
|
+
*activity_notification* will publish all notifications of those targets and notifiables to optional targets.
|
919
925
|
|
920
926
|
#### Customizing message format
|
921
927
|
|
922
928
|
Optional targets prepare publishing messages from notification instance using view template like rendering notifications.
|
923
|
-
As default, all optional targets use
|
924
|
-
You can customize this template by creating
|
925
|
-
For example, if you have a notification for
|
926
|
-
The gem will also look for templates whose
|
929
|
+
As default, all optional targets use *app/views/activity_notification/optional_targets/default/base/_default.text.erb*.
|
930
|
+
You can customize this template by creating *app/views/activity_notification/optional_targets/<target_class_name>/<optional_target_class_name>/<notification_key>.text.(|erb|haml|slim|something_else)*.
|
931
|
+
For example, if you have a notification for *:users* target with *:key* set to *"notification.comment.reply"* and *ActivityNotification::OptionalTarget::AmazonSNS* optional target is configured, the gem will look for a partial in *app/views/activity_notification/optional_targets/users/amazon_sns/comment/_reply.text.erb*.
|
932
|
+
The gem will also look for templates whose *<target_class_name>* is *default*, *<optional_target_class_name>* is *base* and *<notification_key>* is *default*, which means *app/views/activity_notification/optional_targets/users/amazon_sns/_default.text.erb*, *app/views/activity_notification/optional_targets/users/base/_default.text.erb*, *app/views/activity_notification/optional_targets/default/amazon_sns/_default.text.erb* and *app/views/activity_notification/optional_targets/default/base/_default.text.erb*.
|
927
933
|
|
928
934
|
#### Amazon SNS as optional target
|
929
935
|
|
930
|
-
|
936
|
+
*activity_notification* provides **ActivityNotification::OptionalTarget::AmazonSNS** as default optional target implementation for Amazon SNS.
|
931
937
|
|
932
|
-
First, add
|
938
|
+
First, add **aws-sdk** gem to your Gemfile and set AWS Credentials for SDK (See [Configuring the AWS SDK for Ruby](https://docs.aws.amazon.com/sdk-for-ruby/v2/developer-guide/setup-config.html)).
|
933
939
|
|
934
940
|
```ruby
|
935
941
|
gem 'aws-sdk', '~> 2'
|
@@ -943,7 +949,7 @@ Aws.config.update(
|
|
943
949
|
)
|
944
950
|
```
|
945
951
|
|
946
|
-
Then, write `require 'activity_notification/optional_targets/amazon_sns'` statement in your notifiable model and set
|
952
|
+
Then, write `require 'activity_notification/optional_targets/amazon_sns'` statement in your notifiable model and set *ActivityNotification::OptionalTarget::AmazonSNS* to *acts_as_notifiable* with *:topic_arn*, *:target_arn* or *:phone_number* initializing parameters.
|
947
953
|
Any other options for `Aws::SNS::Client.new` are available as initializing parameters. See [API Reference of Class: Aws::SNS::Client](http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Client.html) for more details.
|
948
954
|
|
949
955
|
```ruby
|
@@ -958,15 +964,15 @@ end
|
|
958
964
|
|
959
965
|
#### Slack as optional target
|
960
966
|
|
961
|
-
|
967
|
+
*activity_notification* provides **ActivityNotification::OptionalTarget::Slack** as default optional target implementation for Slack.
|
962
968
|
|
963
|
-
First, add
|
969
|
+
First, add **slack-notifier** gem to your Gemfile and create Incoming WebHooks in Slack (See [Incoming WebHooks](https://wemakejp.slack.com/apps/A0F7XDUAZ-incoming-webhooks)).
|
964
970
|
|
965
971
|
```ruby
|
966
972
|
gem 'slack-notifier'
|
967
973
|
```
|
968
974
|
|
969
|
-
Then, write `require 'activity_notification/optional_targets/slack'` statement in your notifiable model and set
|
975
|
+
Then, write `require 'activity_notification/optional_targets/slack'` statement in your notifiable model and set *ActivityNotification::OptionalTarget::Slack* to *acts_as_notifiable* with *:webhook_url* and *:target_username* initializing parameters. *:webhook_url* is created WebHook URL and required, *:target_username* is target's slack user name as String value, symbol method name or lambda function and is optional.
|
970
976
|
Any other options for `Slack::Notifier.new` are available as initializing parameters. See [Github slack-notifier](https://github.com/stevenosloan/slack-notifier) and [API Reference of Class: Slack::Notifier](http://www.rubydoc.info/gems/slack-notifier/1.5.1/Slack/Notifier) for more details.
|
971
977
|
|
972
978
|
```ruby
|
@@ -985,10 +991,10 @@ end
|
|
985
991
|
#### Developing custom optional targets
|
986
992
|
|
987
993
|
You can develop any custom optional targets.
|
988
|
-
Custom optional target class must extend
|
989
|
-
You can use
|
994
|
+
Custom optional target class must extend **ActivityNotification::OptionalTarget::Base** and override **initialize_target** and **notify** method.
|
995
|
+
You can use **render_notification_message** method to prepare message from notification instance using view template.
|
990
996
|
|
991
|
-
For example, create
|
997
|
+
For example, create *lib/custom_optional_targets/amazon_sns.rb* as follows:
|
992
998
|
|
993
999
|
```ruby
|
994
1000
|
module CustomOptionalTarget
|
@@ -1017,7 +1023,7 @@ module CustomOptionalTarget
|
|
1017
1023
|
end
|
1018
1024
|
```
|
1019
1025
|
|
1020
|
-
Then, you can configure them to notifiable model by
|
1026
|
+
Then, you can configure them to notifiable model by *acts_as_notifiable* like this.
|
1021
1027
|
|
1022
1028
|
```ruby
|
1023
1029
|
class Comment < ActiveRecord::Base
|
@@ -1029,7 +1035,7 @@ class Comment < ActiveRecord::Base
|
|
1029
1035
|
end
|
1030
1036
|
```
|
1031
1037
|
|
1032
|
-
|
1038
|
+
*acts_as_notifiable* creates optional target instances and calls *initialize_target* method with initializing parameters.
|
1033
1039
|
|
1034
1040
|
|
1035
1041
|
## Testing
|
@@ -1071,7 +1077,7 @@ expect(ActivityNotification::Mailer.deliveries.size).to eq(0)
|
|
1071
1077
|
expect(ActivityNotification::Mailer.deliveries.size).to eq(1)
|
1072
1078
|
expect(ActivityNotification::Mailer.deliveries.first.to[0]).to eq(@article_author.email)
|
1073
1079
|
```
|
1074
|
-
Note that notification email will be sent asynchronously without false as
|
1080
|
+
Note that notification email will be sent asynchronously without false as *:send_later* option.
|
1075
1081
|
```ruby
|
1076
1082
|
# Prepare
|
1077
1083
|
include ActiveJob::TestHelper
|
@@ -1103,7 +1109,7 @@ $ bundle exec rake
|
|
1103
1109
|
```
|
1104
1110
|
|
1105
1111
|
#### Dummy Rails application
|
1106
|
-
Test module includes dummy Rails application
|
1112
|
+
Test module includes dummy Rails application in **spec/rails_app**. You can run the dummy application as common Rails application.
|
1107
1113
|
```console
|
1108
1114
|
$ cd spec/rails_app
|
1109
1115
|
$ bin/rake db:migrate
|
@@ -1113,9 +1119,9 @@ $ bin/rails server
|
|
1113
1119
|
Then, you can access <http://localhost:3000> for the dummy application.
|
1114
1120
|
|
1115
1121
|
##### Run with your local database
|
1116
|
-
As default, dummy Rails application runs with local SQLite database in
|
1122
|
+
As default, dummy Rails application runs with local SQLite database in *spec/rails_app/db/development.sqlite3*.
|
1117
1123
|
This application supports to run with your local MySQL, PostgreSQL and MongoDB.
|
1118
|
-
Set
|
1124
|
+
Set **AN_TEST_DB** environment variable like:
|
1119
1125
|
```console
|
1120
1126
|
$ export AN_TEST_DB=mysql
|
1121
1127
|
```
|
@@ -1127,12 +1133,12 @@ for PostgreSQL, and
|
|
1127
1133
|
```console
|
1128
1134
|
$ export AN_TEST_DB=mongodb
|
1129
1135
|
```
|
1130
|
-
for MongoDB. When you set
|
1136
|
+
for MongoDB. When you set **mongodb** as *AN_TEST_DB*, you have to use *activity_notification* with MongoDB. Also set **AN_ORM** like:
|
1131
1137
|
```console
|
1132
1138
|
$ export AN_ORM=mongoid
|
1133
1139
|
```
|
1134
1140
|
|
1135
|
-
Then, configure
|
1141
|
+
Then, configure *spec/rails_app/config/database.yml* or *spec/rails_app/config/mongoid.yml* as your local database.
|
1136
1142
|
Finally, run database migration, seed data script and the dummy appliation.
|
1137
1143
|
```console
|
1138
1144
|
$ cd spec/rails_app
|
@@ -1147,7 +1153,7 @@ $ bin/rails server
|
|
1147
1153
|
|
1148
1154
|
See [API Reference](http://www.rubydoc.info/github/simukappu/activity_notification/index) for more details.
|
1149
1155
|
|
1150
|
-
RubyDoc.info does not support parsing methods in
|
1156
|
+
RubyDoc.info does not support parsing methods in *included* and *class_methods* of *ActiveSupport::Concern* currently.
|
1151
1157
|
To read complete documents, please generate YARD documents on your local environment:
|
1152
1158
|
```console
|
1153
1159
|
$ git pull https://github.com/simukappu/activity_notification.git
|
@@ -1160,7 +1166,7 @@ Then you can see the documents at <http://localhost:8808/docs/index>.
|
|
1160
1166
|
|
1161
1167
|
## Common examples
|
1162
1168
|
|
1163
|
-
To be prepared. See dummy Rails application in
|
1169
|
+
To be prepared. See dummy Rails application in *spec/rails_app*.
|
1164
1170
|
|
1165
1171
|
|
1166
1172
|
## Help
|
@@ -1170,4 +1176,4 @@ Contact us by email of this repository.
|
|
1170
1176
|
|
1171
1177
|
## License
|
1172
1178
|
|
1173
|
-
|
1179
|
+
*activity_notification* project rocks and uses [MIT License](MIT-LICENSE).
|