enju_library 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/mailers/application_mailer.rb +4 -0
  3. data/app/mailers/user_export_mailer.rb +17 -0
  4. data/app/mailers/user_import_mailer.rb +17 -0
  5. data/app/models/concerns/export_file.rb +8 -9
  6. data/app/models/concerns/import_file.rb +7 -7
  7. data/app/models/user_export_file.rb +4 -3
  8. data/app/models/user_import_file.rb +13 -4
  9. data/app/views/user_export_mailer/completed.en.text.erb +9 -0
  10. data/app/views/user_export_mailer/completed.ja.text.erb +9 -0
  11. data/app/views/user_export_mailer/failed.en.text.erb +9 -0
  12. data/app/views/user_export_mailer/failed.ja.text.erb +9 -0
  13. data/app/views/user_import_mailer/completed.en.text.erb +9 -0
  14. data/app/views/user_import_mailer/completed.ja.text.erb +9 -0
  15. data/app/views/user_import_mailer/failed.en.text.erb +9 -0
  16. data/app/views/user_import_mailer/failed.ja.text.erb +9 -0
  17. data/config/locales/translation_en.yml +11 -0
  18. data/config/locales/translation_ja.yml +11 -0
  19. data/lib/enju_library/version.rb +1 -1
  20. data/spec/mailers/previews/user_export_preview.rb +4 -0
  21. data/spec/mailers/previews/user_import_preview.rb +4 -0
  22. data/spec/mailers/user_export_spec.rb +5 -0
  23. data/spec/mailers/user_import_spec.rb +5 -0
  24. data/spec/models/basket_spec.rb +0 -1
  25. data/spec/models/library_group_spec.rb +0 -1
  26. data/spec/models/library_spec.rb +0 -1
  27. data/spec/models/request_status_type_spec.rb +0 -1
  28. data/spec/models/request_type_spec.rb +0 -1
  29. data/spec/models/search_engine_spec.rb +0 -1
  30. data/spec/models/shelf_spec.rb +0 -1
  31. data/spec/models/subscribe_spec.rb +0 -1
  32. data/spec/models/user_export_file_spec.rb +1 -1
  33. data/spec/models/user_group_spec.rb +0 -1
  34. data/spec/models/user_import_file_spec.rb +1 -1
  35. data/spec/models/user_import_result_spec.rb +0 -1
  36. metadata +35 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77bdde03f2503414e4c6cb2392231192de3016ead53bffbf69e35de7d584288
4
- data.tar.gz: 3a0beeecc968ac5dc5101dae91bcf2673ca601548fd4529c981e2751915aa83e
3
+ metadata.gz: 518d6386e03d122a166917fc15a446fd49a9fbf2651c462b145750ddc67f848b
4
+ data.tar.gz: 79d27b3572eb819d9ded99e22b7ead5c44c02c7b9e6d4ba2caaec5b151da6170
5
5
  SHA512:
6
- metadata.gz: d03ed3f75d7d7e69d1713988cdd1b4aa3e9074bcca2005d7b5eeef83d0c55079032b1cc4d0685df6cc9d1ed3c80a08c3cdec9769937dfa94cfcaa4297d6b2668
7
- data.tar.gz: cbfc93babf645402a4c3572ab8e59aa9c9a9ea27de906aebfb74ba4a394dfba3ee730c3547ba84e23d6da45ca8aab5361adad5432548f026fa6bd34bd022e61f
6
+ metadata.gz: e1f11e2a73dae41c407941907c3c367150125f067ec7f7dea9a06055ad6c3aa769091535af07ef73dfa6677a3f1a87a22b6abec8aafa091d4a1e63afa3d9aa92
7
+ data.tar.gz: 70fc2466822926ce04dfb8cca850ddc877c4b72e2def06f372db94de6cdb0fa97e71c1df410846a943a6b55063b09c3b59664a4482e755cbd12a323a79c5dcf9
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ end
4
+
@@ -0,0 +1,17 @@
1
+ class UserExportMailer < ApplicationMailer
2
+ def completed(user_export_file)
3
+ @user_export_file = user_export_file
4
+ @library_group = LibraryGroup.site_config
5
+ from = "#{LibraryGroup.system_name(user_export_file.user.profile.locale)} <#{@library_group.user.email}>"
6
+ subject = "#{I18n.t('user_export_mailer.completed.subject')}: #{@user_export_file.id}"
7
+ mail(from: from, to: user_export_file.user.email, subject: subject)
8
+ end
9
+
10
+ def failed(user_export_file)
11
+ @user_export_file = user_export_file
12
+ @library_group = LibraryGroup.site_config
13
+ from = "#{LibraryGroup.system_name(user_export_file.user.profile.locale)} <#{@library_group.user.email}>"
14
+ subject = "#{I18n.t('user_export_mailer.failed.subject')}: #{@user_export_file.id}"
15
+ mail(from: from, to: user_export_file.user.email, subject: subject)
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class UserImportMailer < ApplicationMailer
2
+ def completed(user_import_file)
3
+ @user_import_file = user_import_file
4
+ @library_group = LibraryGroup.site_config
5
+ from = "#{LibraryGroup.system_name(user_import_file.user.profile.locale)} <#{@library_group.user.email}>"
6
+ subject = "#{I18n.t('user_import_mailer.completed.subject')}: #{@user_import_file.id}"
7
+ mail(from: from, to: user_import_file.user.email, subject: subject)
8
+ end
9
+
10
+ def failed(user_import_file)
11
+ @user_import_file = user_import_file
12
+ @library_group = LibraryGroup.site_config
13
+ from = "#{LibraryGroup.system_name(user_import_file.user.profile.locale)} <#{@library_group.user.email}>"
14
+ subject = "#{I18n.t('user_import_mailer.failed.subject')}: #{@user_import_file.id}"
15
+ mail(from: from, to: user_import_file.user.email, subject: subject)
16
+ end
17
+ end
@@ -7,14 +7,13 @@ module ExportFile
7
7
  attr_accessor :mode
