activity_notification 1.4.4 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  4. data/.github/pull_request_template.md +13 -0
  5. data/.github/workflows/build.yml +116 -0
  6. data/.gitignore +15 -3
  7. data/CHANGELOG.md +200 -1
  8. data/Gemfile +17 -2
  9. data/Procfile +2 -0
  10. data/README.md +168 -1033
  11. data/Rakefile +19 -10
  12. data/activity_notification.gemspec +14 -9
  13. data/app/channels/activity_notification/notification_api_channel.rb +12 -0
  14. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
  15. data/app/channels/activity_notification/notification_channel.rb +37 -0
  16. data/app/channels/activity_notification/notification_with_devise_channel.rb +51 -0
  17. data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
  18. data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
  19. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
  20. data/app/controllers/activity_notification/notifications_controller.rb +60 -54
  21. data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
  22. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
  23. data/app/controllers/activity_notification/subscriptions_controller.rb +83 -73
  24. data/app/jobs/activity_notification/notify_all_job.rb +25 -0
  25. data/app/jobs/activity_notification/notify_job.rb +26 -0
  26. data/app/jobs/activity_notification/notify_to_job.rb +25 -0
  27. data/app/views/activity_notification/notifications/default/_default.html.erb +23 -23
  28. data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +19 -19
  29. data/app/views/activity_notification/notifications/default/_index.html.erb +3 -3
  30. data/app/views/activity_notification/notifications/default/index.html.erb +60 -7
  31. data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
  32. data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
  33. data/app/views/activity_notification/notifications/default/show.html.erb +2 -2
  34. data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
  35. data/app/views/activity_notification/optional_targets/default/base/_default.text.erb +1 -1
  36. data/app/views/activity_notification/optional_targets/default/slack/_default.text.erb +1 -1
  37. data/app/views/activity_notification/subscriptions/default/_form.html.erb +2 -2
  38. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +5 -33
  39. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +8 -8
  40. data/app/views/activity_notification/subscriptions/default/index.html.erb +13 -9
  41. data/app/views/activity_notification/subscriptions/default/show.html.erb +3 -3
  42. data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +1 -1
  43. data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +1 -1
  44. data/app/views/activity_notification/subscriptions/default/subscribe_to_optional_target.js.erb +1 -1
  45. data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +1 -1
  46. data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +1 -1
  47. data/app/views/activity_notification/subscriptions/default/unsubscribe_to_optional_target.js.erb +1 -1
  48. data/bin/_dynamodblocal +4 -0
  49. data/bin/bundle_update.sh +7 -0
  50. data/bin/deploy_on_heroku.sh +16 -0
  51. data/bin/install_dynamodblocal.sh +5 -0
  52. data/bin/start_dynamodblocal.sh +47 -0
  53. data/bin/stop_dynamodblocal.sh +34 -0
  54. data/docs/CODE_OF_CONDUCT.md +76 -0
  55. data/docs/CONTRIBUTING.md +36 -0
  56. data/docs/Functions.md +1146 -0
  57. data/docs/Setup.md +817 -0
  58. data/docs/Testing.md +148 -0
  59. data/gemfiles/Gemfile.rails-5.0 +8 -1
  60. data/gemfiles/Gemfile.rails-5.1 +7 -1
  61. data/gemfiles/Gemfile.rails-5.2 +24 -0
  62. data/gemfiles/Gemfile.rails-6.0 +23 -0
  63. data/gemfiles/Gemfile.rails-6.1 +22 -0
  64. data/gemfiles/Gemfile.rails-7.0 +25 -0
  65. data/lib/activity_notification/apis/notification_api.rb +356 -159
  66. data/lib/activity_notification/apis/subscription_api.rb +98 -59
  67. data/lib/activity_notification/apis/swagger.rb +6 -0
  68. data/lib/activity_notification/common.rb +18 -7
  69. data/lib/activity_notification/config.rb +176 -30
  70. data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
  71. data/lib/activity_notification/controllers/common_controller.rb +47 -27
  72. data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
  73. data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
  74. data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
  75. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
  76. data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
  77. data/lib/activity_notification/controllers/devise_authentication_controller.rb +22 -5
  78. data/lib/activity_notification/gem_version.rb +14 -0
  79. data/lib/activity_notification/helpers/errors.rb +6 -0
  80. data/lib/activity_notification/helpers/view_helpers.rb +118 -28
  81. data/lib/activity_notification/mailers/helpers.rb +19 -12
  82. data/lib/activity_notification/models/concerns/notifiable.rb +142 -55
  83. data/lib/activity_notification/models/concerns/subscriber.rb +28 -13
  84. data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
  85. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
  86. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
  87. data/lib/activity_notification/models/concerns/target.rb +131 -32
  88. data/lib/activity_notification/models/notification.rb +1 -0
  89. data/lib/activity_notification/models/subscription.rb +1 -0
  90. data/lib/activity_notification/models.rb +23 -1
  91. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
  92. data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
  93. data/lib/activity_notification/optional_targets/base.rb +9 -15
  94. data/lib/activity_notification/orm/active_record/notification.rb +23 -34
  95. data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
  96. data/lib/activity_notification/orm/active_record.rb +1 -1
  97. data/lib/activity_notification/orm/dynamoid/extension.rb +262 -0
  98. data/lib/activity_notification/orm/dynamoid/notification.rb +224 -0
  99. data/lib/activity_notification/orm/dynamoid/subscription.rb +82 -0
  100. data/lib/activity_notification/orm/dynamoid.rb +530 -0
  101. data/lib/activity_notification/orm/mongoid/notification.rb +29 -28
  102. data/lib/activity_notification/orm/mongoid/subscription.rb +3 -3
  103. data/lib/activity_notification/orm/mongoid.rb +33 -1
  104. data/lib/activity_notification/rails/routes.rb +273 -60
  105. data/lib/activity_notification/renderable.rb +22 -7
  106. data/lib/activity_notification/roles/acts_as_notifiable.rb +64 -1
  107. data/lib/activity_notification/roles/acts_as_target.rb +99 -9
  108. data/lib/activity_notification/version.rb +1 -1
  109. data/lib/activity_notification.rb +14 -0
  110. data/lib/generators/activity_notification/controllers_generator.rb +2 -1
  111. data/lib/generators/templates/activity_notification.rb +61 -7
  112. data/lib/generators/templates/controllers/README +2 -2
  113. data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
  114. data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
  115. data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
  116. data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
  117. data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
  118. data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
  119. data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
  120. data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
  121. data/lib/generators/templates/migrations/migration.rb +5 -5
  122. data/lib/generators/templates/models/README +8 -4
  123. data/lib/generators/templates/models/notification.rb +1 -1
  124. data/lib/generators/templates/models/subscription.rb +1 -1
  125. data/lib/tasks/activity_notification_tasks.rake +14 -4
  126. data/package.json +8 -0
  127. data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
  128. data/spec/channels/notification_api_channel_spec.rb +49 -0
  129. data/spec/channels/notification_api_with_devise_channel_spec.rb +76 -0
  130. data/spec/channels/notification_channel_shared_examples.rb +59 -0
  131. data/spec/channels/notification_channel_spec.rb +48 -0
  132. data/spec/channels/notification_with_devise_channel_spec.rb +97 -0
  133. data/spec/concerns/apis/notification_api_spec.rb +177 -12
  134. data/spec/concerns/apis/subscription_api_spec.rb +146 -4
  135. data/spec/concerns/common_spec.rb +25 -3
  136. data/spec/concerns/models/notifiable_spec.rb +161 -11
  137. data/spec/concerns/models/subscriber_spec.rb +253 -79
  138. data/spec/concerns/models/target_spec.rb +180 -47
  139. data/spec/concerns/renderable_spec.rb +35 -16
  140. data/spec/config_spec.rb +52 -1
  141. data/spec/controllers/controller_spec_utility.rb +100 -0
  142. data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
  143. data/spec/controllers/notifications_api_controller_spec.rb +19 -0
  144. data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
  145. data/spec/controllers/notifications_controller_shared_examples.rb +55 -76
  146. data/spec/controllers/notifications_controller_spec.rb +1 -2
  147. data/spec/controllers/notifications_with_devise_controller_spec.rb +14 -8
  148. data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
  149. data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
  150. data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
  151. data/spec/controllers/subscriptions_controller_shared_examples.rb +99 -121
  152. data/spec/controllers/subscriptions_controller_spec.rb +1 -2
  153. data/spec/controllers/subscriptions_with_devise_controller_spec.rb +14 -8
  154. data/spec/factories/notifications.rb +1 -1
  155. data/spec/factories/subscriptions.rb +3 -3
  156. data/spec/factories/users.rb +3 -3
  157. data/spec/generators/migration/migration_generator_spec.rb +29 -4
  158. data/spec/helpers/view_helpers_spec.rb +31 -21
  159. data/spec/jobs/notify_all_job_spec.rb +23 -0
  160. data/spec/jobs/notify_job_spec.rb +23 -0
  161. data/spec/jobs/notify_to_job_spec.rb +23 -0
  162. data/spec/mailers/mailer_spec.rb +42 -1
  163. data/spec/models/dummy/dummy_group_spec.rb +4 -0
  164. data/spec/models/dummy/dummy_notifiable_spec.rb +4 -0
  165. data/spec/models/dummy/dummy_notifier_spec.rb +4 -0
  166. data/spec/models/dummy/dummy_subscriber_spec.rb +3 -0
  167. data/spec/models/dummy/dummy_target_spec.rb +4 -0
  168. data/spec/models/notification_spec.rb +181 -45
  169. data/spec/models/subscription_spec.rb +77 -27
  170. data/spec/optional_targets/action_cable_api_channel_spec.rb +34 -0
  171. data/spec/optional_targets/action_cable_channel_spec.rb +41 -0
  172. data/spec/optional_targets/amazon_sns_spec.rb +0 -2
  173. data/spec/optional_targets/slack_spec.rb +0 -2
  174. data/spec/orm/dynamoid_spec.rb +115 -0
  175. data/spec/rails_app/Rakefile +9 -0
  176. data/spec/rails_app/app/assets/config/manifest.js +3 -0
  177. data/spec/rails_app/app/assets/javascripts/application.js +2 -1
  178. data/spec/rails_app/app/assets/javascripts/cable.js +12 -0
  179. data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
  180. data/spec/rails_app/app/controllers/application_controller.rb +1 -1
  181. data/spec/rails_app/app/controllers/articles_controller.rb +6 -1
  182. data/spec/rails_app/app/controllers/comments_controller.rb +3 -1
  183. data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
  184. data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
  185. data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
  186. data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
  187. data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
  188. data/spec/rails_app/app/controllers/users_controller.rb +26 -0
  189. data/spec/rails_app/app/javascript/App.vue +40 -0
  190. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +82 -0
  191. data/spec/rails_app/app/javascript/components/Top.vue +98 -0
  192. data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
  193. data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
  194. data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
  195. data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
  196. data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
  197. data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
  198. data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
  199. data/spec/rails_app/app/javascript/config/development.js +5 -0
  200. data/spec/rails_app/app/javascript/config/environment.js +7 -0
  201. data/spec/rails_app/app/javascript/config/production.js +5 -0
  202. data/spec/rails_app/app/javascript/config/test.js +5 -0
  203. data/spec/rails_app/app/javascript/packs/application.js +18 -0
  204. data/spec/rails_app/app/javascript/packs/spa.js +14 -0
  205. data/spec/rails_app/app/javascript/router/index.js +73 -0
  206. data/spec/rails_app/app/javascript/store/index.js +37 -0
  207. data/spec/rails_app/app/models/admin.rb +15 -10
  208. data/spec/rails_app/app/models/article.rb +25 -20
  209. data/spec/rails_app/app/models/comment.rb +27 -62
  210. data/spec/rails_app/app/models/dummy/dummy_base.rb +1 -0
  211. data/spec/rails_app/app/models/dummy/dummy_group.rb +9 -0
  212. data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +1 -0
  213. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +27 -0
  214. data/spec/rails_app/app/models/dummy/dummy_notifier.rb +1 -0
  215. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +1 -0
  216. data/spec/rails_app/app/models/dummy/dummy_target.rb +1 -0
  217. data/spec/rails_app/app/models/user.rb +44 -18
  218. data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
  219. data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +1 -0
  220. data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +1 -1
  221. data/spec/rails_app/app/views/articles/index.html.erb +68 -20
  222. data/spec/rails_app/app/views/articles/show.html.erb +1 -1
  223. data/spec/rails_app/app/views/layouts/_header.html.erb +9 -3
  224. data/spec/rails_app/app/views/spa/index.html.erb +2 -0
  225. data/spec/rails_app/babel.config.js +72 -0
  226. data/spec/rails_app/bin/webpack +18 -0
  227. data/spec/rails_app/bin/webpack-dev-server +18 -0
  228. data/spec/rails_app/config/application.rb +26 -6
  229. data/spec/rails_app/config/cable.yml +8 -0
  230. data/spec/rails_app/config/database.yml +1 -1
  231. data/spec/rails_app/config/dynamoid.rb +13 -0
  232. data/spec/rails_app/config/environment.rb +5 -1
  233. data/spec/rails_app/config/environments/development.rb +5 -0
  234. data/spec/rails_app/config/environments/production.rb +7 -1
  235. data/spec/rails_app/config/environments/test.rb +7 -11
  236. data/spec/rails_app/config/initializers/activity_notification.rb +63 -9
  237. data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
  238. data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
  239. data/spec/rails_app/config/initializers/mysql.rb +9 -0
  240. data/spec/rails_app/config/locales/activity_notification.en.yml +10 -4
  241. data/spec/rails_app/config/routes.rb +42 -1
  242. data/spec/rails_app/config/webpack/development.js +5 -0
  243. data/spec/rails_app/config/webpack/environment.js +7 -0
  244. data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
  245. data/spec/rails_app/config/webpack/production.js +5 -0
  246. data/spec/rails_app/config/webpack/test.js +5 -0
  247. data/spec/rails_app/config/webpacker.yml +97 -0
  248. data/spec/rails_app/db/migrate/{20160715050433_create_test_tables.rb → 20160716000000_create_test_tables.rb} +1 -1
  249. data/spec/rails_app/db/migrate/{20160715050420_create_activity_notification_tables.rb → 20181209000000_create_activity_notification_tables.rb} +3 -3
  250. data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
  251. data/spec/rails_app/db/schema.rb +46 -43
  252. data/spec/rails_app/db/seeds.rb +28 -4
  253. data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
  254. data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +14 -4
  255. data/spec/rails_app/package.json +23 -0
  256. data/spec/rails_app/postcss.config.js +12 -0
  257. data/spec/roles/acts_as_group_spec.rb +0 -2
  258. data/spec/roles/acts_as_notifiable_spec.rb +80 -20
  259. data/spec/roles/acts_as_notifier_spec.rb +0 -2
  260. data/spec/roles/acts_as_target_spec.rb +1 -5
  261. data/spec/spec_helper.rb +13 -11
  262. data/spec/version_spec.rb +31 -0
  263. metadata +306 -53
  264. data/.travis.yml +0 -85
  265. data/Gemfile.lock +0 -234
  266. data/gemfiles/Gemfile.rails-4.2 +0 -17
  267. data/gemfiles/Gemfile.rails-4.2.lock +0 -225
  268. data/gemfiles/Gemfile.rails-5.0.lock +0 -234
  269. data/gemfiles/Gemfile.rails-5.1.lock +0 -234
  270. data/spec/rails_app/app/views/activity_notification/notifications/users/overriden/custom/_test.html.erb +0 -1
  271. /data/spec/rails_app/app/{models → assets/images}/.keep +0 -0
