activity_notification 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/.gitignore +10 -3
- data/.travis.yml +6 -5
- data/CHANGELOG.md +22 -0
- data/Gemfile +8 -2
- data/Procfile +1 -1
- data/README.md +153 -1510
- data/activity_notification.gemspec +4 -1
- 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 +1 -1
- data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
- 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 +79 -53
- 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 +78 -69
- data/app/views/activity_notification/notifications/default/_default.html.erb +18 -18
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +14 -14
- data/app/views/activity_notification/notifications/default/index.html.erb +6 -6
- data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +3 -31
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +7 -7
- data/app/views/activity_notification/subscriptions/default/index.html.erb +11 -7
- data/bin/deploy_on_heroku.sh +3 -1
- data/docs/CODE_OF_CONDUCT.md +76 -0
- data/docs/CONTRIBUTING.md +36 -0
- data/docs/Functions.md +1130 -0
- data/docs/Setup.md +674 -0
- data/docs/Testing.md +148 -0
- data/gemfiles/Gemfile.rails-4.2 +3 -0
- data/gemfiles/Gemfile.rails-5.0 +3 -0
- data/gemfiles/Gemfile.rails-5.1 +3 -0
- data/gemfiles/Gemfile.rails-5.2 +3 -0
- data/gemfiles/{Gemfile.rails-6.0.rc → Gemfile.rails-6.0} +5 -3
- data/lib/activity_notification.rb +13 -1
- data/lib/activity_notification/apis/notification_api.rb +29 -92
- data/lib/activity_notification/apis/subscription_api.rb +20 -8
- data/lib/activity_notification/apis/swagger.rb +6 -0
- data/lib/activity_notification/config.rb +41 -21
- data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
- data/lib/activity_notification/controllers/common_controller.rb +44 -20
- 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 +7 -6
- data/lib/activity_notification/gem_version.rb +14 -0
- data/lib/activity_notification/helpers/errors.rb +2 -0
- data/lib/activity_notification/helpers/view_helpers.rb +4 -0
- data/lib/activity_notification/mailers/helpers.rb +17 -10
- data/lib/activity_notification/models/concerns/notifiable.rb +26 -10
- data/lib/activity_notification/models/concerns/subscriber.rb +12 -1
- 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 +36 -10
- data/lib/activity_notification/models/notification.rb +1 -0
- data/lib/activity_notification/models/subscription.rb +1 -0
- 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 +7 -13
- data/lib/activity_notification/orm/active_record/notification.rb +17 -1
- data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
- data/lib/activity_notification/orm/dynamoid.rb +28 -0
- data/lib/activity_notification/orm/dynamoid/extension.rb +79 -1
- data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
- data/lib/activity_notification/orm/mongoid.rb +22 -0
- data/lib/activity_notification/orm/mongoid/notification.rb +17 -1
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/rails/routes.rb +132 -48
- data/lib/activity_notification/renderable.rb +13 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +38 -20
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -1
- data/lib/generators/templates/activity_notification.rb +8 -0
- 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/models/README +8 -4
- data/lib/generators/templates/models/notification.rb +1 -1
- data/lib/generators/templates/models/subscription.rb +1 -1
- data/package.json +8 -0
- data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_api_channel_spec.rb +51 -0
- data/spec/channels/notification_api_with_devise_channel_spec.rb +78 -0
- data/spec/concerns/apis/notification_api_spec.rb +37 -2
- data/spec/concerns/models/notifiable_spec.rb +64 -0
- data/spec/concerns/models/subscriber_spec.rb +13 -16
- data/spec/concerns/models/target_spec.rb +32 -0
- data/spec/concerns/renderable_spec.rb +2 -2
- data/spec/controllers/controller_spec_utility.rb +136 -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 +54 -79
- data/spec/controllers/notifications_controller_spec.rb +1 -2
- data/spec/controllers/notifications_with_devise_controller_spec.rb +3 -12
- 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 +94 -121
- data/spec/controllers/subscriptions_controller_spec.rb +1 -2
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +3 -12
- data/spec/helpers/view_helpers_spec.rb +4 -11
- data/spec/mailers/mailer_spec.rb +41 -0
- data/spec/models/notification_spec.rb +17 -0
- data/spec/models/subscription_spec.rb +0 -13
- data/spec/optional_targets/action_cable_api_channel_spec.rb +37 -0
- data/spec/optional_targets/action_cable_channel_spec.rb +44 -0
- data/spec/optional_targets/amazon_sns_spec.rb +0 -2
- data/spec/optional_targets/slack_spec.rb +0 -2
- data/spec/rails_app/Rakefile +9 -0
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/images/.keep +0 -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 -3
- 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 +21 -0
- data/spec/rails_app/app/javascript/App.vue +104 -0
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +83 -0
- data/spec/rails_app/app/javascript/components/Top.vue +99 -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 +11 -0
- data/spec/rails_app/app/javascript/store/auth.js +37 -0
- data/spec/rails_app/app/models/admin.rb +16 -15
- data/spec/rails_app/app/models/article.rb +26 -21
- data/spec/rails_app/app/models/comment.rb +24 -71
- data/spec/rails_app/app/models/user.rb +43 -20
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
- data/spec/rails_app/app/views/articles/index.html.erb +51 -7
- data/spec/rails_app/app/views/articles/show.html.erb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +8 -10
- 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 +15 -2
- data/spec/rails_app/config/environment.rb +2 -1
- data/spec/rails_app/config/environments/development.rb +5 -0
- data/spec/rails_app/config/environments/production.rb +3 -0
- data/spec/rails_app/config/environments/test.rb +5 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +8 -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 +2 -2
- data/spec/rails_app/config/routes.rb +33 -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/20191201000000_add_tokens_to_users.rb +10 -0
- data/spec/rails_app/db/schema.rb +4 -1
- data/spec/rails_app/db/seeds.rb +1 -0
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
- 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 +1 -3
- data/spec/roles/acts_as_notifier_spec.rb +0 -2
- data/spec/roles/acts_as_target_spec.rb +0 -4
- data/spec/spec_helper.rb +7 -15
- data/spec/version_spec.rb +31 -0
- metadata +187 -13
@@ -0,0 +1,50 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::SubscriptionsParameters #: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 subscriptions: 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 subscriptions. 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 subscription 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_key
|
41
|
+
key :in, :query
|
42
|
+
key :description, "Key of subscriptions to filter subscription index: e.g. 'comment.default'"
|
43
|
+
key :required, false
|
44
|
+
key :type, :string
|
45
|
+
key :example, "comment.default"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -2,6 +2,7 @@ module ActivityNotification
|
|
2
2
|
# Module included in controllers to authenticate with Devise module
|
3
3
|
module DeviseAuthenticationController
|
4
4
|
extend ActiveSupport::Concern
|
5
|
+
include CommonController
|
5
6
|
|
6
7
|
included do
|
7
8
|
prepend_before_action :authenticate_devise_resource!
|
@@ -13,17 +14,17 @@ module ActivityNotification
|
|
13
14
|
# Authenticate devise resource by Devise (e.g. calling authenticate_user! method).
|
14
15
|
# @api protected
|
15
16
|
# @todo Needs to call authenticate method by more secure way
|
16
|
-
# @return [
|
17
|
+
# @return [Response] Redirects for unsigned in target by Devise, returns HTTP 403 without neccesary target method or returns 400 when request parameters are not enough
|
17
18
|
def authenticate_devise_resource!
|
18
19
|
if params[:devise_type].present?
|
19
20
|
authenticate_method_name = "authenticate_#{params[:devise_type].to_resource_name}!"
|
20
21
|
if respond_to?(authenticate_method_name)
|
21
22
|
send(authenticate_method_name)
|
22
23
|
else
|
23
|
-
render
|
24
|
+
render status: 403, json: error_response(code: 403, message: "Unauthenticated with Devise")
|
24
25
|
end
|
25
26
|
else
|
26
|
-
render
|
27
|
+
render status: 400, json: error_response(code: 400, message: "Invalid parameter", type: "Missing devise_type")
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -38,7 +39,7 @@ module ActivityNotification
|
|
38
39
|
target_class = target_type.to_model_class
|
39
40
|
current_resource_method_name = "current_#{params[:devise_type].to_resource_name}"
|
40
41
|
params[:target_id] = target_class.resolve_current_devise_target(send(current_resource_method_name))
|
41
|
-
render(
|
42
|
+
render status: 403, json: error_response(code: 403, message: "Unauthenticated as default target") and return if params[:target_id].blank?
|
42
43
|
end
|
43
44
|
super
|
44
45
|
end
|
@@ -46,11 +47,11 @@ module ActivityNotification
|
|
46
47
|
# Authenticate the target of requested notification with authenticated devise resource.
|
47
48
|
# @api protected
|
48
49
|
# @todo Needs to call authenticate method by more secure way
|
49
|
-
# @return [
|
50
|
+
# @return [Response] Returns HTTP 403 for unauthorized target
|
50
51
|
def authenticate_target!
|
51
52
|
current_resource_method_name = "current_#{params[:devise_type].to_resource_name}"
|
52
53
|
unless @target.authenticated_with_devise?(send(current_resource_method_name))
|
53
|
-
render
|
54
|
+
render status: 403, json: error_response(code: 403, message: "Unauthorized target")
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
# Returns the version of the currently loaded ActivityNotification as a Gem::Version
|
3
|
+
def self.gem_version
|
4
|
+
Gem::Version.new VERSION
|
5
|
+
end
|
6
|
+
|
7
|
+
# Manages individual gem version from Gem::Version
|
8
|
+
module GEM_VERSION
|
9
|
+
MAJOR = VERSION.split(".")[0]
|
10
|
+
MINOR = VERSION.split(".")[1]
|
11
|
+
TINY = VERSION.split(".")[2]
|
12
|
+
PRE = VERSION.split(".")[3]
|
13
|
+
end
|
14
|
+
end
|
@@ -13,6 +13,8 @@ module ActivityNotification
|
|
13
13
|
# @option options [String] :layout (nil) Layout template name
|
14
14
|
# @option options [String] :layout_root ('layouts') Root path of layout template
|
15
15
|
# @option options [String, Symbol] :fallback (nil) Fallback template to use when MissingTemplate is raised. Set :text to use i18n text as fallback.
|
16
|
+
# @option options [Hash] :assigns (nil) Parameters to be set as assigns
|
17
|
+
# @option options [Hash] :locals (nil) Parameters to be set as locals
|
16
18
|
# @return [String] Rendered view or text as string
|
17
19
|
def render_notification(notifications, options = {})
|
18
20
|
if notifications.is_a? ActivityNotification::Notification
|
@@ -51,6 +53,8 @@ module ActivityNotification
|
|
51
53
|
# @option options [String] :filtered_by_group_type (nil) Group type for filter, valid with :filtered_by_group_id
|
52
54
|
# @option options [String] :filtered_by_group_id (nil) Group instance id for filter, valid with :filtered_by_group_type
|
53
55
|
# @option options [String] :filtered_by_key (nil) Key of the notification for filter
|
56
|
+
# @option options [String] :later_than (nil) ISO 8601 format time to filter notification index later than specified time
|
57
|
+
# @option options [String] :earlier_than (nil) ISO 8601 format time to filter notification index earlier than specified time
|
54
58
|
# @option options [Array] :custom_filter (nil) Custom notification filter (e.g. ["created_at >= ?", time.hour.ago])
|
55
59
|
# @return [String] Rendered view or text as string
|
56
60
|
def render_notification_of(target, options = {})
|
@@ -58,21 +58,28 @@ module ActivityNotification
|
|
58
58
|
@notification.notifiable.overriding_notification_email_key(@target, key).present?
|
59
59
|
key = @notification.notifiable.overriding_notification_email_key(@target, key)
|
60
60
|
end
|
61
|
-
if @notification.notifiable.respond_to?(:overriding_notification_email_subject) &&
|
62
|
-
@notification.notifiable.overriding_notification_email_subject(@target, key).present?
|
63
|
-
subject = @notification.notifiable.overriding_notification_email_subject(@target, key)
|
64
|
-
else
|
65
|
-
subject = subject_for(key)
|
66
|
-
end
|
67
61
|
headers = {
|
68
|
-
subject: subject,
|
69
62
|
to: mailer_to(@target),
|
70
|
-
from: mailer_from(key),
|
71
|
-
reply_to: mailer_reply_to(key),
|
72
63
|
template_path: template_paths,
|
73
64
|
template_name: template_name(key)
|
74
65
|
}.merge(options)
|
75
|
-
|
66
|
+
{
|
67
|
+
subject: :subject_for,
|
68
|
+
from: :mailer_from,
|
69
|
+
reply_to: :mailer_reply_to,
|
70
|
+
message_id: nil
|
71
|
+
}.each do |header_name, default_method|
|
72
|
+
overridding_method_name = "overriding_notification_email_#{header_name.to_s}"
|
73
|
+
header_value = if @notification.notifiable.respond_to?(overridding_method_name) &&
|
74
|
+
@notification.notifiable.send(overridding_method_name, @target, key).present?
|
75
|
+
@notification.notifiable.send(overridding_method_name, @target, key)
|
76
|
+
elsif default_method
|
77
|
+
send(default_method, key)
|
78
|
+
else
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
headers[header_name] = header_value if header_value
|
82
|
+
end
|
76
83
|
@email = headers[:to]
|
77
84
|
headers
|
78
85
|
end
|
@@ -26,6 +26,7 @@ module ActivityNotification
|
|
26
26
|
:_notification_parameters,
|
27
27
|
:_notification_email_allowed,
|
28
28
|
:_notification_action_cable_allowed,
|
29
|
+
:_notification_action_cable_api_allowed,
|
29
30
|
:_notifiable_path,
|
30
31
|
:_printable_notifiable_name,
|
31
32
|
:_optional_targets
|
@@ -48,16 +49,17 @@ module ActivityNotification
|
|
48
49
|
# Sets default values to notifiable class fields.
|
49
50
|
# @return [NilClass] nil
|
50
51
|
def set_notifiable_class_defaults
|
51
|
-
self._notification_targets
|
52
|
-
self._notification_group
|
53
|
-
self._notification_group_expiry_delay
|
54
|
-
self._notifier
|
55
|
-
self._notification_parameters
|
56
|
-
self._notification_email_allowed
|
57
|
-
self._notification_action_cable_allowed
|
58
|
-
self.
|
59
|
-
self.
|
60
|
-
self.
|
52
|
+
self._notification_targets = {}
|
53
|
+
self._notification_group = {}
|
54
|
+
self._notification_group_expiry_delay = {}
|
55
|
+
self._notifier = {}
|
56
|
+
self._notification_parameters = {}
|
57
|
+
self._notification_email_allowed = {}
|
58
|
+
self._notification_action_cable_allowed = {}
|
59
|
+
self._notification_action_cable_api_allowed = {}
|
60
|
+
self._notifiable_path = {}
|
61
|
+
self._printable_notifiable_name = {}
|
62
|
+
self._optional_targets = {}
|
61
63
|
nil
|
62
64
|
end
|
63
65
|
end
|
@@ -168,6 +170,20 @@ module ActivityNotification
|
|
168
170
|
target, key)
|
169
171
|
end
|
170
172
|
|
173
|
+
# Returns if publishing WebSocket API using ActionCable is allowed for the notifiable from configured field or overridden method.
|
174
|
+
# This method is able to be overridden.
|
175
|
+
#
|
176
|
+
# @param [Object] target Target instance to notify
|
177
|
+
# @param [String] key Key of the notification
|
178
|
+
# @return [Boolean] If publishing WebSocket API using ActionCable is allowed for the notifiable
|
179
|
+
def notification_action_cable_api_allowed?(target, key = nil)
|
180
|
+
resolve_parameter(
|
181
|
+
"notification_action_cable_api_allowed_for_#{cast_to_resources_name(target.class)}?",
|
182
|
+
_notification_action_cable_api_allowed[cast_to_resources_sym(target.class)],
|
183
|
+
ActivityNotification.config.action_cable_api_enabled,
|
184
|
+
target, key)
|
185
|
+
end
|
186
|
+
|
171
187
|
# Returns notifiable_path to move after opening notification from configured field or overridden method.
|
172
188
|
# This method is able to be overridden.
|
173
189
|
#
|
@@ -46,8 +46,19 @@ module ActivityNotification
|
|
46
46
|
# Creates new subscription of the target.
|
47
47
|
#
|
48
48
|
# @param [Hash] subscription_params Parameters to create subscription record
|
49
|
+
# @raise [ActivityNotification::RecordInvalidError] Failed to save subscription due to model validation
|
49
50
|
# @return [Subscription] Created subscription instance
|
50
51
|
def create_subscription(subscription_params = {})
|
52
|
+
subscription = build_subscription(subscription_params)
|
53
|
+
raise RecordInvalidError, subscription.errors.full_messages.first unless subscription.save
|
54
|
+
subscription
|
55
|
+
end
|
56
|
+
|
57
|
+
# Builds new subscription of the target.
|
58
|
+
#
|
59
|
+
# @param [Hash] subscription_params Parameters to build subscription record
|
60
|
+
# @return [Subscription] Built subscription instance
|
61
|
+
def build_subscription(subscription_params = {})
|
51
62
|
created_at = Time.current
|
52
63
|
if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
|
53
64
|
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
|
@@ -74,7 +85,7 @@ module ActivityNotification
|
|
74
85
|
)
|
75
86
|
end
|
76
87
|
subscription.assign_attributes(optional_targets: optional_targets)
|
77
|
-
subscription
|
88
|
+
subscription
|
78
89
|
end
|
79
90
|
|
80
91
|
# Gets configured subscription index of the target.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::ErrorSchema #:nodoc:
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ::Swagger::Blocks
|
5
|
+
|
6
|
+
included do
|
7
|
+
swagger_component do
|
8
|
+
schema :Error do
|
9
|
+
key :required, [:gem, :error]
|
10
|
+
property :gem do
|
11
|
+
key :type, :string
|
12
|
+
key :description, "Name of gem generating this error"
|
13
|
+
key :default, "activity_notification"
|
14
|
+
key :example, "activity_notification"
|
15
|
+
end
|
16
|
+
property :error do
|
17
|
+
key :type, :object
|
18
|
+
key :description, "Error information"
|
19
|
+
property :code do
|
20
|
+
key :type, :integer
|
21
|
+
key :description, "Error code: default value is HTTP status code"
|
22
|
+
end
|
23
|
+
property :message do
|
24
|
+
key :type, :string
|
25
|
+
key :description, "Error message"
|
26
|
+
end
|
27
|
+
property :type do
|
28
|
+
key :type, :string
|
29
|
+
key :description, "Error type describing error message"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
module ActivityNotification
|
2
|
+
module Swagger::NotificationSchema #:nodoc:
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ::Swagger::Blocks
|
5
|
+
|
6
|
+
included do
|
7
|
+
swagger_component do
|
8
|
+
schema :NotificationAttributes do
|
9
|
+
key :type, :object
|
10
|
+
property :id do
|
11
|
+
key :oneOf, [
|
12
|
+
{ type: :integer },
|
13
|
+
{ type: :string }
|
14
|
+
]
|
15
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
16
|
+
key :example, 123
|
17
|
+
end
|
18
|
+
property :target_type do
|
19
|
+
key :type, :string
|
20
|
+
key :example, "User"
|
21
|
+
end
|
22
|
+
property :target_id do
|
23
|
+
key :oneOf, [
|
24
|
+
{ type: :integer },
|
25
|
+
{ type: :string }
|
26
|
+
]
|
27
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
28
|
+
key :example, 1
|
29
|
+
end
|
30
|
+
property :notifiable_type do
|
31
|
+
key :type, :string
|
32
|
+
key :example, "Comment"
|
33
|
+
end
|
34
|
+
property :notifiable_id do
|
35
|
+
key :oneOf, [
|
36
|
+
{ type: :integer },
|
37
|
+
{ type: :string }
|
38
|
+
]
|
39
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
40
|
+
key :example, 22
|
41
|
+
end
|
42
|
+
property :key do
|
43
|
+
key :type, :string
|
44
|
+
key :example, "comment.default"
|
45
|
+
end
|
46
|
+
property :group_type do
|
47
|
+
key :type, :string
|
48
|
+
key :nullable, true
|
49
|
+
key :example, "Article"
|
50
|
+
end
|
51
|
+
property :group_id do
|
52
|
+
key :oneOf, [
|
53
|
+
{ type: :integer },
|
54
|
+
{ type: :string },
|
55
|
+
{ nullable: true }
|
56
|
+
]
|
57
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
58
|
+
key :nullable, true
|
59
|
+
key :example, 11
|
60
|
+
end
|
61
|
+
property :group_owner_id do
|
62
|
+
key :oneOf, [
|
63
|
+
{ type: :integer },
|
64
|
+
{ type: :string },
|
65
|
+
{ type: :object },
|
66
|
+
{ nullable: true }
|
67
|
+
]
|
68
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string or object including $oid with Mongoid or Dynamoid ORMs."
|
69
|
+
key :nullable, true
|
70
|
+
key :example, 123
|
71
|
+
end
|
72
|
+
property :notifier_type do
|
73
|
+
key :type, :string
|
74
|
+
key :nullable, true
|
75
|
+
key :example, "User"
|
76
|
+
end
|
77
|
+
property :notifier_id do
|
78
|
+
key :oneOf, [
|
79
|
+
{ type: :integer },
|
80
|
+
{ type: :string },
|
81
|
+
{ nullable: true }
|
82
|
+
]
|
83
|
+
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
84
|
+
key :nullable, true
|
85
|
+
key :example, 2
|
86
|
+
end
|
87
|
+
property :parameters do
|
88
|
+
key :type, :object
|
89
|
+
key :additionalProperties, {
|
90
|
+
type: :string
|
91
|
+
}
|
92
|
+
key :example, {
|
93
|
+
"test_default_param": "1"
|
94
|
+
}
|
95
|
+
end
|
96
|
+
property :opened_at do
|
97
|
+
key :type, :string
|
98
|
+
key :format, :'date-time'
|
99
|
+
key :nullable, true
|
100
|
+
end
|
101
|
+
property :created_at do
|
102
|
+
key :type, :string
|
103
|
+
key :format, :'date-time'
|
104
|
+
end
|
105
|
+
property :updated_at do
|
106
|
+
key :type, :string
|
107
|
+
key :format, :'date-time'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
schema :Notification do
|
112
|
+
key :type, :object
|
113
|
+
key :required, [ :id, :target_type, :target_id, :notifiable_type, :notifiable_id, :key, :created_at, :updated_at, :target, :notifiable ]
|
114
|
+
allOf do
|
115
|
+
schema do
|
116
|
+
key :'$ref', :NotificationAttributes
|
117
|
+
end
|
118
|
+
schema do
|
119
|
+
key :type, :object
|
120
|
+
property :notifiable_path do
|
121
|
+
key :type, :string
|
122
|
+
key :format, :uri
|
123
|
+
key :example, "/articles/11"
|
124
|
+
end
|
125
|
+
property :printable_notifiable_name do
|
126
|
+
key :type, :string
|
127
|
+
key :format, :uri
|
128
|
+
key :example, "comment \"This is the first Stephen's comment to Ichiro's article.\""
|
129
|
+
end
|
130
|
+
property :group_member_notifier_count do
|
131
|
+
key :type, :integer
|
132
|
+
key :example, 1
|
133
|
+
end
|
134
|
+
property :group_notification_count do
|
135
|
+
key :type, :integer
|
136
|
+
key :example, 2
|
137
|
+
end
|
138
|
+
property :target do
|
139
|
+
key :type, :object
|
140
|
+
key :description, "Associated target model in your application"
|
141
|
+
key :example, {
|
142
|
+
"id": 1,
|
143
|
+
"email": "ichiro@example.com",
|
144
|
+
"name": "Ichiro",
|
145
|
+
"created_at": Time.current,
|
146
|
+
"updated_at": Time.current,
|
147
|
+
"provider": "email",
|
148
|
+
"uid": "",
|
149
|
+
"printable_type": "User",
|
150
|
+
"printable_target_name": "Ichiro"
|
151
|
+
}
|
152
|
+
end
|
153
|
+
property :notifiable do
|
154
|
+
key :type, :object
|
155
|
+
key :description, "Associated notifiable model in your application"
|
156
|
+
key :example, {
|
157
|
+
"id": 22,
|
158
|
+
"user_id": 2,
|
159
|
+
"article_id": 11,
|
160
|
+
"body": "This is the first Stephen's comment to Ichiro's article.",
|
161
|
+
"created_at": Time.current,
|
162
|
+
"updated_at": Time.current,
|
163
|
+
"printable_type": "Comment"
|
164
|
+
}
|
165
|
+
end
|
166
|
+
property :group do
|
167
|
+
key :type, :object
|
168
|
+
key :description, "Associated group model in your application"
|
169
|
+
key :nullable, true
|
170
|
+
key :example, {
|
171
|
+
"id": 11,
|
172
|
+
"user_id": 4,
|
173
|
+
"title": "Ichiro's great article",
|
174
|
+
"body": "This is Ichiro's great article. Please read it!",
|
175
|
+
"created_at": Time.current,
|
176
|
+
"updated_at": Time.current,
|
177
|
+
"printable_type": "Article",
|
178
|
+
"printable_group_name": "article \"Ichiro's great article\""
|
179
|
+
}
|
180
|
+
end
|
181
|
+
property :notifier do
|
182
|
+
key :type, :object
|
183
|
+
key :description, "Associated notifier model in your application"
|
184
|
+
key :nullable, true
|
185
|
+
key :example, {
|
186
|
+
"id": 2,
|
187
|
+
"email": "stephen@example.com",
|
188
|
+
"name": "Stephen",
|
189
|
+
"created_at": Time.current,
|
190
|
+
"updated_at": Time.current,
|
191
|
+
"provider": "email",
|
192
|
+
"uid": "",
|
193
|
+
"printable_type": "User",
|
194
|
+
"printable_notifier_name": "Stephen"
|
195
|
+
}
|
196
|
+
end
|
197
|
+
property :group_members do
|
198
|
+
key :type, :array
|
199
|
+
items do
|
200
|
+
key :'$ref', :NotificationAttributes
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|