8
8
  end
9
9
 
10
- def send_message
11
- sender = User.find(1) #system
12
- locale = user.profile.try(:locale) || I18n.default_locale.to_s
13
- message_template = MessageTemplate.localized_template('export_completed', locale)
14
- request = MessageRequest.new
15
- request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
16
- request.save_message_body
17
- request.save!
18
- request.transition_to!(:sent)
10
+ def send_message(mailer)
11
+ sender = User.find(1)
12
+ message = Message.create!(
13
+ recipient: user.username,
14
+ sender: sender,
15
+ body: mailer.body.raw_source,
16
+ subject: mailer.subject
17
+ )
19
18
  end
20
19
  end
@@ -44,14 +44,14 @@ module ImportFile
44
44
  end
45
45
 
46
46
  # インポート完了時のメッセージを送信します。
47
- def send_message
47
+ def send_message(mailer)
48
48
  sender = User.find(1)
49
- locale = user.profile.try(:locale) || I18n.default_locale.to_s
50
- message_template = MessageTemplate.localized_template('import_completed', locale)
51
- request = MessageRequest.new
52
- request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
53
- request.save_message_body
54
- request.transition_to!(:sent)
49
+ message = Message.create!(
50
+ recipient: user.username,
51
+ sender: sender,
52
+ body: mailer.body.raw_source,
53
+ subject: mailer.subject
54
+ )
55
55
  end
56
56
 
57
57
  private
@@ -34,12 +34,13 @@ class UserExportFile < ActiveRecord::Base
34
34
  tempfile.puts(file)
35
35
  tempfile.close
36
36
  self.user_export = File.new(tempfile.path, 'r')
37
- if save
38
- send_message
39
- end
37
+ save!
40
38
  transition_to!(:completed)
39
+ mailer = UserExportMailer.completed(self)
40
+ send_message(mailer)
41
41
  rescue => e
42
42
  transition_to!(:failed)
43
+ mailer = UserExportMailer.failed(self)
43
44
  raise e
44
45
  end
45
46
 
@@ -115,10 +115,13 @@ class UserImportFile < ActiveRecord::Base
115
115
  else
116
116
  transition_to!(:completed)
117
117
  end
118
- send_message
118
+ mailer = UserImportMailer.completed(self)
119
+ send_message(mailer)
119
120
  num
120
121
  rescue => e
121
122
  transition_to!(:failed)
123
+ mailer = UserImportMailer.failed(self)
124
+ send_message(mailer)
122
125
  raise e
123
126
  end
124
127
 
@@ -161,14 +164,17 @@ class UserImportFile < ActiveRecord::Base
161
164
  end
162
165
 
163
166
  rows.close
164
- transition_to!(:completed)
165
167
  Sunspot.commit
166
- send_message
168
+ transition_to!(:completed)
169
+ mailer = UserImportMailer.completed(self)
170
+ send_message(mailer)
167
171
  num
168
172
  rescue => e
169
173
  self.error_message = "line #{row_num}: #{e.message}"
170
174
  save
171
175
  transition_to!(:failed)
176
+ mailer = UserImportMailer.failed(self)
177
+ send_message(mailer)
172
178
  raise e