@@ -0,0 +1,115 @@
1
+ if ActivityNotification.config.orm == :dynamoid
2
+ describe Dynamoid::Criteria::None do
3
+ let(:none) { ActivityNotification::Notification.none }
4
+
5
+ it "is a Dynamoid::Criteria::None" do
6
+ expect(none).to be_a(Dynamoid::Criteria::None)
7
+ end
8
+
9
+ context "== operator" do
10
+ it "returns true against other None object" do
11
+ expect(none).to eq(ActivityNotification::Notification.none)
12
+ end
13
+
14
+ it "returns false against other objects" do
15
+ expect(none).not_to eq(1)
16
+ end
17
+ end
18
+
19
+ context "records" do
20
+ it "returns empty array" do
21
+ expect(none.records).to eq([])
22
+ end
23
+ end
24
+
25
+ context "all" do
26
+ it "returns empty array" do
27
+ expect(none.all).to eq([])
28
+ end
29
+ end
30
+
31
+ context "count" do
32
+ it "returns 0" do
33
+ expect(none.count).to eq(0)
34
+ end
35
+ end
36
+
37
+ context "delete_all" do
38
+ it "does nothing" do
39
+ expect(none.delete_all).to be_nil
40
+ end
41
+ end
42
+
43
+ context "empty?" do
44
+ it "returns true" do
45
+ expect(none.empty?).to be_truthy
46
+ end
47
+ end
48
+ end
49
+
50
+ describe Dynamoid::Criteria::Chain do
51
+ let(:chain) { ActivityNotification::Notification.scan_index_forward(true) }
52
+
53
+ before do
54
+ ActivityNotification::Notification.delete_all
55
+ end
56
+
57
+ it "is a Dynamoid::Criteria::None" do
58
+ expect(chain).to be_a(Dynamoid::Criteria::Chain)
59
+ end
60
+
61
+ context "none" do
62
+ it "returns Dynamoid::Criteria::None" do
63
+ expect(chain.none).to be_a(Dynamoid::Criteria::None)
64
+ end
65
+ end
66
+
67
+ context "limit" do
68
+ before do
69
+ create(:notification)
70
+ create(:notification)
71
+ end
72
+
73
+ it "returns limited records by record_limit" do
74
+ expect(chain.count).to eq(2)
75
+ expect(chain.limit(1).count).to eq(1)
76
+ end
77
+ end
78
+
79
+ context "exists?" do
80
+ it "returns false when the record does not exist" do
81
+ expect(chain.exists?).to be_falsy
82
+ end
83
+
84
+ it "returns true when the record exists" do
85
+ create(:notification)
86
+ expect(chain.exists?).to be_truthy
87
+ end
88
+ end
89
+
90
+ context "size" do
91
+ it "returns same value as count" do
92
+ expect(chain.count).to eq(0)
93
+ expect(chain.size).to eq(0)
94
+ create(:notification)
95
+ expect(chain.count).to eq(1)
96
+ expect(chain.size).to eq(1)
97
+ end
98
+ end
99
+
100
+ context "update_all" do
101
+ before do
102
+ create(:notification)
103
+ create(:notification)
104
+ end
105
+
106
+ it "updates all records" do
107
+ expect(ActivityNotification::Notification.where(key: "default.default").count).to eq(2)
108
+ expect(ActivityNotification::Notification.where(key: "updated.all").count).to eq(0)
109
+ chain.update_all(key: "updated.all")
110
+ expect(ActivityNotification::Notification.where(key: "default.default").count).to eq(0)
111
+ expect(ActivityNotification::Notification.where(key: "updated.all").count).to eq(2)
112
+ end
113
+ end
114
+ end
115
+ end
@@ -3,4 +3,13 @@
3
3
 
