activity_notification 2.1.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -16
  3. data/CHANGELOG.md +53 -0
  4. data/Gemfile +2 -3
  5. data/README.md +1 -1
  6. data/activity_notification.gemspec +1 -1
  7. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +1 -1
  8. data/app/channels/activity_notification/notification_channel.rb +1 -1
  9. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  10. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +1 -1
  11. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  12. data/app/controllers/activity_notification/subscriptions_api_controller.rb +1 -1
  13. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +1 -1
  14. data/bin/bundle_update.sh +0 -1
  15. data/docs/Functions.md +2 -2
  16. data/docs/Setup.md +190 -63
  17. data/gemfiles/Gemfile.rails-5.0 +3 -1
  18. data/gemfiles/Gemfile.rails-5.1 +3 -1
  19. data/gemfiles/Gemfile.rails-5.2 +3 -1
  20. data/gemfiles/Gemfile.rails-6.0 +2 -3
  21. data/gemfiles/Gemfile.rails-6.1 +24 -0
  22. data/lib/activity_notification/apis/notification_api.rb +7 -0
  23. data/lib/activity_notification/common.rb +15 -4
  24. data/lib/activity_notification/controllers/common_controller.rb +2 -18
  25. data/lib/activity_notification/models/concerns/notifiable.rb +12 -12
  26. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +34 -34
  27. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +17 -17
  28. data/lib/activity_notification/models/concerns/target.rb +5 -9
  29. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +1 -1
  30. data/lib/activity_notification/optional_targets/action_cable_channel.rb +1 -1
  31. data/lib/activity_notification/orm/active_record.rb +1 -1
  32. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  33. data/lib/activity_notification/orm/dynamoid.rb +10 -3
  34. data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
  35. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  36. data/lib/activity_notification/orm/mongoid.rb +10 -3
  37. data/lib/activity_notification/orm/mongoid/notification.rb +8 -6
  38. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  39. data/lib/activity_notification/renderable.rb +2 -2
  40. data/lib/activity_notification/roles/acts_as_notifiable.rb +13 -16
  41. data/lib/activity_notification/version.rb +1 -1
  42. data/lib/generators/templates/migrations/migration.rb +1 -1
  43. data/spec/channels/notification_api_channel_spec.rb +42 -44
  44. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  45. data/spec/channels/notification_channel_spec.rb +41 -43
  46. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  47. data/spec/concerns/common_spec.rb +25 -3
  48. data/spec/concerns/models/notifiable_spec.rb +35 -35
  49. data/spec/concerns/models/target_spec.rb +10 -12
  50. data/spec/concerns/renderable_spec.rb +5 -5
  51. data/spec/config_spec.rb +26 -15
  52. data/spec/controllers/controller_spec_utility.rb +15 -51
  53. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  54. data/spec/helpers/view_helpers_spec.rb +1 -1
  55. data/spec/models/subscription_spec.rb +8 -0
  56. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  57. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  58. data/spec/rails_app/app/controllers/users_controller.rb +5 -0
  59. data/spec/rails_app/app/javascript/App.vue +8 -72
  60. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +3 -4
  61. data/spec/rails_app/app/javascript/components/Top.vue +2 -3
  62. data/spec/rails_app/app/javascript/packs/spa.js +6 -3
  63. data/spec/rails_app/app/javascript/router/index.js +73 -0
  64. data/spec/rails_app/app/javascript/store/{auth.js → index.js} +0 -0
  65. data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
  66. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
  67. data/spec/rails_app/app/models/user.rb +2 -1
  68. data/spec/rails_app/config/application.rb +6 -7
  69. data/spec/rails_app/config/dynamoid.rb +11 -3
  70. data/spec/rails_app/config/environments/production.rb +3 -0
  71. data/spec/rails_app/config/environments/test.rb +2 -11
  72. data/spec/rails_app/config/initializers/activity_notification.rb +3 -3
  73. data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
  74. data/spec/rails_app/config/routes.rb +5 -1
  75. data/spec/rails_app/db/seeds.rb +9 -2
  76. data/spec/roles/acts_as_notifiable_spec.rb +5 -5
  77. data/spec/spec_helper.rb +1 -5
  78. metadata +14 -12
  79. data/gemfiles/Gemfile.rails-4.2 +0 -23
  80. data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
@@ -490,20 +490,18 @@ shared_examples_for :target do
490
490
  end
491
491
  end
492
492
 