173
179
  end
174
180
 
@@ -195,11 +201,14 @@ class UserImportFile < ActiveRecord::Base
195
201
  end
196
202
  end
197
203
  transition_to!(:completed)
198
- send_message
204
+ mailer = UserImportMailer.completed(self)
205
+ send_message(mailer)
199
206
  rescue => e
200
207
  self.error_message = "line #{row_num}: #{e.message}"
201
208
  save
202
209
  transition_to!(:failed)
210
+ mailer = UserImportMailer.failed(self)
211
+ send_message(mailer)
203
212
  raise e
204
213
  end
205
214
 
@@ -0,0 +1,9 @@
1
+ The following export task is completed.
2
+
3
+ ID: <%= @user_export_file.id %>
4
+ Created at: <%= @user_export_file.created_at %>
5
+ Detail: <%= user_export_file_url(@user_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートが完了しました。
2
+
3
+ ID: <%= @user_export_file.id %>
4
+ 作成時刻: <%= @user_export_file.created_at %>
5
+ 詳細: <%= user_export_file_url(@user_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ The following export task failed.
2
+
3
+ ID: <%= @user_export_file.id %>
4
+ Created at: <%= @user_export_file.created_at %>
5
+ Detail: <%= user_export_file_url(@user_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートに失敗しました。
2
+
3
+ ID: <%= @user_export_file.id %>
4
+ 作成時刻: <%= @user_export_file.created_at %>
5
+ 詳細: <%= user_export_file_url(@user_export_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ The following import task is completed.
2
+
3
+ ID: <%= @user_import_file.id %>
4
+ Created at: <%= @user_import_file.created_at %>
5
+ Detail: <%= user_import_file_url(@user_import_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートが完了しました。
2
+
3
+ ID: <%= @user_import_file.id %>
4
+ 作成時刻: <%= @user_import_file.created_at %>
5
+ 詳細: <%= user_import_file_url(@user_import_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ The following import task failed.
2
+
3
+ ID: <%= @user_import_file.id %>
4
+ Created at: <%= @user_import_file.created_at %>
5
+ Detail: <%= user_import_file_url(@user_import_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -0,0 +1,9 @@
1
+ 以下の資料のインポートに失敗しました。
2
+
3
+ ID: <%= @user_import_file.id %>
4
+ 作成時刻: <%= @user_import_file.created_at %>
5
+ 詳細: <%= user_import_file_url(@user_import_file) %>
6
+
7
+ --
8
+ <%= @library_group.display_name %>
9
+ <%= root_url %>
@@ -131,3 +131,14 @@ en:
131
131
  google: Google Books
132
132
  openbd: openBD
133
133
  hanmotocom: Hanmoto.com
134
+
135
+ user_import_mailer:
136
+ completed:
137
+ subject: 'Import completed'
138
+ failed:
139
+ subject: 'Import failed'
140
+ user_export_mailer:
141
+ completed:
142
+ subject: 'Export completed'
143
+ failed:
144
+ subject: 'Export failed'
@@ -131,3 +131,14 @@ ja:
131
131
  google: Googleブックス
132
132
  openbd: openBD
133
133
  hanmotocom: 版元ドットコム
134
+
135
+ user_import_mailer:
136
+ completed:
137
+ subject: 'インポートが完了しました'
138
+ failed:
139
+ subject: 'インポートに失敗しました'
140
+ user_export_mailer:
141
+ completed:
142
+ subject: 'エクスポートが完了しました'
143
+ failed:
144
+ subject: 'エクスポートに失敗しました'
@@ -1,3 +1,3 @@
1
1
  module EnjuLibrary
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -0,0 +1,4 @@
1
+ # Preview all emails at http://localhost:3000/rails/mailers/user_export
2
+ class UserExportPreview < ActionMailer::Preview
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+ # Preview all emails at http://localhost:3000/rails/mailers/user_import
2
+ class UserImportPreview < ActionMailer::Preview
3
+
4
+ end
@@ -0,0 +1,5 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe UserExportMailer, type: :mailer do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe UserImportMailer, type: :mailer do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe Basket do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe LibraryGroup do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe Library do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe RequestStatusType do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe RequestType do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe SearchEngine do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe Shelf do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe Subscribe do
@@ -9,7 +9,7 @@ describe UserExportFile do
9
9
  file.export!
10
10
  #UserExportFileJob.perform_later(file).should be_truthy
11
11
  Message.count.should eq message_count + 1
12
- Message.order(:id).last.subject.should eq 'エクスポートが完了しました'
12
+ Message.order(:created_at).last.subject.should eq "エクスポートが完了しました: #{file.id}"
13
13
  end
14
14
  end
15
15
 
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe UserGroup do
@@ -86,7 +86,7 @@ describe UserImportFile do
86
86
  @file.user = User.where(username: 'librarian1').first
87
87
  @file.import_start
88
88
  Message.count.should eq old_message_count + 1
89
- Message.order(:id).last.subject.should eq 'インポートが完了しました'
89
+ Message.order(:created_at).last.subject.should eq "インポートが完了しました: #{@file.id}"
90
90
  end
91
91
 
92
92
  it "should not import users that have higher roles than current user's role" do
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require 'rails_helper'
3
2
 
4
3
  describe UserImportResult do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_library
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kosuke Tanabe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-28 00:00:00.000000000 Z
11
+ date: 2019-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: enju_seed
@@ -360,6 +360,20 @@ dependencies:
360
360
  - - ">="
361
361
  - !ruby/object:Gem::Version
362
362
  version: '0'
363
+ - !ruby/object:Gem::Dependency
364
+ name: annotate
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - ">="
368
+ - !ruby/object:Gem::Version
369
+ version: '0'
370
+ type: :development
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - ">="
375
+ - !ruby/object:Gem::Version
376
+ version: '0'
363
377
  description: Library module for Next-L Enju
364
378
  email:
365
379
  - nabeta@fastmail.fm
@@ -392,7 +406,10 @@ files:
392
406
  - app/helpers/shelves_helper.rb
393
407
  - app/jobs/user_export_file_job.rb
394
408
  - app/jobs/user_import_file_job.rb
409
+ - app/mailers/application_mailer.rb
395
410
  - app/mailers/notifier.rb
411
+ - app/mailers/user_export_mailer.rb
412
+ - app/mailers/user_import_mailer.rb
396
413
  - app/models/accept.rb
397
414
  - app/models/basket.rb
398
415
  - app/models/bookstore.rb
@@ -517,6 +534,10 @@ files:
517
534
  - app/views/user_export_files/index.html.erb
518
535
  - app/views/user_export_files/new.html.erb
519
536
  - app/views/user_export_files/show.html.erb
537
+ - app/views/user_export_mailer/completed.en.text.erb
538
+ - app/views/user_export_mailer/completed.ja.text.erb
539
+ - app/views/user_export_mailer/failed.en.text.erb
540
+ - app/views/user_export_mailer/failed.ja.text.erb
520
541
  - app/views/user_groups/_form.html.erb
521
542
  - app/views/user_groups/edit.html.erb
522
543
  - app/views/user_groups/index.html.erb
@@ -528,6 +549,10 @@ files:
528
549
  - app/views/user_import_files/index.html.erb
529
550
  - app/views/user_import_files/new.html.erb
530
551
  - app/views/user_import_files/show.html.erb
552
+ - app/views/user_import_mailer/completed.en.text.erb
553
+ - app/views/user_import_mailer/completed.ja.text.erb
554
+ - app/views/user_import_mailer/failed.en.text.erb
555
+ - app/views/user_import_mailer/failed.ja.text.erb
531
556
  - app/views/user_import_results/_form.html.erb
532
557
  - app/views/user_import_results/_list.html.erb
533
558
  - app/views/user_import_results/_list_lines.html.erb
@@ -955,6 +980,10 @@ files:
955
980
  - spec/fixtures/users.yml
956
981
  - spec/fixtures/withdraws.yml
957
982
  - spec/libraries_spec.rb
983
+ - spec/mailers/previews/user_export_preview.rb
984
+ - spec/mailers/previews/user_import_preview.rb
985
+ - spec/mailers/user_export_spec.rb
986
+ - spec/mailers/user_import_spec.rb
958
987
  - spec/models/accept_spec.rb
959
988
  - spec/models/basket_spec.rb
960
989
  - spec/models/bookstore_spec.rb
@@ -1282,6 +1311,10 @@ test_files:
1282
1311
  - spec/dummy/db/migrate/20111129044509_add_pickup_location_to_reserve.rb
1283
1312
  - spec/dummy/README.rdoc
1284
1313
  - spec/libraries_spec.rb
1314
+ - spec/mailers/user_export_spec.rb
1315
+ - spec/mailers/user_import_spec.rb
1316
+ - spec/mailers/previews/user_import_preview.rb
1317
+ - spec/mailers/previews/user_export_preview.rb
1285
1318
  - spec/models/library_group_spec.rb
1286
1319
  - spec/models/request_type_spec.rb
1287
1320
  - spec/models/withdraw_spec.rb