4
4
  require File.expand_path('../config/application', __FILE__)
5
5
 
6
+ # Define dummy module for Webpacker Rake tasks
7
+ require 'devise_token_auth'
8
+ unless defined?(DeviseTokenAuth::Concerns::User)
9
+ module DeviseTokenAuth::Concerns
10
+ module User
11
+ end
12
+ end
13
+ end
14
+
6
15
  Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -1,2 +1,3 @@
1
1
  //= require jquery
2
- //= require jquery_ujs
2
+ //= require jquery_ujs
3
+ //= require_tree .
@@ -0,0 +1,12 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+
7
+ (function() {
8
+ this.App || (this.App = {});
9
+
10
+ App.cable = ActionCable.createConsumer();
11
+
12
+ }).call(this);
@@ -0,0 +1,21 @@
1
+ class AdminsController < ApplicationController
2
+ before_action :set_admin, only: [:show]
3
+
4
+ # GET /admins
5
+ def index
6
+ render json: {
7
+ users: Admin.all.as_json(include: :user, methods: [:printable_target_name, :notification_action_cable_allowed?, :notification_action_cable_with_devise?])
8
+ }
9
+ end
10
+
11
+ # GET /admins/:id
12
+ def show
13
+ render json: @admin.as_json(include: :user, methods: [:printable_target_name, :notification_action_cable_allowed?, :notification_action_cable_with_devise?])
14
+ end
15
+
16
+ private
17
+ # Use callbacks to share common setup or constraints between actions.
18
+ def set_admin
19
+ @admin = Admin.find(params[:id])
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
4
+ protect_from_forgery with: :null_session
5
5
  end