493
- if Rails::VERSION::MAJOR >= 5
494
- describe "#notification_action_cable_channel_class_name" do
495
- context "when custom_notification_action_cable_with_devise? returns true" do
496
- it "returns ActivityNotification::NotificationWithDeviseChannel" do
497
- described_class._notification_action_cable_with_devise = true
498
- expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationWithDeviseChannel.name)
499
- end
493
+ describe "#notification_action_cable_channel_class_name" do
494
+ context "when custom_notification_action_cable_with_devise? returns true" do
495
+ it "returns ActivityNotification::NotificationWithDeviseChannel" do
496
+ described_class._notification_action_cable_with_devise = true
497
+ expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationWithDeviseChannel.name)
500
498
  end
499
+ end
501
500
 
502
- context "when custom_notification_action_cable_with_devise? returns false" do
503
- it "returns ActivityNotification::NotificationChannel" do
504
- described_class._notification_action_cable_with_devise = false
505
- expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationChannel.name)
506
- end
501
+ context "when custom_notification_action_cable_with_devise? returns false" do
502
+ it "returns ActivityNotification::NotificationChannel" do
503
+ described_class._notification_action_cable_with_devise = false
504
+ expect(test_instance.notification_action_cable_channel_class_name).to eq(ActivityNotification::NotificationChannel.name)
507
505
  end
508
506
  end
509
507
  end
@@ -32,7 +32,7 @@ shared_examples_for :renderable do
32
32
  expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text"))
33
33
  .to eq(params_text_original)
34
34
  expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text",
35
- {article_title: article_title}))
35
+ article_title: article_title))
36
36
  .to eq(params_text_embedded)
37
37
  end
38
38
 
@@ -40,7 +40,7 @@ shared_examples_for :renderable do
40
40
  expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text"))
41
41
  .to eq(group_text_original)
42
42
  expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text",
43
- {notifier_name: notifier_name, group_member_count: group_member_count, group_notification_count: group_notification_count}))
43
+ **{ notifier_name: notifier_name, group_member_count: group_member_count, group_notification_count: group_notification_count }))
44
44
  .to eq(group_text_embedded)
45
45
  end
46
46
 
@@ -50,10 +50,10 @@ shared_examples_for :renderable do
50
50
  expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text")[:other])
51
51
  .to eq(plural_text_original_other)
52
52
  expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
53
- {article_title: article_title, notifier_name: notifier_name, count: 1}))
53
+ **{ article_title: article_title, notifier_name: notifier_name, count: 1 }))
54
54
  .to eq(plural_text_embedded_one)
55
55
  expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
56
- {article_title: article_title, notifier_name: notifier_name, count: group_notification_count}))
56
+ **{ article_title: article_title, notifier_name: notifier_name, count: group_notification_count }))
57
57
  .to eq(plural_text_embedded_other)
58
58
  end
59
59
  end
@@ -126,4 +126,4 @@ shared_examples_for :renderable do
126
126
  # #layout_path
127
127
 
128
128
  end
129
- end
129
+ end
@@ -35,38 +35,49 @@ describe ActivityNotification::Config do
35
35
  describe "config.store_with_associated_records" do
36
36
  let(:target) { create(:confirmed_user) }
37
37
 
38
- context "false as default" do
39
- before do
40
- @notification = create(:notification, target: target)
41
- end
42
-
43
- it "stores notification without associated records" do
44
- expect(@notification.target).to eq(target)
45
- expect { @notification.target_record }.to raise_error(NoMethodError)
46
- end
47
- end
48
-
49
38
  context "when it is configured as true" do
50
39
  if ActivityNotification.config.orm == :active_record
51
40
  it "raises ActivityNotification::ConfigError when you use active_record ORM" do
52
41
  expect { ActivityNotification.config.store_with_associated_records = true }.to raise_error(ActivityNotification::ConfigError)
53
42
  end
54
-
55
43
  else
56
44
  before do
45
+ @original = ActivityNotification.config.store_with_associated_records
57
46
  ActivityNotification.config.store_with_associated_records = true
58
47
  load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
59
48
  @notification = create(:notification, target: target)
60
49
  end
61
50
 
62
51
  after do
63
- ActivityNotification.config.store_with_associated_records = false
52
+ ActivityNotification.config.store_with_associated_records = @original
64
53
  load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
65
54
  end
66
55
 
67
- it "stores notification without associated records" do
56
+ it "stores notification with associated records" do
68
57
  expect(@notification.target).to eq(target)
