activity_notification 1.4.4 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -11,6 +11,7 @@ module ActivityNotification
|
|
11
11
|
|
12
12
|
prepend_before_action :set_target
|
13
13
|
before_action :set_view_prefixes
|
14
|
+
rescue_from ActivityNotification::RecordInvalidError, with: ->(e){ render_unprocessable_entity(e.message) }
|
14
15
|
end
|
15
16
|
|
16
17
|
DEFAULT_VIEW_DIRECTORY = "default"
|
@@ -19,15 +20,15 @@ module ActivityNotification
|
|
19
20
|
|
20
21
|
# Sets @target instance variable from request parameters.
|
21
22
|
# @api protected
|
22
|
-
# @return [Object] Target instance (Returns HTTP 400 when request parameters are
|
23
|
+
# @return [Object] Target instance (Returns HTTP 400 when request parameters are invalid)
|
23
24
|
def set_target
|
24
25
|
if (target_type = params[:target_type]).present?
|
25
26
|
target_class = target_type.to_model_class
|
26
27
|
@target = params[:target_id].present? ?
|
27
28
|
target_class.find_by!(id: params[:target_id]) :
|
28
|
-
target_class.find_by!(id: params["#{target_type.to_resource_name}_id"])
|
29
|
+
target_class.find_by!(id: params["#{target_type.to_resource_name[/([^\/]+)$/]}_id"])
|
29
30
|
else
|
30
|
-
render
|
31
|
+
render status: 400, json: error_response(code: 400, message: "Invalid parameter", type: "Parameter is missing or the value is empty: target_type")
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -37,12 +38,12 @@ module ActivityNotification
|
|
37
38
|
# @return Nil or render HTTP 403 status
|
38
39
|
def validate_target(belonging_model)
|
39
40
|
if @target.present? && belonging_model.target != @target
|
40
|
-
render
|
41
|
+
render status: 403, json: error_response(code: 403, message: "Forbidden because of invalid parameter", type: "Wrong target is specified")
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
# Sets options to load resource index from request parameters.
|
45
|
-
# This method is to be
|
46
|
+
# This method is to be overridden.
|
46
47
|
# @api protected
|
47
48
|
# @return [Hash] options to load resource index
|
48
49
|
def set_index_options
|
@@ -50,7 +51,7 @@ module ActivityNotification
|
|
50
51
|
end
|
51
52
|
|
52
53
|
# Loads resource index with request parameters.
|
53
|
-
# This method is to be
|
54
|
+
# This method is to be overridden.
|
54
55
|
# @api protected
|
55
56
|
# @return [Array] Array of resource index
|
56
57
|
def load_index
|
@@ -58,7 +59,7 @@ module ActivityNotification
|
|
58
59
|
end
|
59
60
|
|
60
61
|
# Returns controller path.
|
61
|
-
# This method is called from target_view_path method and can be
|
62
|
+
# This method is called from target_view_path method and can be overridden.
|
62
63
|
# @api protected
|
63
64
|
# @return [String] "activity_notification" as controller path
|
64
65
|
def controller_path
|
@@ -82,9 +83,46 @@ module ActivityNotification
|
|
82
83
|
lookup_context.prefixes.prepend(target_view_path)
|
83
84
|
end
|
84
85
|
|
86
|
+
# Returns error response as Hash
|
87
|
+
# @api protected
|
88
|
+
# @return [Hash] Error message
|
89
|
+
def error_response(error_info = {})
|
90
|
+
{ gem: "activity_notification", error: error_info }
|
91
|
+
end
|
92
|
+
|
93
|
+
# Render Resource Not Found error with 404 status
|
94
|
+
# @api protected
|
95
|
+
# @return [void]
|
96
|
+
def render_resource_not_found(error = nil)
|
97
|
+
message_type = error.respond_to?(:message) ? error.message : error
|
98
|
+
render status: 404, json: error_response(code: 404, message: "Resource not found", type: message_type)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Render Invalid Parameter error with 400 status
|
102
|
+
# @api protected
|
103
|
+
# @return [void]
|
104
|
+
def render_invalid_parameter(message)
|
105
|
+
render status: 400, json: error_response(code: 400, message: "Invalid parameter", type: message)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Validate param and return HTTP 400 unless it presents.
|
109
|
+
# @api protected
|
110
|
+
# @param [String, Symbol] param_name Parameter name to validate
|
111
|
+
# @return [void]
|
112
|
+
def validate_param(param_name)
|
113
|
+
render_invalid_parameter("Parameter is missing: #{param_name}") if params[param_name].blank?
|
114
|
+
end
|
115
|
+
|
116
|
+
# Render Invalid Parameter error with 400 status
|
117
|
+
# @api protected
|
118
|
+
# @return [void]
|
119
|
+
def render_unprocessable_entity(message)
|
120
|
+
render status: 422, json: error_response(code: 422, message: "Unprocessable entity", type: message)
|
121
|
+
end
|
122
|
+
|
85
123
|
# Returns JavaScript view for ajax request or redirects to back as default.
|
86
124
|
# @api protected
|
87
|
-
# @return [
|
125
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
88
126
|
def return_back_or_ajax
|
89
127
|
set_index_options
|
90
128
|
respond_to do |format|
|
@@ -92,27 +130,9 @@ module ActivityNotification
|
|
92
130
|
load_index if params[:reload].to_s.to_boolean(true)
|
93
131
|
format.js
|
94
132
|
else
|
95
|
-
|
133
|
+
redirect_back(fallback_location: { action: :index }, **@index_options) and return
|
96
134
|
end
|
97
135
|
end
|
98
136
|
end
|
99
|
-
|
100
|
-
# Redirect to back.
|
101
|
-
# @api protected
|
102
|
-
# @return [Boolean] True
|
103
|
-
def compatibly_redirect_back(request_params = {})
|
104
|
-
# :skip-rails4:
|
105
|
-
if Rails::VERSION::MAJOR >= 5
|
106
|
-
redirect_back fallback_location: { action: :index }, **request_params
|
107
|
-
# :skip-rails4:
|
108
|
-
# :skip-rails5:
|
109
|
-
elsif request.referer
|
110
|
-
redirect_to :back, **request_params
|
111
|
-
else
|
112
|
-
redirect_to action: :index, **request_params
|
113
|
-
end
|
114
|
-
# :skip-rails5:
|
115
|
-
true
|
116
|
-
end
|
117
137
|
end
|
118
138
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::ErrorResponses #:nodoc:
|
3
|
+
module InvalidParameterError #:nodoc:
|
4
|
+
def self.extended(base)
|
5
|
+
base.response 400 do
|
6
|
+
key :description, "Invalid parameter"
|
7
|
+
content 'application/json' do
|
8
|
+
schema do
|
9
|
+
key :'$ref', :Error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ForbiddenError #:nodoc:
|
17
|
+
def self.extended(base)
|
18
|
+
base.response 403 do
|
19
|
+
key :description, "Forbidden because of invalid parameter"
|
20
|
+
content 'application/json' do
|
21
|
+
schema do
|
22
|
+
key :'$ref', :Error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module ResourceNotFoundError #:nodoc:
|
30
|
+
def self.extended(base)
|
31
|
+
base.response 404 do
|
32
|
+
key :description, "Resource not found"
|
33
|
+
content 'application/json' do
|
34
|
+
schema do
|
35
|
+
key :'$ref', :Error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module UnprocessableEntityError #:nodoc:
|
43
|
+
def self.extended(base)
|
44
|
+
base.response 422 do
|
45
|
+
key :description, "Unprocessable entity"
|
46
|
+
content 'application/json' do
|
47
|
+
schema do
|
48
|
+
key :'$ref', :Error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::NotificationsApi #:nodoc:
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ::Swagger::Blocks
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Swagger::ErrorSchema
|
8
|
+
|
9
|
+
swagger_path '/{target_type}/{target_id}/notifications' do
|
10
|
+
operation :get do
|
11
|
+
key :summary, 'Get notifications'
|
12
|
+
key :description, 'Returns notification index of the target.'
|
13
|
+
key :operationId, 'getNotifications'
|
14
|
+
key :tags, ['notifications']
|
15
|
+
|
16
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
17
|
+
parameter do
|
18
|
+
key :name, :filter
|
19
|
+
key :in, :query
|
20
|
+
key :description, "Filter option to load notification index by their status"
|
21
|
+
key :required, false
|
22
|
+
key :type, :string
|
23
|
+
key :enum, ['auto', 'opened', 'unopened']
|
24
|
+
key :default, 'auto'
|
25
|
+
end
|
26
|
+
parameter do
|
27
|
+
key :name, :limit
|
28
|
+
key :in, :query
|
29
|
+
key :description, "Maximum number of notifications to return"
|
30
|
+
key :required, false
|
31
|
+
key :type, :integer
|
32
|
+
end
|
33
|
+
parameter do
|
34
|
+
key :name, :reverse
|
35
|
+
key :in, :query
|
36
|
+
key :description, "Whether notification index will be ordered as earliest first"
|
37
|
+
key :required, false
|
38
|
+
key :type, :boolean
|
39
|
+
key :default, false
|
40
|
+
end
|
41
|
+
parameter do
|
42
|
+
key :name, :without_grouping
|
43
|
+
key :in, :query
|
44
|
+
key :description, "Whether notification index will include group members, same as 'with_group_members'"
|
45
|
+
key :required, false
|
46
|
+
key :type, :boolean
|
47
|
+
key :default, false
|
48
|
+
key :example, true
|
49
|
+
end
|
50
|
+
parameter do
|
51
|
+
key :name, :with_group_members
|
52
|
+
key :in, :query
|
53
|
+
key :description, "Whether notification index will include group members, same as 'without_grouping'"
|
54
|
+
key :required, false
|
55
|
+
key :type, :boolean
|
56
|
+
key :default, false
|
57
|
+
end
|
58
|
+
extend Swagger::NotificationsParameters::FilterByParameters
|
59
|
+
|
60
|
+
response 200 do
|
61
|
+
key :description, "Notification index of the target"
|
62
|
+
content 'application/json' do
|
63
|
+
schema do
|
64
|
+
key :type, :object
|
65
|
+
property :count do
|
66
|
+
key :type, :integer
|
67
|
+
key :description, "Number of notification index records"
|
68
|
+
key :example, 1
|
69
|
+
end
|
70
|
+
property :notifications do
|
71
|
+
key :type, :array
|
72
|
+
items do
|
73
|
+
key :'$ref', :Notification
|
74
|
+
end
|
75
|
+
key :description, "Notification index, which means array of notifications of the target"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
81
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
swagger_path '/{target_type}/{target_id}/notifications/open_all' do
|
86
|
+
operation :post do
|
87
|
+
key :summary, 'Open all notifications'
|
88
|
+
key :description, 'Opens all notifications of the target.'
|
89
|
+
key :operationId, 'openAllNotifications'
|
90
|
+
key :tags, ['notifications']
|
91
|
+
|
92
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
93
|
+
extend Swagger::NotificationsParameters::FilterByParameters
|
94
|
+
|
95
|
+
response 200 do
|
96
|
+
key :description, "Opened notifications"
|
97
|
+
content 'application/json' do
|
98
|
+
schema do
|
99
|
+
key :type, :object
|
100
|
+
property :count do
|
101
|
+
key :type, :integer
|
102
|
+
key :description, "Number of opened notification records"
|
103
|
+
key :example, 1
|
104
|
+
end
|
105
|
+
property :notifications do
|
106
|
+
key :type, :array
|
107
|
+
items do
|
108
|
+
key :'$ref', :Notification
|
109
|
+
end
|
110
|
+
key :description, "Opened notifications"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
116
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
swagger_path '/{target_type}/{target_id}/notifications/{id}' do
|
121
|
+
operation :get do
|
122
|
+
key :summary, 'Get notification'
|
123
|
+
key :description, 'Returns a single notification.'
|
124
|
+
key :operationId, 'getNotification'
|
125
|
+
key :tags, ['notifications']
|
126
|
+
|
127
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
128
|
+
extend Swagger::NotificationsParameters::IdParameter
|
129
|
+
|
130
|
+
response 200 do
|
131
|
+
key :description, "Found single notification"
|
132
|
+
content 'application/json' do
|
133
|
+
schema do
|
134
|
+
key :'$ref', :Notification
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
139
|
+
extend Swagger::ErrorResponses::ForbiddenError
|
140
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
141
|
+
end
|
142
|
+
|
143
|
+
operation :delete do
|
144
|
+
key :summary, 'Delete notification'
|
145
|
+
key :description, 'Deletes a notification.'
|
146
|
+
key :operationId, 'deleteNotification'
|
147
|
+
key :tags, ['notifications']
|
148
|
+
|
149
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
150
|
+
extend Swagger::NotificationsParameters::IdParameter
|
151
|
+
|
152
|
+
response 204 do
|
153
|
+
key :description, "No content as successfully deleted"
|
154
|
+
end
|
155
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
156
|
+
extend Swagger::ErrorResponses::ForbiddenError
|
157
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
swagger_path '/{target_type}/{target_id}/notifications/{id}/open' do
|
162
|
+
operation :put do
|
163
|
+
key :summary, 'Open notification'
|
164
|
+
key :description, 'Opens a notification.'
|
165
|
+
key :operationId, 'openNotification'
|
166
|
+
key :tags, ['notifications']
|
167
|
+
|
168
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
169
|
+
extend Swagger::NotificationsParameters::IdParameter
|
170
|
+
parameter do
|
171
|
+
key :name, :move
|
172
|
+
key :in, :query
|
173
|
+
key :description, "Whether it redirects to notifiable_path after the notification is opened"
|
174
|
+
key :required, false
|
175
|
+
key :type, :boolean
|
176
|
+
key :default, false
|
177
|
+
end
|
178
|
+
|
179
|
+
response 200 do
|
180
|
+
key :description, "Opened notification"
|
181
|
+
content 'application/json' do
|
182
|
+
schema do
|
183
|
+
key :type, :object
|
184
|
+
property :count do
|
185
|
+
key :type, :integer
|
186
|
+
key :description, "Number of opened notification records"
|
187
|
+
key :example, 2
|
188
|
+
end
|
189
|
+
property :notification do
|
190
|
+
key :type, :object
|
191
|
+
key :'$ref', :Notification
|
192
|
+
key :description, "Opened notification"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
response 302 do
|
198
|
+
key :description, "Opened notification and redirection to notifiable_path"
|
199
|
+
content 'application/json' do
|
200
|
+
schema do
|
201
|
+
key :type, :object
|
202
|
+
property :location do
|
203
|
+
key :type, :string
|
204
|
+
key :format, :uri
|
205
|
+
key :description, "notifiable_path for redirection"
|
206
|
+
end
|
207
|
+
property :count do
|
208
|
+
key :type, :integer
|
209
|
+
key :description, "Number of opened notification records"
|
210
|
+
key :example, 2
|
211
|
+
end
|
212
|
+
property :notification do
|
213
|
+
key :type, :object
|
214
|
+
key :'$ref', :Notification
|
215
|
+
key :description, "Opened notification"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
221
|
+
extend Swagger::ErrorResponses::ForbiddenError
|
222
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
swagger_path '/{target_type}/{target_id}/notifications/{id}/move' do
|
227
|
+
operation :get do
|
228
|
+
key :summary, 'Move to notifiable_path'
|
229
|
+
key :description, 'Moves to notifiable_path of the notification.'
|
230
|
+
key :operationId, 'moveNotification'
|
231
|
+
key :tags, ['notifications']
|
232
|
+
|
233
|
+
extend Swagger::NotificationsParameters::TargetParameters
|
234
|
+
extend Swagger::NotificationsParameters::IdParameter
|
235
|
+
parameter do
|
236
|
+
key :name, :open
|
237
|
+
key :in, :query
|
238
|
+
key :description, "Whether the notification will be opened"
|
239
|
+
key :required, false
|
240
|
+
key :type, :boolean
|
241
|
+
key :default, false
|
242
|
+
end
|
243
|
+
|
244
|
+
response 302 do
|
245
|
+
key :description, "Redirection to notifiable path"
|
246
|
+
content 'application/json' do
|
247
|
+
schema do
|
248
|
+
property :location do
|
249
|
+
key :type, :string
|
250
|
+
key :format, :uri
|
251
|
+
key :description, "Notifiable path for redirection"
|
252
|
+
end
|
253
|
+
property :count do
|
254
|
+
key :type, :integer
|
255
|
+
key :description, "Number of opened notification records"
|
256
|
+
key :example, 2
|
257
|
+
end
|
258
|
+
property :notification do
|
259
|
+
key :type, :object
|
260
|
+
key :'$ref', :Notification
|
261
|
+
key :description, "Found notification to move"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
extend Swagger::ErrorResponses::InvalidParameterError
|
267
|
+
extend Swagger::ErrorResponses::ForbiddenError
|
268
|
+
extend Swagger::ErrorResponses::ResourceNotFoundError
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::NotificationsParameters #:nodoc:
|
3
|
+
module TargetParameters #:nodoc:
|
4
|
+
def self.extended(base)
|
5
|
+
base.parameter do
|
6
|
+
key :name, :target_type
|
7
|
+
key :in, :path
|
8
|
+
key :description, "Target type of notifications: e.g. 'users'"
|
9
|
+
key :required, true
|
10
|
+
key :type, :string
|
11
|
+
key :example, "users"
|
12
|
+
end
|
13
|
+
base.parameter do
|
14
|
+
key :name, :target_id
|
15
|
+
key :in, :path
|
16
|
+
key :description, "Target ID of notifications. This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
17
|
+
key :required, true
|
18
|
+
key :type, :string
|
19
|
+
key :example, 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module IdParameter #:nodoc:
|
25
|
+
def self.extended(base)
|
26
|
+
base.parameter do
|
27
|
+
key :name, :id
|
28
|
+
key :in, :path
|
29
|
+
key :description, 'ID of notification record. This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs.'
|
30
|
+
key :required, true
|
31
|
+
key :type, :string
|
32
|
+
key :example, 123
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module FilterByParameters #:nodoc:
|
38
|
+
def self.extended(base)
|
39
|
+
base.parameter do
|
40
|
+
key :name, :filtered_by_type
|
41
|
+
key :in, :query
|
42
|
+
key :description, "Notifiable type to filter notification index: e.g. 'Comment'"
|
43
|
+
key :required, false
|
44
|
+
key :type, :string
|
45
|
+
key :example, "Comment"
|
46
|
+
end
|
47
|
+
base.parameter do
|
48
|
+
key :name, :filtered_by_group_type
|
49
|
+
key :in, :query
|
50
|
+
key :description, "Group type to filter notification index, valid with 'filtered_by_group_id': e.g. 'Article'"
|
51
|
+
key :required, false
|
52
|
+
key :type, :string
|
53
|
+
key :example, "Article"
|
54
|
+
end
|
55
|
+
base.parameter do
|
56
|
+
key :name, :filtered_by_group_id
|
57
|
+
key :in, :query
|
58
|
+
key :description, "Group instance ID to filter notification index, valid with 'filtered_by_group_type'"
|
59
|
+
key :required, false
|
60
|
+
key :type, :string
|
61
|
+
key :example, 2
|
62
|
+
end
|
63
|
+
base.parameter do
|
64
|
+
key :name, :filtered_by_key
|
65
|
+
key :in, :query
|
66
|
+
key :description, "Key of notifications to filter notification index: e.g. 'comment.default'"
|
67
|
+
key :required, false
|
68
|
+
key :type, :string
|
69
|
+
key :example, "comment.default"
|
70
|
+
end
|
71
|
+
base.parameter do
|
72
|
+
key :name, :later_than
|
73
|
+
key :in, :query
|
74
|
+
key :description, "ISO 8601 format time to filter notification index later than specified time"
|
75
|
+
key :required, false
|
76
|
+
key :type, :string
|
77
|
+
key :format, :'date-time'
|
78
|
+
key :example, Time.current.ago(10.years).iso8601(3)
|
79
|
+
end
|
80
|
+
base.parameter do
|
81
|
+
key :name, :earlier_than
|
82
|
+
key :in, :query
|
83
|
+
key :description, "ISO 8601 format time to filter notification index earlier than specified time"
|
84
|
+
key :required, false
|
85
|
+
key :type, :string
|
86
|
+
key :format, :'date-time'
|
87
|
+
key :example, Time.current.since(10.years).iso8601(3)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|