@@ -4,6 +4,10 @@ class ArticlesController < ApplicationController
4
4
 
5
5
  # GET /articles
6
6
  def index
7
+ @exists_notifications_routes = respond_to?('notifications_path')
8
+ @exists_user_notifications_routes = respond_to?('user_notifications_path')
9
+ @exists_admins_notifications_routes = respond_to?('admins_notifications_path')
10
+ @exists_admin_notifications_routes = respond_to?('admin_notifications_path')
7
11
  @articles = Article.all.includes(:user)
8
12
  end
9
13
 
@@ -27,7 +31,7 @@ class ArticlesController < ApplicationController
27
31
  @article.user = current_user
28
32
 
29
33
  if @article.save
30
- @article.notify :users
34
+ @article.notify :users, key: 'article.create'
31
35
  redirect_to @article, notice: 'Article was successfully created.'
32
36
  else
33
37
  render :new
@@ -37,6 +41,7 @@ class ArticlesController < ApplicationController
37
41
  # PATCH/PUT /articles/1
38
42
  def update
39
43
  if @article.update(article_params)
44
+ @article.notify :users, key: 'article.update'
40
45
  redirect_to @article, notice: 'Article was successfully updated.'
41
46
  else
42
47
  render :edit
@@ -7,7 +7,9 @@ class CommentsController < ApplicationController
7
7
  @comment.user = current_user