69
- expect(@notification.target_record).to eq(target.to_json)
58
+ expect(@notification.stored_target["id"].to_s).to eq(target.id.to_s)
59
+ end
60
+ end
61
+ end
62
+
63
+ context "when it is configured as false" do
64
+ before do
65
+ @original = ActivityNotification.config.store_with_associated_records
66
+ ActivityNotification.config.store_with_associated_records = false
67
+ load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
68
+ @notification = create(:notification, target: target)
69
+ end
70
+
71
+ after do
72
+ ActivityNotification.config.store_with_associated_records = @original
73
+ load Rails.root.join("../../lib/activity_notification/orm/#{ActivityNotification.config.orm}/notification.rb").to_s
74
+ end
75
+
76
+ it "does not store notification with associated records" do
77
+ expect(@notification.target).to eq(target)
78
+ begin
79
+ expect(@notification.stored_target).to be_nil
80
+ rescue NoMethodError
70
81
  end
71
82
  end
72
83
  end
@@ -2,43 +2,23 @@ module ActivityNotification
2
2
  module ControllerSpec
3
3
  module RequestUtility
4
4
  def get_with_compatibility action, params, session
5
- if Rails::VERSION::MAJOR <= 4
6
- get action, params, session
7
- else
8
- get action, params: params, session: session
9
- end
5
+ get action, params: params, session: session
10
6
  end
11
7
 
12
8
  def post_with_compatibility action, params, session
13
- if Rails::VERSION::MAJOR <= 4
14
- post action, params, session
15
- else
16
- post action, params: params, session: session
17
- end
9
+ post action, params: params, session: session
18
10
  end
19
11
 
20
12
  def put_with_compatibility action, params, session
21
- if Rails::VERSION::MAJOR <= 4
22
- put action, params, session
23
- else
24
- put action, params: params, session: session
25
- end
13
+ put action, params: params, session: session
26
14
  end
27
15
 
28
16
  def delete_with_compatibility action, params, session
29
- if Rails::VERSION::MAJOR <= 4
30
- delete action, params, session
31
- else
32
- delete action, params: params, session: session
33
- end
17
+ delete action, params: params, session: session
34
18
  end
35
19
 
36
20
  def xhr_with_compatibility method, action, params, session
37
- if Rails::VERSION::MAJOR <= 4
38
- xhr method, action, params, session
39
- else
40
- send method.to_s, action, xhr: true, params: params, session: session
41
- end
21
+ send method.to_s, action, xhr: true, params: params, session: session
42
22
  end
43
23
  end
44
24
 
@@ -76,53 +56,37 @@ module ActivityNotification
76
56
  def api_path
77
57
  "/#{root_path}/#{target_type}/#{test_target.id}"
78
58
  end
79
-
59
+
80
60
  def schema_path
81
- Rails.root.join('..', 'openapi.json')
61
+ Rails.root.join('..', 'openapi.json')
82
62
  end
83
-
63
+
84
64
  def write_schema_file(schema_json)
85
65
  File.open(schema_path, "w") { |file| file.write(schema_json) }
86
66
  end
87
-
67
+
88
68
  def read_schema_file
89
69
  JSON.parse(File.read(schema_path))
90
70
  end
91
71
 
92
72
  def committee_options
93
- @committee_options ||= { schema: Committee::Drivers::load_from_file(schema_path), prefix: root_path, validate_success_only: true }
73
+ @committee_options ||= { schema: Committee::Drivers::load_from_file(schema_path), prefix: root_path, validate_success_only: true, parse_response_by_content_type: false }
94
74
  end
95
75
 
96
76
  def get_with_compatibility path, options = {}
97
- if Rails::VERSION::MAJOR <= 4
98
- get path, options[:params], options[:headers]
99
- else
100
- get path, options
101
- end
77
+ get path, **options
102
78
  end
103
79
 
104
80
  def post_with_compatibility path, options = {}
105
- if Rails::VERSION::MAJOR <= 4
106
- post path, options[:params], options[:headers]
107
- else
108
- post path, options
109
- end
81
+ post path, **options
110
82
  end
111
83
 
112
84
  def put_with_compatibility path, options = {}
113
- if Rails::VERSION::MAJOR <= 4
114
- put path, options[:params], options[:headers]
115
- else
116
- put path, options
117
- end
85
+ put path, **options
118
86
  end
119
87
 
120
88
  def delete_with_compatibility path, options = {}
