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.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.github/pull_request_template.md +13 -0
- data/.github/workflows/build.yml +116 -0
- data/.gitignore +15 -3
- data/CHANGELOG.md +200 -1
- data/Gemfile +17 -2
- data/Procfile +2 -0
- data/README.md +168 -1033
- data/Rakefile +19 -10
- data/activity_notification.gemspec +14 -9
- data/app/channels/activity_notification/notification_api_channel.rb +12 -0
- data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
- data/app/channels/activity_notification/notification_channel.rb +37 -0
- data/app/channels/activity_notification/notification_with_devise_channel.rb +51 -0
- data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
- data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
- data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/notifications_controller.rb +60 -54
- data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
- data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/subscriptions_controller.rb +83 -73
- data/app/jobs/activity_notification/notify_all_job.rb +25 -0
- data/app/jobs/activity_notification/notify_job.rb +26 -0
- data/app/jobs/activity_notification/notify_to_job.rb +25 -0
- data/app/views/activity_notification/notifications/default/_default.html.erb +23 -23
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +19 -19
- data/app/views/activity_notification/notifications/default/_index.html.erb +3 -3
- data/app/views/activity_notification/notifications/default/index.html.erb +60 -7
- data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
- data/app/views/activity_notification/notifications/default/show.html.erb +2 -2
- data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
- data/app/views/activity_notification/optional_targets/default/base/_default.text.erb +1 -1
- data/app/views/activity_notification/optional_targets/default/slack/_default.text.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +5 -33
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +8 -8
- data/app/views/activity_notification/subscriptions/default/index.html.erb +13 -9
- data/app/views/activity_notification/subscriptions/default/show.html.erb +3 -3
- data/app/views/activity_notification/subscriptions/default/subscribe.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/subscribe_to_email.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/subscribe_to_optional_target.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_email.js.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/unsubscribe_to_optional_target.js.erb +1 -1
- data/bin/_dynamodblocal +4 -0
- data/bin/bundle_update.sh +7 -0
- data/bin/deploy_on_heroku.sh +16 -0
- data/bin/install_dynamodblocal.sh +5 -0
- data/bin/start_dynamodblocal.sh +47 -0
- data/bin/stop_dynamodblocal.sh +34 -0
- data/docs/CODE_OF_CONDUCT.md +76 -0
- data/docs/CONTRIBUTING.md +36 -0
- data/docs/Functions.md +1146 -0
- data/docs/Setup.md +817 -0
- data/docs/Testing.md +148 -0
- data/gemfiles/Gemfile.rails-5.0 +8 -1
- data/gemfiles/Gemfile.rails-5.1 +7 -1
- data/gemfiles/Gemfile.rails-5.2 +24 -0
- data/gemfiles/Gemfile.rails-6.0 +23 -0
- data/gemfiles/Gemfile.rails-6.1 +22 -0
- data/gemfiles/Gemfile.rails-7.0 +25 -0
- data/lib/activity_notification/apis/notification_api.rb +356 -159
- data/lib/activity_notification/apis/subscription_api.rb +98 -59
- data/lib/activity_notification/apis/swagger.rb +6 -0
- data/lib/activity_notification/common.rb +18 -7
- data/lib/activity_notification/config.rb +176 -30
- data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
- data/lib/activity_notification/controllers/common_controller.rb +47 -27
- data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +22 -5
- data/lib/activity_notification/gem_version.rb +14 -0
- data/lib/activity_notification/helpers/errors.rb +6 -0
- data/lib/activity_notification/helpers/view_helpers.rb +118 -28
- data/lib/activity_notification/mailers/helpers.rb +19 -12
- data/lib/activity_notification/models/concerns/notifiable.rb +142 -55
- data/lib/activity_notification/models/concerns/subscriber.rb +28 -13
- data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
- data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
- data/lib/activity_notification/models/concerns/target.rb +131 -32
- data/lib/activity_notification/models/notification.rb +1 -0
- data/lib/activity_notification/models/subscription.rb +1 -0
- data/lib/activity_notification/models.rb +23 -1
- data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
- data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
- data/lib/activity_notification/optional_targets/base.rb +9 -15
- data/lib/activity_notification/orm/active_record/notification.rb +23 -34
- data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/extension.rb +262 -0
- data/lib/activity_notification/orm/dynamoid/notification.rb +224 -0
- data/lib/activity_notification/orm/dynamoid/subscription.rb +82 -0
- data/lib/activity_notification/orm/dynamoid.rb +530 -0
- data/lib/activity_notification/orm/mongoid/notification.rb +29 -28
- data/lib/activity_notification/orm/mongoid/subscription.rb +3 -3
- data/lib/activity_notification/orm/mongoid.rb +33 -1
- data/lib/activity_notification/rails/routes.rb +273 -60
- data/lib/activity_notification/renderable.rb +22 -7
- data/lib/activity_notification/roles/acts_as_notifiable.rb +64 -1
- data/lib/activity_notification/roles/acts_as_target.rb +99 -9
- data/lib/activity_notification/version.rb +1 -1
- data/lib/activity_notification.rb +14 -0
- data/lib/generators/activity_notification/controllers_generator.rb +2 -1
- data/lib/generators/templates/activity_notification.rb +61 -7
- data/lib/generators/templates/controllers/README +2 -2
- data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
- data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
- data/lib/generators/templates/migrations/migration.rb +5 -5
- data/lib/generators/templates/models/README +8 -4
- data/lib/generators/templates/models/notification.rb +1 -1
- data/lib/generators/templates/models/subscription.rb +1 -1
- data/lib/tasks/activity_notification_tasks.rake +14 -4
- data/package.json +8 -0
- data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_api_channel_spec.rb +49 -0
- data/spec/channels/notification_api_with_devise_channel_spec.rb +76 -0
- data/spec/channels/notification_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_channel_spec.rb +48 -0
- data/spec/channels/notification_with_devise_channel_spec.rb +97 -0
- data/spec/concerns/apis/notification_api_spec.rb +177 -12
- data/spec/concerns/apis/subscription_api_spec.rb +146 -4
- data/spec/concerns/common_spec.rb +25 -3
- data/spec/concerns/models/notifiable_spec.rb +161 -11
- data/spec/concerns/models/subscriber_spec.rb +253 -79
- data/spec/concerns/models/target_spec.rb +180 -47
- data/spec/concerns/renderable_spec.rb +35 -16
- data/spec/config_spec.rb +52 -1
- data/spec/controllers/controller_spec_utility.rb +100 -0
- data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
- data/spec/controllers/notifications_api_controller_spec.rb +19 -0
- data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +55 -76
- data/spec/controllers/notifications_controller_spec.rb +1 -2
- data/spec/controllers/notifications_with_devise_controller_spec.rb +14 -8
- data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
- data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
- data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/subscriptions_controller_shared_examples.rb +99 -121
- data/spec/controllers/subscriptions_controller_spec.rb +1 -2
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +14 -8
- data/spec/factories/notifications.rb +1 -1
- data/spec/factories/subscriptions.rb +3 -3
- data/spec/factories/users.rb +3 -3
- data/spec/generators/migration/migration_generator_spec.rb +29 -4
- data/spec/helpers/view_helpers_spec.rb +31 -21
- data/spec/jobs/notify_all_job_spec.rb +23 -0
- data/spec/jobs/notify_job_spec.rb +23 -0
- data/spec/jobs/notify_to_job_spec.rb +23 -0
- data/spec/mailers/mailer_spec.rb +42 -1
- data/spec/models/dummy/dummy_group_spec.rb +4 -0
- data/spec/models/dummy/dummy_notifiable_spec.rb +4 -0
- data/spec/models/dummy/dummy_notifier_spec.rb +4 -0
- data/spec/models/dummy/dummy_subscriber_spec.rb +3 -0
- data/spec/models/dummy/dummy_target_spec.rb +4 -0
- data/spec/models/notification_spec.rb +181 -45
- data/spec/models/subscription_spec.rb +77 -27
- data/spec/optional_targets/action_cable_api_channel_spec.rb +34 -0
- data/spec/optional_targets/action_cable_channel_spec.rb +41 -0
- data/spec/optional_targets/amazon_sns_spec.rb +0 -2
- data/spec/optional_targets/slack_spec.rb +0 -2
- data/spec/orm/dynamoid_spec.rb +115 -0
- data/spec/rails_app/Rakefile +9 -0
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/javascripts/application.js +2 -1
- data/spec/rails_app/app/assets/javascripts/cable.js +12 -0
- data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
- data/spec/rails_app/app/controllers/application_controller.rb +1 -1
- data/spec/rails_app/app/controllers/articles_controller.rb +6 -1
- data/spec/rails_app/app/controllers/comments_controller.rb +3 -1
- data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
- data/spec/rails_app/app/controllers/users_controller.rb +26 -0
- data/spec/rails_app/app/javascript/App.vue +40 -0
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +82 -0
- data/spec/rails_app/app/javascript/components/Top.vue +98 -0
- data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
- data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
- data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
- data/spec/rails_app/app/javascript/config/development.js +5 -0
- data/spec/rails_app/app/javascript/config/environment.js +7 -0
- data/spec/rails_app/app/javascript/config/production.js +5 -0
- data/spec/rails_app/app/javascript/config/test.js +5 -0
- data/spec/rails_app/app/javascript/packs/application.js +18 -0
- data/spec/rails_app/app/javascript/packs/spa.js +14 -0
- data/spec/rails_app/app/javascript/router/index.js +73 -0
- data/spec/rails_app/app/javascript/store/index.js +37 -0
- data/spec/rails_app/app/models/admin.rb +15 -10
- data/spec/rails_app/app/models/article.rb +25 -20
- data/spec/rails_app/app/models/comment.rb +27 -62
- data/spec/rails_app/app/models/dummy/dummy_base.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_group.rb +9 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +27 -0
- data/spec/rails_app/app/models/dummy/dummy_notifier.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_target.rb +1 -0
- data/spec/rails_app/app/models/user.rb +44 -18
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
- data/spec/rails_app/app/views/activity_notification/notifications/users/overridden/custom/_test.html.erb +1 -0
- data/spec/rails_app/app/views/activity_notification/optional_targets/admins/amazon_sns/comment/_default.text.erb +1 -1
- data/spec/rails_app/app/views/articles/index.html.erb +68 -20
- data/spec/rails_app/app/views/articles/show.html.erb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +9 -3
- data/spec/rails_app/app/views/spa/index.html.erb +2 -0
- data/spec/rails_app/babel.config.js +72 -0
- data/spec/rails_app/bin/webpack +18 -0
- data/spec/rails_app/bin/webpack-dev-server +18 -0
- data/spec/rails_app/config/application.rb +26 -6
- data/spec/rails_app/config/cable.yml +8 -0
- data/spec/rails_app/config/database.yml +1 -1
- data/spec/rails_app/config/dynamoid.rb +13 -0
- data/spec/rails_app/config/environment.rb +5 -1
- data/spec/rails_app/config/environments/development.rb +5 -0
- data/spec/rails_app/config/environments/production.rb +7 -1
- data/spec/rails_app/config/environments/test.rb +7 -11
- data/spec/rails_app/config/initializers/activity_notification.rb +63 -9
- data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
- data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
- data/spec/rails_app/config/initializers/mysql.rb +9 -0
- data/spec/rails_app/config/locales/activity_notification.en.yml +10 -4
- data/spec/rails_app/config/routes.rb +42 -1
- data/spec/rails_app/config/webpack/development.js +5 -0
- data/spec/rails_app/config/webpack/environment.js +7 -0
- data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
- data/spec/rails_app/config/webpack/production.js +5 -0
- data/spec/rails_app/config/webpack/test.js +5 -0
- data/spec/rails_app/config/webpacker.yml +97 -0
- data/spec/rails_app/db/migrate/{20160715050433_create_test_tables.rb → 20160716000000_create_test_tables.rb} +1 -1
- data/spec/rails_app/db/migrate/{20160715050420_create_activity_notification_tables.rb → 20181209000000_create_activity_notification_tables.rb} +3 -3
- data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
- data/spec/rails_app/db/schema.rb +46 -43
- data/spec/rails_app/db/seeds.rb +28 -4
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
- data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +14 -4
- data/spec/rails_app/package.json +23 -0
- data/spec/rails_app/postcss.config.js +12 -0
- data/spec/roles/acts_as_group_spec.rb +0 -2
- data/spec/roles/acts_as_notifiable_spec.rb +80 -20
- data/spec/roles/acts_as_notifier_spec.rb +0 -2
- data/spec/roles/acts_as_target_spec.rb +1 -5
- data/spec/spec_helper.rb +13 -11
- data/spec/version_spec.rb +31 -0
- metadata +306 -53
- data/.travis.yml +0 -85
- data/Gemfile.lock +0 -234
- data/gemfiles/Gemfile.rails-4.2 +0 -17
- data/gemfiles/Gemfile.rails-4.2.lock +0 -225
- data/gemfiles/Gemfile.rails-5.0.lock +0 -234
- data/gemfiles/Gemfile.rails-5.1.lock +0 -234
- data/spec/rails_app/app/views/activity_notification/notifications/users/overriden/custom/_test.html.erb +0 -1
- /data/spec/rails_app/app/{models → assets/images}/.keep +0 -0
|
@@ -4,55 +4,77 @@ module ActivityNotification
|
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
6
|
included do
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
filtered_subscriptions =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
# :nocov:
|
|
8
|
+
unless ActivityNotification.config.orm == :dynamoid
|
|
9
|
+
# Selects filtered subscriptions by key.
|
|
10
|
+
# @example Get filtered subscriptions of the @user with key 'comment.reply'
|
|
11
|
+
# @subscriptions = @user.subscriptions.filtered_by_key('comment.reply')
|
|
12
|
+
# @scope class
|
|
13
|
+
# @param [String] key Key of the subscription for filter
|
|
14
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of filtered subscriptions
|
|
15
|
+
scope :filtered_by_key, ->(key) { where(key: key) }
|
|
16
|
+
|
|
17
|
+
# Selects filtered subscriptions by key with filter options.
|
|
18
|
+
# @example Get filtered subscriptions of the @user with key 'comment.reply'
|
|
19
|
+
# @subscriptions = @user.subscriptions.filtered_by_key('comment.reply')
|
|
20
|
+
# @example Get custom filtered subscriptions of the @user
|
|
21
|
+
# @subscriptions = @user.subscriptions.filtered_by_options({ custom_filter: ["created_at >= ?", time.hour.ago] })
|
|
22
|
+
# @scope class
|
|
23
|
+
# @param [Hash] options Options for filter
|
|
24
|
+
# @option options [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
25
|
+
# @option options [Array|Hash] :custom_filter (nil) Custom subscription filter (e.g. ["created_at >= ?", time.hour.ago] or ['created_at.gt': time.hour.ago])
|
|
26
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of filtered subscriptions
|
|
27
|
+
scope :filtered_by_options, ->(options = {}) {
|
|
28
|
+
options = ActivityNotification.cast_to_indifferent_hash(options)
|
|
29
|
+
filtered_subscriptions = all
|
|
30
|
+
if options.has_key?(:filtered_by_key)
|
|
31
|
+
filtered_subscriptions = filtered_subscriptions.filtered_by_key(options[:filtered_by_key])
|
|
32
|
+
end
|
|
33
|
+
if options.has_key?(:custom_filter)
|
|
34
|
+
filtered_subscriptions = filtered_subscriptions.where(options[:custom_filter])
|
|
35
|
+
end
|
|
36
|
+
filtered_subscriptions
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Orders by latest (newest) first as created_at: :desc.
|
|
40
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by latest first
|
|
41
|
+
scope :latest_order, -> { order(created_at: :desc) }
|
|
42
|
+
|
|
43
|
+
# Orders by earliest (older) first as created_at: :asc.
|
|
44
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by earliest first
|
|
45
|
+
scope :earliest_order, -> { order(created_at: :asc) }
|
|
46
|
+
|
|
47
|
+
# Orders by latest (newest) first as created_at: :desc.
|
|
48
|
+
# This method is to be overridden in implementation for each ORM.
|
|
49
|
+
# @param [Boolean] reverse If subscriptions will be ordered as earliest first
|
|
50
|
+
# @return [ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>] Database query of ordered subscriptions
|
|
51
|
+
scope :latest_order!, ->(reverse = false) { reverse ? earliest_order : latest_order }
|
|
52
|
+
|
|
53
|
+
# Orders by earliest (older) first as created_at: :asc.
|
|
54
|
+
# This method is to be overridden in implementation for each ORM.
|
|
55
|
+
# @return [ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by earliest first
|
|
56
|
+
scope :earliest_order!, -> { earliest_order }
|
|
57
|
+
|
|
58
|
+
# Orders by latest (newest) first as subscribed_at: :desc.
|
|
59
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by latest subscribed_at first
|
|
60
|
+
scope :latest_subscribed_order, -> { order(subscribed_at: :desc) }
|
|
61
|
+
|
|
62
|
+
# Orders by earliest (older) first as subscribed_at: :asc.
|
|
63
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by earliest subscribed_at first
|
|
64
|
+
scope :earliest_subscribed_order, -> { order(subscribed_at: :asc) }
|
|
65
|
+
|
|
66
|
+
# Orders by key name as key: :asc.
|
|
67
|
+
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by key name
|
|
68
|
+
scope :key_order, -> { order(key: :asc) }
|
|
69
|
+
|
|
70
|
+
# Convert Time value to store in database as Hash value.
|
|
71
|
+
# @param [Time] time Time value to store in database as Hash value
|
|
72
|
+
# @return [Time, Object] Converted Time value
|
|
73
|
+
def self.convert_time_as_hash(time)
|
|
74
|
+
time
|
|
33
75
|
end
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# Orders by latest (newest) first as created_at: :desc.
|
|
38
|
-
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by latest first
|
|
39
|
-
scope :latest_order, -> { order(created_at: :desc) }
|
|
40
|
-
|
|
41
|
-
# Orders by earliest (older) first as created_at: :asc.
|
|
42
|
-
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by earliest first
|
|
43
|
-
scope :earliest_order, -> { order(created_at: :asc) }
|
|
44
|
-
|
|
45
|
-
# Orders by latest (newest) first as subscribed_at: :desc.
|
|
46
|
-
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by latest subscribed_at first
|
|
47
|
-
scope :latest_subscribed_order, -> { order(subscribed_at: :desc) }
|
|
48
|
-
|
|
49
|
-
# Orders by earliest (older) first as subscribed_at: :asc.
|
|
50
|
-
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by earliest subscribed_at first
|
|
51
|
-
scope :earliest_subscribed_order, -> { order(subscribed_at: :asc) }
|
|
52
|
-
|
|
53
|
-
# Orders by key name as key: :asc.
|
|
54
|
-
# @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of subscriptions ordered by key name
|
|
55
|
-
scope :key_order, -> { order(key: :asc) }
|
|
76
|
+
end
|
|
77
|
+
# :nocov:
|
|
56
78
|
end
|
|
57
79
|
|
|
58
80
|
class_methods do
|
|
@@ -78,6 +100,24 @@ module ActivityNotification
|
|
|
78
100
|
end
|
|
79
101
|
end
|
|
80
102
|
|
|
103
|
+
# Override as_json method for optional_targets representation
|
|
104
|
+
#
|
|
105
|
+
# @param [Hash] options Options for as_json method
|
|
106
|
+
# @return [Hash] Hash representing the subscription model
|
|
107
|
+
def as_json(options = {})
|
|
108
|
+
json = super(options).with_indifferent_access
|
|
109
|
+
optional_targets_json = {}
|
|
110
|
+
optional_target_names.each do |optional_target_name|
|
|
111
|
+
optional_targets_json[optional_target_name] = {
|
|
112
|
+
subscribing: json[:optional_targets][Subscription.to_optional_target_key(optional_target_name)],
|
|
113
|
+
subscribed_at: json[:optional_targets][Subscription.to_optional_target_subscribed_at_key(optional_target_name)],
|
|
114
|
+
unsubscribed_at: json[:optional_targets][Subscription.to_optional_target_unsubscribed_at_key(optional_target_name)]
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
json[:optional_targets] = optional_targets_json
|
|
118
|
+
json
|
|
119
|
+
end
|
|
120
|
+
|
|
81
121
|
# Subscribes to the notification and notification email.
|
|
82
122
|
#
|
|
83
123
|
# @param [Hash] options Options for subscribing to the notification
|
|
@@ -87,15 +127,15 @@ module ActivityNotification
|
|
|
87
127
|
# @return [Boolean] If successfully updated subscription instance
|
|
88
128
|
def subscribe(options = {})
|
|
89
129
|
subscribed_at = options[:subscribed_at] || Time.current
|
|
90
|
-
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] :
|
|
91
|
-
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] :
|
|
130
|
+
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : ActivityNotification.config.subscribe_to_email_as_default
|
|
131
|
+
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : ActivityNotification.config.subscribe_to_optional_targets_as_default
|
|
92
132
|
new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
|
|
93
133
|
new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
|
|
94
134
|
if with_optional_targets
|
|
95
135
|
optional_target_names.each do |optional_target_name|
|
|
96
136
|
new_attributes[:optional_targets] = new_attributes[:optional_targets].merge(
|
|
97
137
|
Subscription.to_optional_target_key(optional_target_name) => true,
|
|
98
|
-
Subscription.to_optional_target_subscribed_at_key(optional_target_name) => subscribed_at)
|
|
138
|
+
Subscription.to_optional_target_subscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(subscribed_at))
|
|
99
139
|
end
|
|
100
140
|
end
|
|
101
141
|
update(new_attributes)
|
|
@@ -114,7 +154,7 @@ module ActivityNotification
|
|
|
114
154
|
optional_target_names.each do |optional_target_name|
|
|
115
155
|
new_attributes[:optional_targets] = new_attributes[:optional_targets].merge(
|
|
116
156
|
Subscription.to_optional_target_key(optional_target_name) => false,
|
|
117
|
-
Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => subscribed_at)
|
|
157
|
+
Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(subscribed_at))
|
|
118
158
|
end
|
|
119
159
|
update(new_attributes)
|
|
120
160
|
end
|
|
@@ -144,7 +184,7 @@ module ActivityNotification
|
|
|
144
184
|
# @param [Symbol] optional_target_name Symbol class name of the optional target implementation (e.g. :amazon_sns, :slack)
|
|
145
185
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
146
186
|
# @return [Boolean] If the target subscribes to the specified optional target
|
|
147
|
-
def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.
|
|
187
|
+
def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
|
|
148
188
|
optional_target_key = Subscription.to_optional_target_key(optional_target_name)
|
|
149
189
|
subscribe_as_default ?
|
|
150
190
|
!optional_targets.has_key?(optional_target_key) || optional_targets[optional_target_key] :
|
|
@@ -161,7 +201,7 @@ module ActivityNotification
|
|
|
161
201
|
subscribed_at = options[:subscribed_at] || Time.current
|
|
162
202
|
update(optional_targets: optional_targets.merge(
|
|
163
203
|
Subscription.to_optional_target_key(optional_target_name) => true,
|
|
164
|
-
Subscription.to_optional_target_subscribed_at_key(optional_target_name) => subscribed_at)
|
|
204
|
+
Subscription.to_optional_target_subscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(subscribed_at))
|
|
165
205
|
)
|
|
166
206
|
end
|
|
167
207
|
|
|
@@ -175,7 +215,7 @@ module ActivityNotification
|
|
|
175
215
|
unsubscribed_at = options[:unsubscribed_at] || Time.current
|
|
176
216
|
update(optional_targets: optional_targets.merge(
|
|
177
217
|
Subscription.to_optional_target_key(optional_target_name) => false,
|
|
178
|
-
Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => unsubscribed_at)
|
|
218
|
+
Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(unsubscribed_at))
|
|
179
219
|
)
|
|
180
220
|
end
|
|
181
221
|
|
|
@@ -185,17 +225,16 @@ module ActivityNotification
|
|
|
185
225
|
optional_targets.keys.select { |key| key.to_s.start_with?("subscribing_to_") }.map { |key| key.slice(15..-1) }
|
|
186
226
|
end
|
|
187
227
|
|
|
188
|
-
|
|
189
228
|
protected
|
|
190
229
|
|
|
191
|
-
# Validates subscribing_to_email cannot be true when subscribing
|
|
230
|
+
# Validates subscribing_to_email cannot be true when subscribing is false.
|
|
192
231
|
def subscribing_to_email_cannot_be_true_when_subscribing_is_false
|
|
193
232
|
if !subscribing && subscribing_to_email?
|
|
194
233
|
errors.add(:subscribing_to_email, "cannot be true when subscribing is false")
|
|
195
234
|
end
|
|
196
235
|
end
|
|
197
236
|
|
|
198
|
-
# Validates subscribing_to_optional_target cannot be true when subscribing
|
|
237
|
+
# Validates subscribing_to_optional_target cannot be true when subscribing is false.
|
|
199
238
|
def subscribing_to_optional_target_cannot_be_true_when_subscribing_is_false
|
|
200
239
|
optional_target_names.each do |optional_target_name|
|
|
201
240
|
if !subscribing && subscribing_to_optional_target?(optional_target_name)
|
|
@@ -205,4 +244,4 @@ module ActivityNotification
|
|
|
205
244
|
end
|
|
206
245
|
|
|
207
246
|
end
|
|
208
|
-
end
|
|
247
|
+
end
|
|
@@ -16,7 +16,11 @@ module ActivityNotification
|
|
|
16
16
|
when Symbol
|
|
17
17
|
symbol_method = context.method(thing)
|
|
18
18
|
if symbol_method.arity > 1
|
|
19
|
-
|
|
19
|
+
if args.last.kind_of?(Hash)
|
|
20
|
+
symbol_method.call(ActivityNotification.get_controller, *args[0...-1], **args[-1])
|
|
21
|
+
else
|
|
22
|
+
symbol_method.call(ActivityNotification.get_controller, *args)
|
|
23
|
+
end
|
|
20
24
|
elsif symbol_method.arity > 0
|
|
21
25
|
symbol_method.call(ActivityNotification.get_controller)
|
|
22
26
|
else
|
|
@@ -74,7 +78,11 @@ module ActivityNotification
|
|
|
74
78
|
when Symbol
|
|
75
79
|
symbol_method = method(thing)
|
|
76
80
|
if symbol_method.arity > 0
|
|
77
|
-
|
|
81
|
+
if args.last.kind_of?(Hash)
|
|
82
|
+
symbol_method.call(*args[0...-1], **args[-1])
|
|
83
|
+
else
|
|
84
|
+
symbol_method.call(*args)
|
|
85
|
+
end
|
|
78
86
|
else
|
|
79
87
|
symbol_method.call
|
|
80
88
|
end
|
|
@@ -98,28 +106,31 @@ module ActivityNotification
|
|
|
98
106
|
end
|
|
99
107
|
|
|
100
108
|
# Convets to class name.
|
|
109
|
+
# This function returns base_class name for STI models if the class responds to base_class method.
|
|
110
|
+
# @see https://github.com/simukappu/activity_notification/issues/89
|
|
111
|
+
# @see https://github.com/simukappu/activity_notification/pull/139
|
|
101
112
|
# @return [String] Class name
|
|
102
113
|
def to_class_name
|
|
103
|
-
self.class.name
|
|
114
|
+
self.class.respond_to?(:base_class) ? self.class.base_class.name : self.class.name
|
|
104
115
|
end
|
|
105
116
|
|
|
106
117
|
# Convets to singularized model name (resource name).
|
|
107
118
|
# @return [String] Singularized model name (resource name)
|
|
108
119
|
def to_resource_name
|
|
109
|
-
self.
|
|
120
|
+
self.to_class_name.demodulize.singularize.underscore
|
|
110
121
|
end
|
|
111
122
|
|
|
112
123
|
# Convets to pluralized model name (resources name).
|
|
113
124
|
# @return [String] Pluralized model name (resources name)
|
|
114
125
|
def to_resources_name
|
|
115
|
-
self.
|
|
126
|
+
self.to_class_name.demodulize.pluralize.underscore
|
|
116
127
|
end
|
|
117
128
|
|
|
118
129
|
# Convets to printable model type name to be humanized.
|
|
119
130
|
# @return [String] Printable model type name
|
|
120
131
|
# @todo Is this the best to make readable?
|
|
121
132
|
def printable_type
|
|
122
|
-
"#{self.
|
|
133
|
+
"#{self.to_class_name.demodulize.humanize}"
|
|
123
134
|
end
|
|
124
135
|
|
|
125
136
|
# Convets to printable model name to show in view or email.
|
|
@@ -128,4 +139,4 @@ module ActivityNotification
|
|
|
128
139
|
"#{self.printable_type} (#{id})"
|
|
129
140
|
end
|
|
130
141
|
end
|
|
131
|
-
end
|
|
142
|
+
end
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
module ActivityNotification
|
|
2
2
|
# Class used to initialize configuration object.
|
|
3
3
|
class Config
|
|
4
|
+
|
|
5
|
+
# @overload :orm
|
|
6
|
+
# Returns ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb)
|
|
7
|
+
# @return [Boolean] ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb).
|
|
8
|
+
attr_reader :orm
|
|
9
|
+
|
|
4
10
|
# @overload enabled
|
|
5
11
|
# Returns whether ActivityNotification is enabled
|
|
6
12
|
# @return [Boolean] Whether ActivityNotification is enabled.
|
|
@@ -10,16 +16,6 @@ module ActivityNotification
|
|
|
10
16
|
# @return [Boolean] Whether ActivityNotification is enabled.
|
|
11
17
|
attr_accessor :enabled
|
|
12
18
|
|
|
13
|
-
# @deprecated as of 1.1.0
|
|
14
|
-
# @overload table_name
|
|
15
|
-
# Returns table name to store notifications
|
|
16
|
-
# @return [String] Table name to store notifications.
|
|
17
|
-
# @overload table_name=(value)
|
|
18
|
-
# Sets table name to store notifications
|
|
19
|
-
# @param [String] table_name The new notification_table_name
|
|
20
|
-
# @return [String] Table name to store notifications.
|
|
21
|
-
attr_accessor :table_name
|
|
22
|
-
|
|
23
19
|
# @overload notification_table_name
|
|
24
20
|
# Returns table name to store notifications
|
|
25
21
|
# @return [String] Table name to store notifications.
|
|
@@ -65,6 +61,18 @@ module ActivityNotification
|
|
|
65
61
|
# @return [Boolean] Default subscription value to use when the subscription record does not configured.
|
|
66
62
|
attr_accessor :subscribe_as_default
|
|
67
63
|
|
|
64
|
+
# @overload subscribe_to_email_as_default=(value)
|
|
65
|
+
# Sets default email subscription value to use when the subscription record does not configured
|
|
66
|
+
# @param [Boolean] subscribe_to_email_as_default The new subscribe_to_email_as_default
|
|
67
|
+
# @return [Boolean] Default email subscription value to use when the subscription record does not configured.
|
|
68
|
+
attr_writer :subscribe_to_email_as_default
|
|
69
|
+
|
|
70
|
+
# @overload subscribe_to_optional_targets_as_default=(value)
|
|
71
|
+
# Sets default optional target subscription value to use when the subscription record does not configured
|
|
72
|
+
# @param [Boolean] subscribe_to_optional_targets_as_default The new subscribe_to_optional_targets_as_default
|
|
73
|
+
# @return [Boolean] Default optional target subscription value to use when the subscription record does not configured.
|
|
74
|
+
attr_writer :subscribe_to_optional_targets_as_default
|
|
75
|
+
|
|
68
76
|
# @overload mailer_sender
|
|
69
77
|
# Returns email address as sender of notification email
|
|
70
78
|
# @return [String] Email address as sender of notification email.
|
|
@@ -92,6 +100,15 @@ module ActivityNotification
|
|
|
92
100
|
# @return [String] Base mailer class for email notification.
|
|
93
101
|
attr_accessor :parent_mailer
|
|
94
102
|
|
|
103
|
+
# @overload parent_job
|
|
104
|
+
# Returns base job class for delayed notifications
|
|
105
|
+
# @return [String] Base job class for delayed notifications.
|
|
106
|
+
# @overload parent_job=(value)
|
|
107
|
+
# Sets base job class for delayed notifications
|
|
108
|
+
# @param [String] parent_job The new parent_job
|
|
109
|
+
# @return [String] Base job class for delayed notifications.
|
|
110
|
+
attr_accessor :parent_job
|
|
111
|
+
|
|
95
112
|
# @overload parent_controller
|
|
96
113
|
# Returns base controller class for notifications_controller
|
|
97
114
|
# @return [String] Base controller class for notifications_controller.
|
|
@@ -101,6 +118,24 @@ module ActivityNotification
|
|
|
101
118
|
# @return [String] Base controller class for notifications_controller.
|
|
102
119
|
attr_accessor :parent_controller
|
|
103
120
|
|
|
121
|
+
# @overload parent_channel
|
|
122
|
+
# Returns base channel class for notification_channel
|
|
123
|
+
# @return [String] Base channel class for notification_channel.
|
|
124
|
+
# @overload parent_channel=(value)
|
|
125
|
+
# Sets base channel class for notification_channel
|
|
126
|
+
# @param [String] parent_channel The new parent_channel
|
|
127
|
+
# @return [String] Base channel class for notification_channel.
|
|
128
|
+
attr_accessor :parent_channel
|
|
129
|
+
|
|
130
|
+
# @overload mailer_templates_dir
|
|
131
|
+
# Returns custom mailer templates directory
|
|
132
|
+
# @return [String] Custom mailer templates directory.
|
|
133
|
+
# @overload mailer_templates_dir=(value)
|
|
134
|
+
# Sets custom mailer templates directory
|
|
135
|
+
# @param [String] mailer_templates_dir The new custom mailer templates directory
|
|
136
|
+
# @return [String] Custom mailer templates directory.
|
|
137
|
+
attr_accessor :mailer_templates_dir
|
|
138
|
+
|
|
104
139
|
# @overload opened_index_limit
|
|
105
140
|
# Returns default limit to query for opened notifications
|
|
106
141
|
# @return [Integer] Default limit to query for opened notifications.
|
|
@@ -110,34 +145,145 @@ module ActivityNotification
|
|
|
110
145
|
# @return [Integer] Default limit to query for opened notifications.
|
|
111
146
|
attr_accessor :opened_index_limit
|
|
112
147
|
|
|
113
|
-
# @overload
|
|
114
|
-
# Returns
|
|
115
|
-
# @return [
|
|
116
|
-
|
|
148
|
+
# @overload active_job_queue
|
|
149
|
+
# Returns ActiveJob queue name for delayed notifications
|
|
150
|
+
# @return [Symbol] ActiveJob queue name for delayed notifications.
|
|
151
|
+
# @overload active_job_queue=(value)
|
|
152
|
+
# Sets ActiveJob queue name for delayed notifications
|
|
153
|
+
# @param [Symbol] active_job_queue The new active_job_queue
|
|
154
|
+
# @return [Symbol] ActiveJob queue name for delayed notifications.
|
|
155
|
+
attr_accessor :active_job_queue
|
|
156
|
+
|
|
157
|
+
# @overload composite_key_delimiter
|
|
158
|
+
# Returns Delimiter of composite key for DynamoDB
|
|
159
|
+
# @return [String] Delimiter of composite key for DynamoDB.
|
|
160
|
+
# @overload composite_key_delimiter=(value)
|
|
161
|
+
# Sets delimiter of composite key for DynamoDB
|
|
162
|
+
# @param [Symbol] composite_key_delimiter The new delimiter of composite key for DynamoDB
|
|
163
|
+
# @return [Symbol] Delimiter of composite key for DynamoDB.
|
|
164
|
+
attr_accessor :composite_key_delimiter
|
|
165
|
+
|
|
166
|
+
# @overload store_with_associated_records
|
|
167
|
+
# Returns whether activity_notification stores notificaion records including associated records like target and notifiable
|
|
168
|
+
# @return [Boolean] Whether activity_notification stores notificaion records including associated records like target and notifiable.
|
|
169
|
+
attr_reader :store_with_associated_records
|
|
170
|
+
|
|
171
|
+
# @overload action_cable_enabled
|
|
172
|
+
# Returns whether WebSocket subscription using ActionCable is enabled
|
|
173
|
+
# @return [Boolean] Whether WebSocket subscription using ActionCable is enabled.
|
|
174
|
+
# @overload action_cable_enabled=(value)
|
|
175
|
+
# Sets whether WebSocket subscription using ActionCable is enabled
|
|
176
|
+
# @param [Boolean] action_cable_enabled The new action_cable_enabled
|
|
177
|
+
# @return [Boolean] Whether WebSocket subscription using ActionCable is enabled.
|
|
178
|
+
attr_accessor :action_cable_enabled
|
|
179
|
+
|
|
180
|
+
# @overload action_cable_api_enabled
|
|
181
|
+
# Returns whether WebSocket API subscription using ActionCable is enabled
|
|
182
|
+
# @return [Boolean] Whether WebSocket API subscription using ActionCable is enabled.
|
|
183
|
+
# @overload action_cable_api_enabled=(value)
|
|
184
|
+
# Sets whether WebSocket API subscription using ActionCable is enabled
|
|
185
|
+
# @param [Boolean] action_cable_enabled The new action_cable_api_enabled
|
|
186
|
+
# @return [Boolean] Whether WebSocket API subscription using ActionCable is enabled.
|
|
187
|
+
attr_accessor :action_cable_api_enabled
|
|
188
|
+
|
|
189
|
+
# @overload action_cable_with_devise
|
|
190
|
+
# Returns whether activity_notification publishes WebSocket notifications using ActionCable only to authenticated target with Devise
|
|
191
|
+
# @return [Boolean] Whether activity_notification publishes WebSocket notifications using ActionCable only to authenticated target with Devise.
|
|
192
|
+
# @overload action_cable_with_devise=(value)
|
|
193
|
+
# Sets whether activity_notification publishes WebSocket notifications using ActionCable only to authenticated target with Devise
|
|
194
|
+
# @param [Boolean] action_cable_with_devise The new action_cable_with_devise
|
|
195
|
+
# @return [Boolean] Whether activity_notification publishes WebSocket notifications using ActionCable only to authenticated target with Devise.
|
|
196
|
+
attr_accessor :action_cable_with_devise
|
|
197
|
+
|
|
198
|
+
# @overload notification_channel_prefix
|
|
199
|
+
# Returns notification channel prefix for ActionCable
|
|
200
|
+
# @return [String] Notification channel prefix for ActionCable.
|
|
201
|
+
# @overload notification_channel_prefix=(value)
|
|
202
|
+
# Sets notification channel prefix for ActionCable
|
|
203
|
+
# @param [String] notification_channel_prefix The new notification_channel_prefix
|
|
204
|
+
# @return [String] Notification channel prefix for ActionCable.
|
|
205
|
+
attr_accessor :notification_channel_prefix
|
|
206
|
+
|
|
207
|
+
# @overload notification_api_channel_prefix
|
|
208
|
+
# Returns notification API channel prefix for ActionCable
|
|
209
|
+
# @return [String] Notification API channel prefix for ActionCable.
|
|
210
|
+
# @overload notification_api_channel_prefix=(value)
|
|
211
|
+
# Sets notification API channel prefix for ActionCable
|
|
212
|
+
# @param [String] notification_api_channel_prefix The new notification_api_channel_prefix
|
|
213
|
+
# @return [String] Notification API channel prefix for ActionCable.
|
|
214
|
+
attr_accessor :notification_api_channel_prefix
|
|
215
|
+
|
|
216
|
+
# @overload rescue_optional_target_errors
|
|
217
|
+
# Returns whether activity_notification internally rescues optional target errors
|
|
218
|
+
# @return [Boolean] Whether activity_notification internally rescues optional target errors.
|
|
219
|
+
# @overload rescue_optional_target_errors=(value)
|
|
220
|
+
# Sets whether activity_notification internally rescues optional target errors
|
|
221
|
+
# @param [Boolean] rescue_optional_target_errors The new rescue_optional_target_errors
|
|
222
|
+
# @return [Boolean] Whether activity_notification internally rescues optional target errors.
|
|
223
|
+
attr_accessor :rescue_optional_target_errors
|
|
117
224
|
|
|
118
225
|
# Initialize configuration for ActivityNotification.
|
|
119
|
-
# These configuration can be
|
|
226
|
+
# These configuration can be overridden in initializer.
|
|
120
227
|
# @return [Config] A new instance of Config
|
|
121
228
|
def initialize
|
|
122
|
-
@enabled
|
|
123
|
-
@
|
|
124
|
-
@
|
|
125
|
-
@
|
|
126
|
-
@
|
|
127
|
-
@
|
|
128
|
-
@
|
|
129
|
-
@
|
|
130
|
-
@
|
|
131
|
-
@
|
|
132
|
-
@
|
|
133
|
-
@
|
|
229
|
+
@enabled = true
|
|
230
|
+
@orm = :active_record
|
|
231
|
+
@notification_table_name = 'notifications'
|
|
232
|
+
@subscription_table_name = 'subscriptions'
|
|
233
|
+
@email_enabled = false
|
|
234
|
+
@subscription_enabled = false
|
|
235
|
+
@subscribe_as_default = true
|
|
236
|
+
@subscribe_to_email_as_default = nil
|
|
237
|
+
@subscribe_to_optional_targets_as_default = nil
|
|
238
|
+
@mailer_sender = nil
|
|
239
|
+
@mailer = 'ActivityNotification::Mailer'
|
|
240
|
+
@parent_mailer = 'ActionMailer::Base'
|
|
241
|
+
@parent_job = 'ActiveJob::Base'
|
|
242
|
+
@parent_controller = 'ApplicationController'
|
|
243
|
+
@parent_channel = 'ActionCable::Channel::Base'
|
|
244
|
+
@mailer_templates_dir = 'activity_notification/mailer'
|
|
245
|
+
@opened_index_limit = 10
|
|
246
|
+
@active_job_queue = :activity_notification
|
|
247
|
+
@composite_key_delimiter = '#'
|
|
248
|
+
@store_with_associated_records = false
|
|
249
|
+
@action_cable_enabled = false
|
|
250
|
+
@action_cable_api_enabled = false
|
|
251
|
+
@action_cable_with_devise = false
|
|
252
|
+
@notification_channel_prefix = 'activity_notification_channel'
|
|
253
|
+
@notification_api_channel_prefix = 'activity_notification_api_channel'
|
|
254
|
+
@rescue_optional_target_errors = true
|
|
134
255
|
end
|
|
135
256
|
|
|
136
|
-
# Sets ORM name for ActivityNotification (:active_record or :
|
|
137
|
-
# @param [Symbol, String] orm The new ORM name for ActivityNotification (:active_record or :
|
|
138
|
-
# @return [Symbol] ORM name for ActivityNotification (:active_record or :
|
|
257
|
+
# Sets ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb)
|
|
258
|
+
# @param [Symbol, String] orm The new ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb)
|
|
259
|
+
# @return [Symbol] ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb).
|
|
139
260
|
def orm=(orm)
|
|
140
261
|
@orm = orm.to_sym
|
|
141
262
|
end
|
|
263
|
+
|
|
264
|
+
# Sets whether activity_notification stores notificaion records including associated records like target and notifiable.
|
|
265
|
+
# This store_with_associated_records option can be set true only when you use mongoid or dynamoid ORM.
|
|
266
|
+
# @param [Boolean] store_with_associated_records The new store_with_associated_records
|
|
267
|
+
# @return [Boolean] Whether activity_notification stores notificaion records including associated records like target and notifiable.
|
|
268
|
+
def store_with_associated_records=(store_with_associated_records)
|
|
269
|
+
if store_with_associated_records && [:mongoid, :dynamoid].exclude?(@orm) then raise ActivityNotification::ConfigError, "config.store_with_associated_records can be set true only when you use mongoid or dynamoid ORM." end
|
|
270
|
+
@store_with_associated_records = store_with_associated_records
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Returns default email subscription value to use when the subscription record does not configured
|
|
274
|
+
# @return [Boolean] Default email subscription value to use when the subscription record does not configured.
|
|
275
|
+
def subscribe_to_email_as_default
|
|
276
|
+
return false unless @subscribe_as_default
|
|
277
|
+
|
|
278
|
+
@subscribe_to_email_as_default.nil? ? @subscribe_as_default : @subscribe_to_email_as_default
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Returns default optional target subscription value to use when the subscription record does not configured
|
|
282
|
+
# @return [Boolean] Default optinal target subscription value to use when the subscription record does not configured.
|
|
283
|
+
def subscribe_to_optional_targets_as_default
|
|
284
|
+
return false unless @subscribe_as_default
|
|
285
|
+
|
|
286
|
+
@subscribe_to_optional_targets_as_default.nil? ? @subscribe_as_default : @subscribe_to_optional_targets_as_default
|
|
287
|
+
end
|
|
142
288
|
end
|
|
143
289
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module ActivityNotification
|
|
2
|
+
# Module included in api controllers to select target
|
|
3
|
+
module CommonApiController
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
rescue_from ActiveRecord::RecordNotFound, with: :render_resource_not_found if defined?(ActiveRecord)
|
|
8
|
+
rescue_from Mongoid::Errors::DocumentNotFound, with: :render_resource_not_found if ActivityNotification.config.orm == :mongoid
|
|
9
|
+
rescue_from Dynamoid::Errors::RecordNotFound, with: :render_resource_not_found if ActivityNotification.config.orm == :dynamoid
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
protected
|
|
13
|
+
|
|
14
|
+
# Override to do nothing instead of JavaScript view for ajax request or redirects to back.
|
|
15
|
+
# @api protected
|
|
16
|
+
def return_back_or_ajax
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Override to do nothing instead of redirecting to notifiable_path
|
|
20
|
+
# @api protected
|
|
21
|
+
def redirect_to_notifiable_path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Override to do nothing instead of redirecting to subscription path
|
|
25
|
+
# @api protected
|
|
26
|
+
def redirect_to_subscription_path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|