8
8
 
9
9
  if @comment.save
10
- @comment.notify :users
10
+ @comment.notify_now :users, key: 'comment.create', parameters: { notifier_name: @comment.user.printable_notifier_name, article_title: @comment.article.title }
11
+ # @comment.notify_later :users, key: 'comment.create', parameters: { notifier_name: @comment.user.printable_notifier_name, article_title: @comment.article.title }
12
+ # @comment.notify :users, key: 'comment.create', notify_later: true, parameters: { notifier_name: @comment.user.printable_notifier_name, article_title: @comment.article.title }
11
13
  redirect_to @comment.article, notice: 'Comment was successfully created.'
12
14
  else
13
15
  redirect_to @comment.article
@@ -0,0 +1,7 @@
1
+ class SpaController < ApplicationController
2
+
3
+ # GET /spa
4
+ def index
5
+ end
6
+
7
+ end
@@ -1,67 +1,2 @@
1
1
  class Users::NotificationsController < ActivityNotification::NotificationsController
2
- # GET /:target_type/:target_id/notifications
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/notifications/open_all
8
- # def open_all
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/notifications/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/notifications/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/notifications/:id/open
23
- # def open
24
- # super
25
- # end
26
-
27
- # GET /:target_type/:target_id/notifications/:id/move
28
- # def move
29
- # super
30
- # end
31
-
32
- # No action routing
33
- # This method needs to be public since it is called from view helper
34
- # def target_view_path
35
- # super
36
- # end
37
-
38
- # protected
39
-
40
- # def set_target
41
- # super
42
- # end
43
-
44
- # def set_notification
45
- # super
46
- # end
47
-
48
- # def set_index_options
49
- # super
50
- # end
51
-
52
- # def load_notification_index(options = {})
53
- # super(options)
54
- # end
55
-
56
- # def controller_path
57
- # super
58
- # end
59
-
60
- # def set_view_prefixes
61
- # super
62
- # end
63
-
64
- # def return_back_or_ajax
65
- # super
66
- # end
67
2
  end