121
- if Rails::VERSION::MAJOR <= 4
122
- delete path, options[:params], options[:headers]
123
- else
124
- delete path, options
125
- end
89
+ delete path, **options
126
90
  end
127
91
 
128
92
  def assert_all_schema_confirm(response, status)
@@ -133,4 +97,4 @@ module ActivityNotification
133
97
  end
134
98
  end
135
99
  end
136
- end
100
+ end
@@ -31,11 +31,7 @@ describe ActivityNotification::Generators::MigrationGenerator, type: :generator
31
31
  describe 'CreateNotifications migration file' do
32
32
  subject { file(Dir["tmp/db/migrate/*_create_activity_notification_tables.rb"].first.gsub!('tmp/', '')) }
33
33
  it { is_expected.to exist }
34
- if Rails::VERSION::MAJOR >= 5
35
- it { is_expected.to contain(/class CreateActivityNotificationTables < ActiveRecord::Migration\[\d\.\d\]/) }
36
- else
37
- it { is_expected.to contain(/class CreateActivityNotificationTables < ActiveRecord::Migration/) }
38
- end
34
+ it { is_expected.to contain(/class CreateActivityNotificationTables < ActiveRecord::Migration\[\d\.\d\]/) }
39
35
 
40
36
  if ActivityNotification.config.orm == :active_record
41
37
  it 'can be executed to migrate scheme' do
@@ -55,11 +51,7 @@ describe ActivityNotification::Generators::MigrationGenerator, type: :generator
55
51
  describe 'CreateCustomNotifications migration file' do
56
52
  subject { file(Dir["tmp/db/migrate/*_create_custom_notifications.rb"].first.gsub!('tmp/', '')) }
57
53
  it { is_expected.to exist }
58
- if Rails::VERSION::MAJOR >= 5
59
- it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration\[\d\.\d\]/) }
60
- else
61
- it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration/) }
62
- end
54
+ it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration\[\d\.\d\]/) }
63
55
 
64
56
  if ActivityNotification.config.orm == :active_record
65
57
  it 'can be executed to migrate scheme' do
@@ -1,5 +1,5 @@
1
1
  describe ActivityNotification::ViewHelpers, type: :helper do
2
- let(:view_context) { ActionView::Base.new }
2
+ let(:view_context) { ActionView::Base.new(ActionView::LookupContext.new(ActionController::Base.view_paths), [], nil) }
3
3
  let(:notification) {
4
4
  create(:notification, target: create(:confirmed_user))
5
5
  }
@@ -11,6 +11,14 @@ describe ActivityNotification::Subscription, type: :model do
11
11
  subscription = create(:subscription, target: target)
12
12
  expect(subscription.reload.target).to eq(target)
13
13
  end
14
+
15
+ it "several targets can subscribe to the same key" do
16
+ target = create(:confirmed_user)
17
+ target2 = create(:confirmed_user)
18
+ subscription_1 = create(:subscription, target: target, key: 'key.1')
19
+ subscription_2 = create(:subscription, target: target2, key: 'key.1')
20
+ expect(subscription_2).to be_valid
21
+ end
14
22
  end
15
23
 
16
24
  describe "with validation" do
@@ -1,37 +1,34 @@
1
- if Rails::VERSION::MAJOR >= 5
2
- require 'activity_notification/optional_targets/action_cable_api_channel'
3
- describe ActivityNotification::OptionalTarget::ActionCableApiChannel do
4
- let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableApiChannel.new(skip_initializing_target: true) }
1
+ require 'activity_notification/optional_targets/action_cable_api_channel'
2
+ describe ActivityNotification::OptionalTarget::ActionCableApiChannel do
3
+ let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableApiChannel.new(skip_initializing_target: true) }
5
4
 
6
- describe "as public instance methods" do
7
- describe "#to_optional_target_name" do
8
- it "is return demodulized symbol class name" do
9
- expect(test_instance.to_optional_target_name).to eq(:action_cable_api_channel)
10
- end
5
+ describe "as public instance methods" do
6
+ describe "#to_optional_target_name" do
7
+ it "is return demodulized symbol class name" do
8
+ expect(test_instance.to_optional_target_name).to eq(:action_cable_api_channel)
11
9
  end
10
+ end
12
11
 
13
- describe "#initialize_target" do
14
- it "does not raise NotImplementedError" do
15
- test_instance.initialize_target
16
- end
12
+ describe "#initialize_target" do
13
+ it "does not raise NotImplementedError" do
14
+ test_instance.initialize_target
17
15
  end
