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
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
module ActivityNotification
|
|
2
|
+
# Controller to manage subscriptions API.
|
|
3
|
+
class SubscriptionsApiController < SubscriptionsController
|
|
4
|
+
# Include Swagger API reference
|
|
5
|
+
include Swagger::SubscriptionsApi
|
|
6
|
+
# Include CommonApiController to select target and define common methods
|
|
7
|
+
include CommonApiController
|
|
8
|
+
protect_from_forgery except: [:create]
|
|
9
|
+
before_action :set_subscription, except: [:index, :create, :find, :optional_target_names]
|
|
10
|
+
before_action ->{ validate_param(:key) }, only: [:find, :optional_target_names]
|
|
11
|
+
|
|
12
|
+
# Returns subscription index of the target.
|
|
13
|
+
#
|
|
14
|
+
# GET /:target_type/:target_id/subscriptions
|
|
15
|
+
# @overload index(params)
|
|
16
|
+
# @param [Hash] params Request parameter options for subscription index
|
|
17
|
+
# @option params [String] :filter (nil) Filter option to load subscription index by their configuration status (Nothing as all, 'configured' or 'unconfigured')
|
|
18
|
+
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
19
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
20
|
+
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
21
|
+
# @return [JSON] configured_count: count of subscription index, subscriptions: subscription index, unconfigured_count: count of unconfigured notification keys, unconfigured_notification_keys: unconfigured notification keys
|
|
22
|
+
def index
|
|
23
|
+
super
|
|
24
|
+
json_response = { configured_count: @subscriptions.size, subscriptions: @subscriptions } if @subscriptions
|
|
25
|
+
json_response = (json_response || {}).merge(unconfigured_count: @notification_keys.size, unconfigured_notification_keys: @notification_keys) if @notification_keys
|
|
26
|
+
render json: json_response
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Creates new subscription.
|
|
30
|
+
#
|
|
31
|
+
# POST /:target_type/:target_id/subscriptions
|
|
32
|
+
# @overload create(params)
|
|
33
|
+
# @param [Hash] params Request parameters
|
|
34
|
+
# @option params [String] :subscription Subscription parameters
|
|
35
|
+
# @option params [String] :subscription[:key] Key of the subscription
|
|
36
|
+
# @option params [String] :subscription[:subscribing] (nil) Whether the target will subscribe to the notification
|
|
37
|
+
# @option params [String] :subscription[:subscribing_to_email] (nil) Whether the target will subscribe to the notification email
|
|
38
|
+
# @return [JSON] Created subscription
|
|
39
|
+
def create
|
|
40
|
+
render_invalid_parameter("Parameter is missing or the value is empty: subscription") and return if params[:subscription].blank?
|
|
41
|
+
optional_target_names = (params[:subscription][:optional_targets] || {}).keys.select { |key| !key.to_s.start_with?("subscribing_to_") }
|
|
42
|
+
optional_target_names.each do |optional_target_name|
|
|
43
|
+
subscribing_param = params[:subscription][:optional_targets][optional_target_name][:subscribing]
|
|
44
|
+
params[:subscription][:optional_targets]["subscribing_to_#{optional_target_name}"] = subscribing_param unless subscribing_param.nil?
|
|
45
|
+
end
|
|
46
|
+
super
|
|
47
|
+
render status: 201, json: subscription_json if @subscription
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Finds and shows a subscription from specified key.
|
|
51
|
+
#
|
|
52
|
+
# GET /:target_type/:target_id/subscriptions/find
|
|
53
|
+
# @overload index(params)
|
|
54
|
+
# @param [Hash] params Request parameter options for subscription index
|
|
55
|
+
# @option params [required, String] :key (nil) Key of the subscription
|
|
56
|
+
# @return [JSON] Found single subscription
|
|
57
|
+
def find
|
|
58
|
+
super
|
|
59
|
+
render json: subscription_json if @subscription
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Finds and returns configured optional_target names from specified key.
|
|
63
|
+
#
|
|
64
|
+
# GET /:target_type/:target_id/subscriptions/optional_target_names
|
|
65
|
+
# @overload index(params)
|
|
66
|
+
# @param [Hash] params Request parameter options for subscription index
|
|
67
|
+
# @option params [required, String] :key (nil) Key of the subscription
|
|
68
|
+
# @return [JSON] Configured optional_target names
|
|
69
|
+
def optional_target_names
|
|
70
|
+
latest_notification = @target.notifications.filtered_by_key(params[:key]).latest
|
|
71
|
+
latest_notification ?
|
|
72
|
+
render(json: { configured_count: latest_notification.optional_target_names.length, optional_target_names: latest_notification.optional_target_names }) :
|
|
73
|
+
render_resource_not_found("Couldn't find notification with this target and 'key'=#{params[:key]}")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Shows a subscription.
|
|
77
|
+
#
|
|
78
|
+
# GET /:target_type/:target_id/subscriptions/:id
|
|
79
|
+
# @overload show(params)
|
|
80
|
+
# @param [Hash] params Request parameters
|
|
81
|
+
# @return [JSON] Found single subscription
|
|
82
|
+
def show
|
|
83
|
+
super
|
|
84
|
+
render json: subscription_json
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Deletes a subscription.
|
|
88
|
+
#
|
|
89
|
+
# DELETE /:target_type/:target_id/subscriptions/:id
|
|
90
|
+
#
|
|
91
|
+
# @overload destroy(params)
|
|
92
|
+
# @param [Hash] params Request parameters
|
|
93
|
+
# @return [JSON] 204 No Content
|
|
94
|
+
def destroy
|
|
95
|
+
super
|
|
96
|
+
head 204
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Updates a subscription to subscribe to the notifications.
|
|
100
|
+
#
|
|
101
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe
|
|
102
|
+
# @overload open(params)
|
|
103
|
+
# @param [Hash] params Request parameters
|
|
104
|
+
# @option params [String] :with_email_subscription ('true') Whether the subscriber also subscribes notification email
|
|
105
|
+
# @option params [String] :with_optional_targets ('true') Whether the subscriber also subscribes optional targets
|
|
106
|
+
# @return [JSON] Updated subscription
|
|
107
|
+
def subscribe
|
|
108
|
+
super
|
|
109
|
+
validate_and_render_subscription
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Updates a subscription to unsubscribe to the notifications.
|
|
113
|
+
#
|
|
114
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe
|
|
115
|
+
# @overload open(params)
|
|
116
|
+
# @param [Hash] params Request parameters
|
|
117
|
+
# @return [JSON] Updated subscription
|
|
118
|
+
def unsubscribe
|
|
119
|
+
super
|
|
120
|
+
validate_and_render_subscription
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Updates a subscription to subscribe to the notification email.
|
|
124
|
+
#
|
|
125
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe_email
|
|
126
|
+
# @overload open(params)
|
|
127
|
+
# @param [Hash] params Request parameters
|
|
128
|
+
# @return [JSON] Updated subscription
|
|
129
|
+
def subscribe_to_email
|
|
130
|
+
super
|
|
131
|
+
validate_and_render_subscription
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Updates a subscription to unsubscribe to the notification email.
|
|
135
|
+
#
|
|
136
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_email
|
|
137
|
+
# @overload open(params)
|
|
138
|
+
# @param [Hash] params Request parameters
|
|
139
|
+
# @return [JSON] Updated subscription
|
|
140
|
+
def unsubscribe_to_email
|
|
141
|
+
super
|
|
142
|
+
validate_and_render_subscription
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Updates a subscription to subscribe to the specified optional target.
|
|
146
|
+
#
|
|
147
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe_to_optional_target
|
|
148
|
+
# @overload open(params)
|
|
149
|
+
# @param [Hash] params Request parameters
|
|
150
|
+
# @option params [required, String] :optional_target_name (nil) Class name of the optional target implementation (e.g. 'amazon_sns', 'slack')
|
|
151
|
+
# @return [JSON] Updated subscription
|
|
152
|
+
def subscribe_to_optional_target
|
|
153
|
+
super
|
|
154
|
+
validate_and_render_subscription
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Updates a subscription to unsubscribe to the specified optional target.
|
|
158
|
+
#
|
|
159
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_to_optional_target
|
|
160
|
+
# @overload open(params)
|
|
161
|
+
# @param [Hash] params Request parameters
|
|
162
|
+
# @option params [required, String] :optional_target_name (nil) Class name of the optional target implementation (e.g. 'amazon_sns', 'slack')
|
|
163
|
+
# @return [JSON] Updated subscription
|
|
164
|
+
def unsubscribe_to_optional_target
|
|
165
|
+
super
|
|
166
|
+
validate_and_render_subscription
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
protected
|
|
170
|
+
|
|
171
|
+
# Returns include option for subscription JSON
|
|
172
|
+
# @api protected
|
|
173
|
+
def subscription_json_include_option
|
|
174
|
+
[:target].freeze
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Returns methods option for subscription JSON
|
|
178
|
+
# @api protected
|
|
179
|
+
def subscription_json_methods_option
|
|
180
|
+
[].freeze
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Returns JSON of @subscription
|
|
184
|
+
# @api protected
|
|
185
|
+
def subscription_json
|
|
186
|
+
@subscription.as_json(include: subscription_json_include_option, methods: subscription_json_methods_option)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Validate @subscription and render JSON of @subscription
|
|
190
|
+
# @api protected
|
|
191
|
+
def validate_and_render_subscription
|
|
192
|
+
raise RecordInvalidError, @subscription.errors.full_messages.first if @subscription.invalid?
|
|
193
|
+
render json: subscription_json
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
end
|
|
197
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module ActivityNotification
|
|
2
|
+
# Controller to manage subscriptions API with Devise authentication.
|
|
3
|
+
class SubscriptionsApiWithDeviseController < SubscriptionsApiController
|
|
4
|
+
include DeviseTokenAuth::Concerns::SetUserByToken if defined?(DeviseTokenAuth)
|
|
5
|
+
include DeviseAuthenticationController
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -3,163 +3,171 @@ module ActivityNotification
|
|
|
3
3
|
class SubscriptionsController < ActivityNotification.config.parent_controller.constantize
|
|
4
4
|
# Include CommonController to select target and define common methods
|
|
5
5
|
include CommonController
|
|
6
|
-
before_action :set_subscription, except: [:index, :create]
|
|
7
|
-
before_action :
|
|
6
|
+
before_action :set_subscription, except: [:index, :create, :find]
|
|
7
|
+
before_action ->{ validate_param(:key) }, only: [:find]
|
|
8
|
+
before_action ->{ validate_param(:optional_target_name) }, only: [:subscribe_to_optional_target, :unsubscribe_to_optional_target]
|
|
8
9
|
|
|
9
10
|
# Shows subscription index of the target.
|
|
10
11
|
#
|
|
11
12
|
# GET /:target_type/:target_id/subscriptions
|
|
12
13
|
# @overload index(params)
|
|
13
14
|
# @param [Hash] params Request parameter options for subscription index
|
|
14
|
-
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
15
|
+
# @option params [String] :filter (nil) Filter option to load subscription index by their configuration status (Nothing as all, 'configured' or 'unconfigured')
|
|
15
16
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
16
|
-
# @option params [String] :reverse ('false')
|
|
17
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
17
18
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
18
|
-
# @return [
|
|
19
|
+
# @return [Response] HTML view of subscription index
|
|
19
20
|
def index
|
|
20
21
|
set_index_options
|
|
21
22
|
load_index if params[:reload].to_s.to_boolean(true)
|
|
22
|
-
respond_to do |format|
|
|
23
|
-
format.html # index.html.erb
|
|
24
|
-
format.json { render json: { subscriptions: @subscriptions, unconfigured_notification_keys: @notification_keys } }
|
|
25
|
-
end
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
# Creates
|
|
29
|
-
#
|
|
30
|
-
# POST /:target_type/:target_id/subscriptions
|
|
25
|
+
# Creates new subscription.
|
|
31
26
|
#
|
|
27
|
+
# PUT /:target_type/:target_id/subscriptions
|
|
32
28
|
# @overload create(params)
|
|
33
29
|
# @param [Hash] params Request parameters
|
|
34
30
|
# @option params [String] :subscription Subscription parameters
|
|
35
31
|
# @option params [String] :subscription[:key] Key of the subscription
|
|
36
|
-
# @option params [String] :subscription[:subscribing] (nil)
|
|
37
|
-
# @option params [String] :subscription[:subscribing_to_email] (nil)
|
|
38
|
-
# @option params [String] :filter (nil)
|
|
39
|
-
# @option params [String] :limit (nil)
|
|
40
|
-
# @option params [String] :reverse ('false')
|
|
41
|
-
# @option params [String] :filtered_by_key (nil)
|
|
42
|
-
# @return [
|
|
32
|
+
# @option params [String] :subscription[:subscribing] (nil) Whether the target will subscribe to the notification
|
|
33
|
+
# @option params [String] :subscription[:subscribing_to_email] (nil) Whether the target will subscribe to the notification email
|
|
34
|
+
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
35
|
+
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
36
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
37
|
+
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
38
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
43
39
|
def create
|
|
44
|
-
@target.create_subscription(subscription_params)
|
|
40
|
+
@subscription = @target.create_subscription(subscription_params)
|
|
45
41
|
return_back_or_ajax
|
|
46
42
|
end
|
|
47
43
|
|
|
44
|
+
# Finds and shows a subscription from specified key.
|
|
45
|
+
#
|
|
46
|
+
# GET /:target_type/:target_id/subscriptions/find
|
|
47
|
+
# @overload index(params)
|
|
48
|
+
# @param [Hash] params Request parameter options for subscription index
|
|
49
|
+
# @option params [required, String] :key (nil) Key of the subscription
|
|
50
|
+
# @return [Response] HTML view as default or JSON of subscription index with json format parameter
|
|
51
|
+
def find
|
|
52
|
+
@subscription = @target.find_subscription(params[:key])
|
|
53
|
+
@subscription ? redirect_to_subscription_path : render_resource_not_found("Couldn't find subscription with this target and 'key'=#{params[:key]}")
|
|
54
|
+
end
|
|
55
|
+
|
|
48
56
|
# Shows a subscription.
|
|
49
57
|
#
|
|
50
58
|
# GET /:target_type/:target_id/subscriptions/:id
|
|
51
59
|
# @overload show(params)
|
|
52
60
|
# @param [Hash] params Request parameters
|
|
53
|
-
# @return [
|
|
61
|
+
# @return [Response] HTML view as default
|
|
54
62
|
def show
|
|
63
|
+
set_index_options
|
|
55
64
|
end
|
|
56
65
|
|
|
57
66
|
# Deletes a subscription.
|
|
58
67
|
#
|
|
59
68
|
# DELETE /:target_type/:target_id/subscriptions/:id
|
|
60
|
-
#
|
|
61
69
|
# @overload destroy(params)
|
|
62
70
|
# @param [Hash] params Request parameters
|
|
63
71
|
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
64
72
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
65
|
-
# @option params [String] :reverse ('false')
|
|
73
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
66
74
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
67
|
-
# @return [
|
|
75
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
68
76
|
def destroy
|
|
69
77
|
@subscription.destroy
|
|
70
78
|
return_back_or_ajax
|
|
71
79
|
end
|
|
72
80
|
|
|
73
|
-
#
|
|
81
|
+
# Updates a subscription to subscribe to notifications.
|
|
74
82
|
#
|
|
75
|
-
#
|
|
83
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe
|
|
76
84
|
# @overload open(params)
|
|
77
85
|
# @param [Hash] params Request parameters
|
|
78
|
-
# @option params [String] :with_email_subscription ('true')
|
|
79
|
-
# @option params [String] :with_optional_targets ('true')
|
|
86
|
+
# @option params [String] :with_email_subscription ('true') Whether the subscriber also subscribes notification email
|
|
87
|
+
# @option params [String] :with_optional_targets ('true') Whether the subscriber also subscribes optional targets
|
|
80
88
|
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
81
89
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
82
|
-
# @option params [String] :reverse ('false')
|
|
90
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
83
91
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
84
|
-
# @return [
|
|
92
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
85
93
|
def subscribe
|
|
86
|
-
@subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(
|
|
87
|
-
with_optional_targets: params[:with_optional_targets].to_s.to_boolean(
|
|
94
|
+
@subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(ActivityNotification.config.subscribe_to_email_as_default),
|
|
95
|
+
with_optional_targets: params[:with_optional_targets].to_s.to_boolean(ActivityNotification.config.subscribe_to_optional_targets_as_default))
|
|
88
96
|
return_back_or_ajax
|
|
89
97
|
end
|
|
90
98
|
|
|
91
|
-
#
|
|
99
|
+
# Updates a subscription to unsubscribe to the notifications.
|
|
92
100
|
#
|
|
93
|
-
#
|
|
101
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe
|
|
94
102
|
# @overload open(params)
|
|
95
103
|
# @param [Hash] params Request parameters
|
|
96
104
|
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
97
105
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
98
|
-
# @option params [String] :reverse ('false')
|
|
106
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
99
107
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
100
|
-
# @return [
|
|
108
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
101
109
|
def unsubscribe
|
|
102
110
|
@subscription.unsubscribe
|
|
103
111
|
return_back_or_ajax
|
|
104
112
|
end
|
|
105
113
|
|
|
106
|
-
#
|
|
114
|
+
# Updates a subscription to subscribe to the notification email.
|
|
107
115
|
#
|
|
108
|
-
#
|
|
116
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe_email
|
|
109
117
|
# @overload open(params)
|
|
110
118
|
# @param [Hash] params Request parameters
|
|
111
119
|
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
112
120
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
113
|
-
# @option params [String] :reverse ('false')
|
|
121
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
114
122
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
115
|
-
# @return [
|
|
123
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
116
124
|
def subscribe_to_email
|
|
117
125
|
@subscription.subscribe_to_email
|
|
118
126
|
return_back_or_ajax
|
|
119
127
|
end
|
|
120
128
|
|
|
121
|
-
#
|
|
129
|
+
# Updates a subscription to unsubscribe to the notification email.
|
|
122
130
|
#
|
|
123
|
-
#
|
|
131
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_email
|
|
124
132
|
# @overload open(params)
|
|
125
133
|
# @param [Hash] params Request parameters
|
|
126
134
|
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
127
135
|
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
128
|
-
# @option params [String] :reverse ('false')
|
|
136
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
129
137
|
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
130
|
-
# @return [
|
|
138
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
131
139
|
def unsubscribe_to_email
|
|
132
140
|
@subscription.unsubscribe_to_email
|
|
133
141
|
return_back_or_ajax
|
|
134
142
|
end
|
|
135
143
|
|
|
136
|
-
#
|
|
144
|
+
# Updates a subscription to subscribe to the specified optional target.
|
|
137
145
|
#
|
|
138
|
-
#
|
|
146
|
+
# PUT /:target_type/:target_id/subscriptions/:id/subscribe_to_optional_target
|
|
139
147
|
# @overload open(params)
|
|
140
148
|
# @param [Hash] params Request parameters
|
|
141
|
-
# @option params [required, String] :optional_target_name (nil)
|
|
142
|
-
# @option params [String] :filter (nil)
|
|
143
|
-
# @option params [String] :limit (nil)
|
|
144
|
-
# @option params [String] :reverse ('false')
|
|
145
|
-
# @option params [String] :filtered_by_key (nil)
|
|
146
|
-
# @return [
|
|
149
|
+
# @option params [required, String] :optional_target_name (nil) Class name of the optional target implementation (e.g. 'amazon_sns', 'slack')
|
|
150
|
+
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
151
|
+
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
152
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
153
|
+
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
154
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
147
155
|
def subscribe_to_optional_target
|
|
148
156
|
@subscription.subscribe_to_optional_target(params[:optional_target_name])
|
|
149
157
|
return_back_or_ajax
|
|
150
158
|
end
|
|
151
159
|
|
|
152
|
-
#
|
|
160
|
+
# Updates a subscription to unsubscribe to the specified optional target.
|
|
153
161
|
#
|
|
154
|
-
#
|
|
162
|
+
# PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_to_optional_target
|
|
155
163
|
# @overload open(params)
|
|
156
164
|
# @param [Hash] params Request parameters
|
|
157
|
-
# @option params [required, String] :optional_target_name (nil)
|
|
158
|
-
# @option params [String] :filter (nil)
|
|
159
|
-
# @option params [String] :limit (nil)
|
|
160
|
-
# @option params [String] :reverse ('false')
|
|
161
|
-
# @option params [String] :filtered_by_key (nil)
|
|
162
|
-
# @return [
|
|
165
|
+
# @option params [required, String] :optional_target_name (nil) Class name of the optional target implementation (e.g. 'amazon_sns', 'slack')
|
|
166
|
+
# @option params [String] :filter (nil) Filter option to load subscription index (Nothing as all, 'configured' or 'unconfigured')
|
|
167
|
+
# @option params [String] :limit (nil) Limit to query for subscriptions
|
|
168
|
+
# @option params [String] :reverse ('false') Whether subscription index and unconfigured notification keys will be ordered as earliest first
|
|
169
|
+
# @option params [String] :filtered_by_key (nil) Key of the subscription for filter
|
|
170
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
163
171
|
def unsubscribe_to_optional_target
|
|
164
172
|
@subscription.unsubscribe_to_optional_target(params[:optional_target_name])
|
|
165
173
|
return_back_or_ajax
|
|
@@ -176,11 +184,14 @@ module ActivityNotification
|
|
|
176
184
|
|
|
177
185
|
# Only allow a trusted parameter "white list" through.
|
|
178
186
|
def subscription_params
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
if params[:subscription].present?
|
|
188
|
+
optional_target_keys = (params[:subscription][:optional_targets] || {}).keys.select { |key| key.to_s.start_with?("subscribing_to_") }
|
|
189
|
+
optional_target_keys.each do |optional_target_key|
|
|
190
|
+
boolean_value = params[:subscription][:optional_targets][optional_target_key].respond_to?(:to_boolean) ? params[:subscription][:optional_targets][optional_target_key].to_boolean : !!params[:subscription][:optional_targets][optional_target_key]
|
|
191
|
+
params[:subscription][:optional_targets][optional_target_key] = boolean_value
|
|
192
|
+
end
|
|
182
193
|
end
|
|
183
|
-
params.require(:subscription).permit(:key, :subscribing, :subscribing_to_email, optional_targets:
|
|
194
|
+
params.require(:subscription).permit(:key, :subscribing, :subscribing_to_email, optional_targets: optional_target_keys)
|
|
184
195
|
end
|
|
185
196
|
|
|
186
197
|
# Sets options to load subscription index from request parameters.
|
|
@@ -190,7 +201,7 @@ module ActivityNotification
|
|
|
190
201
|
limit = params[:limit].to_i > 0 ? params[:limit].to_i : nil
|
|
191
202
|
reverse = params[:reverse].present? ?
|
|
192
203
|
params[:reverse].to_s.to_boolean(false) : nil
|
|
193
|
-
@index_options = params.permit(:filter, :filtered_by_key)
|
|
204
|
+
@index_options = params.permit(:filter, :filtered_by_key, :routing_scope, :devise_default_routes)
|
|
194
205
|
.to_h.symbolize_keys.merge(limit: limit, reverse: reverse)
|
|
195
206
|
end
|
|
196
207
|
|
|
@@ -211,20 +222,19 @@ module ActivityNotification
|
|
|
211
222
|
end
|
|
212
223
|
end
|
|
213
224
|
|
|
225
|
+
# Redirect to subscription path
|
|
226
|
+
# @api protected
|
|
227
|
+
def redirect_to_subscription_path
|
|
228
|
+
redirect_to action: :show, id: @subscription
|
|
229
|
+
end
|
|
230
|
+
|
|
214
231
|
# Returns controller path.
|
|
215
|
-
# This method is called from target_view_path method and can be
|
|
232
|
+
# This method is called from target_view_path method and can be overridden.
|
|
216
233
|
# @api protected
|
|
217
234
|
# @return [String] "activity_notification/subscriptions" as controller path
|
|
218
235
|
def controller_path
|
|
219
236
|
"activity_notification/subscriptions"
|
|
220
237
|
end
|
|
221
238
|
|
|
222
|
-
# Validate optional_target_name param and return HTTP 400 unless it presents.
|
|
223
|
-
def validate_optional_target_param
|
|
224
|
-
if params[:optional_target_name].blank?
|
|
225
|
-
render plain: "400 Bad Request: Missing parameter", status: 400
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
239
|
end
|
|
230
240
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
if defined?(ActiveJob)
|
|
2
|
+
# Job to generate notifications by ActivityNotification::Notification#notify_all method.
|
|
3
|
+
class ActivityNotification::NotifyAllJob < ActivityNotification.config.parent_job.constantize
|
|
4
|
+
queue_as ActivityNotification.config.active_job_queue
|
|
5
|
+
|
|
6
|
+
# Generates notifications to specified targets with ActiveJob.
|
|
7
|
+
#
|
|
8
|
+
# @param [Array<Object>] targets Targets to send notifications
|
|
9
|
+
# @param [Object] notifiable Notifiable instance
|
|
10
|
+
# @param [Hash] options Options for notifications
|
|
11
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
|
12
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
|
13
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
|
14
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
|
15
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
|
16
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
|
17
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
|
18
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
|
19
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
|
20
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
|
21
|
+
def perform(targets, notifiable, options = {})
|
|
22
|
+
ActivityNotification::Notification.notify_all(targets, notifiable, options)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
if defined?(ActiveJob)
|
|
2
|
+
# Job to generate notifications by ActivityNotification::Notification#notify method.
|
|
3
|
+
class ActivityNotification::NotifyJob < ActivityNotification.config.parent_job.constantize
|
|
4
|
+
queue_as ActivityNotification.config.active_job_queue
|
|
5
|
+
|
|
6
|
+
# Generates notifications to configured targets with notifiable model with ActiveJob.
|
|
7
|
+
#
|
|
8
|
+
# @param [Symbol, String, Class] target_type Type of target
|
|
9
|
+
# @param [Object] notifiable Notifiable instance
|
|
10
|
+
# @param [Hash] options Options for notifications
|
|
11
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
|
12
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
|
13
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
|
14
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
|
15
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
|
16
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
|
17
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
|
18
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
|
19
|
+
# @option options [Boolean] :pass_full_options (false) Whether it passes full options to notifiable.notification_targets, not a key only
|
|
20
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
|
21
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
|
22
|
+
def perform(target_type, notifiable, options = {})
|
|
23
|
+
ActivityNotification::Notification.notify(target_type, notifiable, options)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
if defined?(ActiveJob)
|
|
2
|
+
# Job to generate notifications by ActivityNotification::Notification#notify_to method.
|
|
3
|
+
class ActivityNotification::NotifyToJob < ActivityNotification.config.parent_job.constantize
|
|
4
|
+
queue_as ActivityNotification.config.active_job_queue
|
|
5
|
+
|
|
6
|
+
# Generates notifications to one target with ActiveJob.
|
|
7
|
+
#
|
|
8
|
+
# @param [Object] target Target to send notifications
|
|
9
|
+
# @param [Object] notifiable Notifiable instance
|
|
10
|
+
# @param [Hash] options Options for notifications
|
|
11
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
|
12
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
|
13
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
|
14
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
|
15
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
|
16
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
|
17
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
|
18
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
|
19
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
|
20
|
+
# @return [Notification] Generated notification instance
|
|
21
|
+
def perform(target, notifiable, options = {})
|
|
22
|
+
ActivityNotification::Notification.notify_to(target, notifiable, options)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|