@@ -1,75 +1,2 @@
1
1
  class Users::NotificationsWithDeviseController < ActivityNotification::NotificationsWithDeviseController
2
- # GET /:target_type/:target_id/notifications
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/notifications/open_all
8
- # def open_all
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/notifications/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/notifications/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/notifications/:id/open
23
- # def open
24
- # super
25
- # end
26
-
27
- # GET /:target_type/:target_id/notifications/:id/move
28
- # def move
29
- # super
30
- # end
31
-
32
- # No action routing
33
- # This method needs to be public since it is called from view helper
34
- # def target_view_path
35
- # super
36
- # end
37
-
38
- # protected
39
-
40
- # def set_target
41
- # super
42
- # end
43
-
44
- # def set_notification
45
- # super
46
- # end
47
-
48
- # def set_index_options
49
- # super
50
- # end
51
-
52
- # def load_notification_index(options = {})
53
- # super(options)
54
- # end
55
-
56
- # def controller_path
57
- # super
58
- # end
59
-
60
- # def set_view_prefixes
61
- # super
62
- # end
63
-
64
- # def return_back_or_ajax
65
- # super
66
- # end
67
-
68
- # def authenticate_devise_resource!
69
- # super
70
- # end
71
-
72
- # def authenticate_target!
73
- # super
74
- # end
75
2
  end