16
+ end
18
17
 
19
- describe "#notify" do
20
- it "does not raise NotImplementedError" do
21
- test_instance.notify(create(:notification))
22
- end
18
+ describe "#notify" do
19
+ it "does not raise NotImplementedError" do
20
+ test_instance.notify(create(:notification))
23
21
  end
24
22
  end
23
+ end
25
24
 
26
- describe "as protected instance methods" do
27
- describe "#render_notification_message" do
28
- context "as default" do
29
- it "renders notification message as formatted JSON" do
30
- expect(test_instance.send(:render_notification_message, create(:notification)).with_indifferent_access[:notification].has_key?(:id)).to be_truthy
31
- end
25
+ describe "as protected instance methods" do
26
+ describe "#render_notification_message" do
27
+ context "as default" do
28
+ it "renders notification message as formatted JSON" do
29
+ expect(test_instance.send(:render_notification_message, create(:notification)).with_indifferent_access[:notification].has_key?(:id)).to be_truthy
32
30
  end
33
31
  end
34
32
  end
35
-
36
33
  end
37
34
  end
@@ -1,44 +1,41 @@
1
- if Rails::VERSION::MAJOR >= 5
2
- require 'activity_notification/optional_targets/action_cable_channel'
3
- describe ActivityNotification::OptionalTarget::ActionCableChannel do
4
- let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableChannel.new(skip_initializing_target: true) }
1
+ require 'activity_notification/optional_targets/action_cable_channel'
2
+ describe ActivityNotification::OptionalTarget::ActionCableChannel do
3
+ let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableChannel.new(skip_initializing_target: true) }
5
4
 
6
- describe "as public instance methods" do
7
- describe "#to_optional_target_name" do
8
- it "is return demodulized symbol class name" do
9
- expect(test_instance.to_optional_target_name).to eq(:action_cable_channel)
10
- end
5
+ describe "as public instance methods" do
6
+ describe "#to_optional_target_name" do
7
+ it "is return demodulized symbol class name" do
8
+ expect(test_instance.to_optional_target_name).to eq(:action_cable_channel)
11
9
  end
10
+ end
12
11
 
13
- describe "#initialize_target" do
14
- it "does not raise NotImplementedError" do
15
- test_instance.initialize_target
16
- end
12
+ describe "#initialize_target" do
13
+ it "does not raise NotImplementedError" do
14
+ test_instance.initialize_target
17
15
  end
16
+ end
18
17
 
19
- describe "#notify" do
20
- it "does not raise NotImplementedError" do
21
- test_instance.notify(create(:notification))
22
- end
18
+ describe "#notify" do
19
+ it "does not raise NotImplementedError" do
20
+ test_instance.notify(create(:notification))
23
21
  end
24
22
  end
23
+ end
25
24
 
26
- describe "as protected instance methods" do
27
- describe "#render_notification_message" do
28
- context "as default" do
29
- it "renders notification message with default template" do
30
- expect(test_instance.send(:render_notification_message, create(:notification))).to be_include("<div class='notification_list")
31
- end
25
+ describe "as protected instance methods" do
26
+ describe "#render_notification_message" do
27
+ context "as default" do
28
+ it "renders notification message with default template" do
29
+ expect(test_instance.send(:render_notification_message, create(:notification))).to be_include("<div class='notification_list")
32
30
  end
31
+ end
33
32
 
34
- context "with unexisting template as fallback option" do
35
- it "raise ActionView::MissingTemplate" do
36
- expect { expect(test_instance.send(:render_notification_message, create(:notification), fallback: :hoge)) }
37
- .to raise_error(ActionView::MissingTemplate)
38
- end
33
+ context "with unexisting template as fallback option" do
34
+ it "raise ActionView::MissingTemplate" do
35
+ expect { expect(test_instance.send(:render_notification_message, create(:notification), fallback: :hoge)) }
36
+ .to raise_error(ActionView::MissingTemplate)
39
37
  end
40
38
  end
41
39
  end
42
-
43
40
  end
44
41
  end
@@ -13,6 +13,11 @@ class UsersController < ApplicationController
13
13
  render json: @user
14
14
  end
15
15
 
16
+ # GET /users/find
17
+ def find
18
+ render json: User.find_by_email!(params[:email])
19
+ end
20
+
16
21
  private
17
22
  # Use callbacks to share common setup or constraints between actions.
18
23
  def set_user
@@ -6,85 +6,15 @@
6
6
 
7
7
  <script>
8
8
  import Vue from 'vue'
9
- import VueRouter from 'vue-router'
10
9
  import VueMoment from 'vue-moment'
11
10
  import moment from 'moment-timezone'
12
11
  import VuePluralize from 'vue-pluralize'
13
12
  import ActionCableVue from 'actioncable-vue'
14
13
  import axios from 'axios'
15
14
  import env from './config/environment'
16
- import authStore from "./store/auth"
17
- import Top from './components/Top.vue'
18
- import DeviseTokenAuth from './components/DeviseTokenAuth.vue'
19
- import NotificationsIndex from './components/notifications/Index.vue'
20
- import SubscriptionsIndex from './components/subscriptions/Index.vue'
21
15
 
22
- const router = new VueRouter({
23
- routes: [
24
- { path: '/', component: Top },
25
- { path: '/login', component: DeviseTokenAuth },
26
- { path: '/logout', component: DeviseTokenAuth, props: { isLogout: true } },
27
- // Routes for single page application working with activity_notification REST API backend for users
28
- {
29
- path: '/notifications',
30
- name: 'AuthenticatedUserNotificationsIndex',
31
- component: NotificationsIndex,
32
- props: () => ({ target_type: 'users', target: authStore.getters.currentUser }),
33
- meta: { requiresAuth: true }
34
- },
35
- {
36
- path: '/subscriptions',
37
- name: 'AuthenticatedUserSubscriptionsIndex',
38
- component: SubscriptionsIndex,
39
- props: () => ({ target_type: 'users', target: authStore.getters.currentUser }),
40
- meta: { requiresAuth: true }
41
- },
42
- // Routes for single page application working with activity_notification REST API backend for admins
43
- {
44
- path: '/admins/notifications',
45
- name: 'AuthenticatedAdminNotificationsIndex',
46
- component: NotificationsIndex,
47
- props: () => ({ target_type: 'admins', targetApiPath: 'admins', target: authStore.getters.currentUser.admin }),
48
- meta: { requiresAuth: true }
49
- },
50
- {
51
- path: '/admins/subscriptions',
52
- name: 'AuthenticatedAdminSubscriptionsIndex',
53
- component: SubscriptionsIndex,
54
- props: () => ({ target_type: 'admins', targetApiPath: 'admins', target: authStore.getters.currentUser.admin }),
55
- meta: { requiresAuth: true }
56
- },
57
- // Routes for single page application working with activity_notification REST API backend for unauthenticated targets
58
- {
59
- path: '/:target_type/:target_id/notifications',
60
- name: 'UnauthenticatedTargetNotificationsIndex',
61
- component: NotificationsIndex,
62
- props : true
63
- },
64
- {
65
- path: '/:target_type/:target_id/subscriptions',
66
- name: 'UnauthenticatedTargetSubscriptionsIndex',
67
- component: SubscriptionsIndex,
68
- props : true
69
- }
70
- ]
71
- })
72
-
73
- router.beforeEach((to, from, next) => {
74
- if (to.matched.some(record => record.meta.requiresAuth) && !authStore.getters.userSignedIn) {
75
- next({ path: '/login', query: { redirect: to.fullPath }});
76
- } else {
77
- next();
78
- }
79
- })
16
+ axios.defaults.baseURL = "/api/v2"
80
17
 
81
- if (authStore.getters.userSignedIn) {
82
- for (var authHeader of Object.keys(authStore.getters.authHeaders)) {
83
- axios.defaults.headers.common[authHeader] = authStore.getters.authHeaders[authHeader];
84
- }
85
- }
86
-
87
- Vue.use(VueRouter)
88
18
  Vue.use(VueMoment, { moment })
89
19
  Vue.use(VuePluralize)
90
20
  Vue.use(ActionCableVue, {
@@ -96,7 +26,13 @@ Vue.use(ActionCableVue, {
96
26
 
97
27
  export default {
98
28
  name: 'App',
99
- router
29
+ mounted () {
30
+ if (this.$store.getters.userSignedIn) {
31
+ for (var authHeader of Object.keys(this.$store.getters.authHeaders)) {
32
+ axios.defaults.headers.common[authHeader] = this.$store.getters.authHeaders[authHeader];
33
+ }
34
+ }
35
+ }
100
36
  }
101
37
  </script>
102
38