@@ -1,79 +1,2 @@
1
1
  class Users::SubscriptionsController < ActivityNotification::SubscriptionsController
2
- # GET /:target_type/:target_id/subscriptions
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/subscriptions
8
- # def create
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/subscriptions/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/subscriptions/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/subscriptions/:id/subscribe
23
- # def subscribe
24
- # super
25
- # end
26
-
27
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe
28
- # def unsubscribe
29
- # super
30
- # end
31
-
32
- # POST /:target_type/:target_id/subscriptions/:id/subscribe_to_email
33
- # def subscribe_to_email
34
- # super
35
- # end
36
-
37
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe_to_email
38
- # def unsubscribe_to_email
39
- # super
40
- # end
41
-
42
- # protected
43
-
44
- # def set_target
45
- # super
46
- # end
47
-
48
- # def set_subscription
49
- # super
50
- # end
51
-
52
- # def subscription_params
53
- # super
54
- # end
55
-
56
- # def set_index_options
57
- # super
58
- # end
59
-
60
- # def load_subscription_index(options = {})
61
- # super(options)
62
- # end
63
-
64
- # def controller_path
65
- # super
66
- # end
67
-
68
- # def target_view_path
69
- # super
70
- # end
71
-
72
- # def set_view_prefixes
73
- # super
74
- # end
75
-
76
- # def return_back_or_ajax
77
- # super
78
- # end
79
2
  end
@@ -1,87 +1,2 @@
1
1
  class Users::SubscriptionsWithDeviseController < ActivityNotification::SubscriptionsWithDeviseController
2
- # GET /:target_type/:target_id/subscriptions
3
- # def index
4
- # super
5
- # end
6
-
7
- # POST /:target_type/:target_id/subscriptions
8
- # def create
9
- # super
10
- # end
11
-
12
- # GET /:target_type/:target_id/subscriptions/:id
13
- # def show
14
- # super
15
- # end
16
-
17
- # DELETE /:target_type/:target_id/subscriptions/:id
18
- # def destroy
19
- # super
20
- # end
21
-
22
- # POST /:target_type/:target_id/subscriptions/:id/subscribe
23
- # def subscribe
24
- # super
25
- # end
26
-
27
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe
28
- # def unsubscribe
29
- # super
30
- # end
31
-
32
- # POST /:target_type/:target_id/subscriptions/:id/subscribe_to_email
33
- # def subscribe_to_email
34
- # super
35
- # end
36
-
37
- # POST /:target_type/:target_id/subscriptions/:id/unsubscribe_to_email
38
- # def unsubscribe_to_email
39
- # super
40
- # end
41
-
42
- # protected
43
-
44
- # def set_target
45
- # super
46
- # end
47
-
48
- # def set_subscription
49
- # super
50
- # end
51
-
52
- # def subscription_params
53
- # super
54
- # end
55
-
56
- # def set_index_options
57
- # super
58
- # end
59
-
60
- # def load_subscription_index(options = {})
61
- # super(options)
62
- # end
63
-
64
- # def controller_path
65
- # super
66
- # end
67
-
68
- # def target_view_path
69
- # super
70
- # end
71
-
72
- # def set_view_prefixes
73
- # super
74
- # end
75
-
76
- # def return_back_or_ajax
77
- # super
78
- # end
79
-
80
- # def authenticate_devise_resource!
81
- # super
82
- # end
83
-
84
- # def authenticate_target!
85
- # super
86
- # end
87
2
  end
@@ -0,0 +1,26 @@
1
+ class UsersController < ApplicationController
2
+ before_action :set_user, only: [:show]
3
+
4
+ # GET /users
5
+ def index
6
+ render json: {
7
+ users: User.all
8
+ }
9
+ end
10
+
11
+ # GET /users/:id
12
+ def show
13
+ render json: @user
14
+ end
15
+
16
+ # GET /users/find
17
+ def find
18
+ render json: User.find_by_email!(params[:email])
19
+ end
20
+
21
+ private
22
+ # Use callbacks to share common setup or constraints between actions.
23
+ def set_user
24
+ @user = User.find(params[:id])
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <div>
3
+ <router-view />
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ import Vue from 'vue'
9
+ import VueMoment from 'vue-moment'
10
+ import moment from 'moment-timezone'
11
+ import VuePluralize from 'vue-pluralize'
12
+ import ActionCableVue from 'actioncable-vue'
13
+ import axios from 'axios'
14
+ import env from './config/environment'
15
+
16
+ axios.defaults.baseURL = "/api/v2"
17
+
18
+ Vue.use(VueMoment, { moment })
19
+ Vue.use(VuePluralize)
20
+ Vue.use(ActionCableVue, {
21
+ debug: true,
22
+ debugLevel: 'error',
23
+ connectionUrl: env.ACTION_CABLE_CONNECTION_URL,
24
+ connectImmediately: true
25
+ })
26
+
27
+ export default {
28
+ name: 'App',
29
+ mounted () {
30
+ if (this.$store.getters.userSignedIn) {
31
+ for (var authHeader of Object.keys(this.$store.getters.authHeaders)) {
32
+ axios.defaults.headers.common[authHeader] = this.$store.getters.authHeaders[authHeader];
33
+ }
34
+ }
35
+ }
36
+ }
37
+ </script>
38
+
39
+ <style scoped>
40
+ </style>
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <div id="login">
3
+ <h2>Log in</h2>
4
+ <form class="new_user" @submit.prevent="login">
5
+ <div class="field">
6
+ <label for="user_email">Email</label><br />
7
+ <input v-model="loginParams.email" autofocus="autofocus" autocomplete="email" type="email" value="" name="user[email]" id="user_email" />
8
+ </div>
9
+ <div class="field">
10
+ <label for="user_password">Password</label><br />
11
+ <input v-model="loginParams.password" autocomplete="current-password" type="password" name="user[password]" id="user_password" />
12
+ </div>
13
+ <div class="actions">
14
+ <input type="submit" name="commit" value="Log in" data-disable-with="Log in" />
15
+ </div>
16
+ </form>
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ import axios from 'axios'
22
+
23
+ export default {
24
+ name: 'DeviseTokenAuth',
25
+ props: {
26
+ isLogout: {
27
+ type: Boolean,
28
+ default: false
29
+ }
30
+ },
31
+ data () {
32
+ return {
33
+ loginParams: {
34
+ email: "",
35
+ password: ""
36
+ }
37
+ }
38
+ },
39
+ mounted () {
40
+ if (this.isLogout) {
41
+ this.logout();
42
+ }
43
+ },
44
+ methods: {
45
+ login () {
46
+ axios
47
+ .post('/auth/sign_in', { email: this.loginParams.email, password: this.loginParams.password })
48
+ .then(response => {
49
+ if (response.status == 200) {
50
+ let authHeaders = {};
51
+ for (let authHeader of ['access-token', 'client', 'uid']) {
52
+ authHeaders[authHeader] = response.headers[authHeader];
53
+ axios.defaults.headers.common[authHeader] = authHeaders[authHeader];
54
+ }
55
+ this.$store.commit('signIn', { user: response.data.data, authHeaders: authHeaders });
56
+ if (this.$route.query.redirect) {
57
+ this.$router.push(this.$route.query.redirect);
58
+ } else {
59
+ this.$router.push('/');
60
+ }
61
+ }
62
+ })
63
+ .catch (error => {
64
+ console.log("Authentication failed");
65
+ if (error.response.status == 401) {
66
+ this.$router.go({path: this.$router.currentRoute.path});
67
+ }
68
+ })
69
+ },
70
+ logout () {
71
+ for (var authHeader of Object.keys(this.$store.getters.authHeaders)) {
72
+ delete axios.defaults.headers.common[authHeader];
73
+ }
74
+ this.$store.commit('signOut');
75
+ this.$router.push('/');
76
+ }
77
+ }
78
+ }
79
+ </script>
80
+
81
+ <style scoped>
82
+ </style>