enju_leaf 1.2.0.beta.2 → 1.2.0.beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/layouts/application.html.erb +1 -1
  3. data/app/views/page/configuration.html.erb +6 -2
  4. data/app/views/page/import.html.erb +3 -1
  5. data/lib/enju_leaf.rb +0 -3
  6. data/lib/enju_leaf/version.rb +1 -1
  7. data/lib/generators/enju_leaf/quick_install/quick_install_generator.rb +3 -0
  8. data/lib/generators/enju_leaf/setup/setup_generator.rb +3 -5
  9. data/lib/tasks/enju_leaf_tasks.rake +3 -6
  10. data/spec/dummy/app/models/user.rb +1 -3
  11. data/spec/dummy/config/application.rb +4 -2
  12. data/spec/dummy/db/migrate/20160813191533_add_book_jacket_source_to_library_group.rb +5 -0
  13. data/spec/dummy/db/migrate/20160813191647_add_max_number_of_results_to_library_group.rb +5 -0
  14. data/spec/dummy/db/migrate/20160813191733_add_family_name_first_to_library_group.rb +5 -0
  15. data/spec/dummy/db/migrate/20160813191820_add_screenshot_generator_to_library_group.rb +5 -0
  16. data/spec/dummy/db/migrate/20160813192542_add_pub_year_facet_range_interval_to_library_group.rb +5 -0
  17. data/spec/dummy/db/migrate/20160813203039_add_user_id_to_library_group.rb +5 -0
  18. data/spec/dummy/db/schema.rb +14 -6
  19. data/spec/fixtures/library_groups.yml +1 -2
  20. data/spec/views/page/about.html.erb_spec.rb +2 -3
  21. data/spec/views/page/advanced_search.html.erb_spec.rb +1 -2
  22. data/spec/views/page/configuration.html.erb_spec.rb +2 -3
  23. data/spec/views/page/export.html.erb_spec.rb +2 -3
  24. data/spec/views/page/import.html.erb_spec.rb +2 -3
  25. data/spec/views/page/index.html.erb_spec.rb +1 -1
  26. data/spec/views/page/opensearch.xml.builder_spec.rb +1 -2
  27. data/spec/views/page/statistics.html.erb_spec.rb +3 -4
  28. metadata +43 -46
  29. data/app/models/concerns/calculate_stat.rb +0 -35
  30. data/app/models/concerns/enju_leaf/enju_user.rb +0 -309
  31. data/app/models/concerns/export_file.rb +0 -19
  32. data/app/models/concerns/import_file.rb +0 -89
  33. data/app/models/concerns/master_model.rb +0 -38
  34. data/lib/enju_leaf/localized_name.rb +0 -15
  35. data/lib/enju_leaf/url_validator.rb +0 -12
  36. data/lib/generators/enju_leaf/setup/templates/config/initializers/enju_leaf.rb +0 -1
  37. data/lib/generators/enju_leaf/setup/templates/config/initializers/resque.rb +0 -3
  38. data/spec/dummy/config/initializers/enju_leaf.rb +0 -2
  39. data/spec/factories/checkout.rb +0 -9
  40. data/spec/models/user_spec.rb +0 -194
@@ -1,35 +0,0 @@
1
- module CalculateStat
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- validates_presence_of :start_date, :end_date
6
- validate :check_date
7
-
8
- # 利用統計の集計を開始します。
9
- def self.calculate_stat
10
- self.not_calculated.each do |stat|
11
- stat.transition_to!(:started)
12
- end
13
- end
14
- end
15
-
16
- # 利用統計の日付をチェックします。
17
- def check_date
18
- if self.start_date and self.end_date
19
- if self.start_date >= self.end_date
20
- errors.add(:start_date)
21
- errors.add(:end_date)
22
- end
23
- end
24
- end
25
-
26
- # 利用統計の集計完了メッセージを送信します。
27
- def send_message
28
- sender = User.find(1) #system
29
- message_template = MessageTemplate.localized_template('counting_completed', user.profile.locale)
30
- request = MessageRequest.new
31
- request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
32
- request.save_message_body
33
- request.transition_to!(:sent)
34
- end
35
- end
@@ -1,309 +0,0 @@
1
- module EnjuLeaf
2
- module EnjuUser
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- scope :administrators, -> { joins(:role).where('roles.name = ?', 'Administrator') }
7
- scope :librarians, -> { joins(:role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
8
- scope :suspended, -> { where('locked_at IS NOT NULL') }
9
- has_one :profile
10
- if defined?(EnjuBiblio)
11
- has_many :import_requests
12
- has_many :picture_files, as: :picture_attachable, dependent: :destroy
13
- end
14
- has_one :user_has_role, dependent: :destroy
15
- has_one :role, through: :user_has_role
16
- belongs_to :user_group
17
- belongs_to :library
18
- belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
19
- accepts_nested_attributes_for :user_has_role
20
-
21
- validates :username, presence: true, uniqueness: true, format: {
22
- with: /\A[0-9A-Za-z][0-9A-Za-z_\-]*[0-9A-Za-z]\z/
23
- }
24
- validates :email, format: Devise::email_regexp, allow_blank: true, uniqueness: true
25
- validates_date :expired_at, allow_blank: true
26
-
27
- with_options if: :password_required? do |v|
28
- v.validates_presence_of :password
29
- v.validates_confirmation_of :password
30
- v.validates_length_of :password, allow_blank: true,
31
- within: Devise::password_length
32
- end
33
-
34
- before_validation :set_lock_information
35
- before_destroy :check_role_before_destroy
36
- before_save :check_expiration
37
- after_create :set_confirmation
38
-
39
- extend FriendlyId
40
- friendly_id :username
41
- strip_attributes only: :username
42
- strip_attributes only: :email, allow_empty: true
43
-
44
- attr_accessor :password_not_verified,
45
- :update_own_account, :auto_generated_password,
46
- :locked, :current_password #, :agent_id
47
-
48
- paginates_per 10
49
-
50
- def send_devise_notification(notification, *args)
51
- devise_mailer.send(notification, self, *args).deliver_later
52
- end
53
-
54
- # 有効期限切れのユーザを一括で使用不可にします。
55
- def self.lock_expired_users
56
- User.find_each do |user|
57
- user.lock_access! if user.expired? and user.active_for_authentication?
58
- end
59
- end
60
-
61
- # ユーザの情報をエクスポートします。
62
- # @param [Hash] options
63
- def self.export(options = {format: :txt})
64
- header = %w(
65
- username
66
- full_name
67
- full_name_transcription
68
- email
69
- user_number
70
- role
71
- user_group
72
- library
73
- locale
74
- locked
75
- required_role
76
- created_at
77
- updated_at
78
- expired_at
79
- keyword_list
80
- note
81
- )
82
- header += %w(
83
- checkout_icalendar_token
84
- save_checkout_history
85
- ) if defined? EnjuCirculation
86
- header << "save_search_history" if defined? EnjuSearchLog
87
- header << "share_bookmarks" if defined? EnjuBookmark
88
- lines = []
89
- User.find_each.map{|u|
90
- line = []
91
- line << u.username
92
- line << u.try(:profile).try(:full_name)
93
- line << u.try(:profile).try(:full_name_transcription)
94
- line << u.email
95
- line << u.try(:profile).try(:user_number)
96
- line << u.role.try(:name)
97
- line << u.try(:profile).try(:user_group).try(:name)
98
- line << u.try(:profile).try(:library).try(:name)
99
- line << u.try(:profile).try(:locale)
100
- line << u.access_locked?
101
- line << u.try(:profile).try(:required_role).try(:name)
102
- line << u.created_at
103
- line << u.updated_at
104
- line << u.try(:profile).try(:expired_at)
105
- line << u.try(:profile).try(:keyword_list).try(:split).try(:join, "//")
106
- line << u.try(:profile).try(:note)
107
- if defined? EnjuCirculation
108
- line << u.try(:profile).try(:checkout_icalendar_token)
109
- line << u.try(:profile).try(:save_checkout_history)
110
- end
111
- if defined? EnjuSearchLog
112
- line << u.try(:profile).try(:save_search_history)
113
- end
114
- if defined? EnjuBookmark
115
- line << u.try(:profile).try(:share_bookmarks)
116
- end
117
- lines << line
118
- }
119
- if options[:format] == :txt
120
- lines.map{|line| line.to_csv(col_sep: "\t")}.unshift(header.to_csv(col_sep: "\t")).join
121
- else
122
- lines
123
- end
124
- end
125
- end
126
-
127
- # ユーザにパスワードが必要かどうかをチェックします。
128
- # @return [Boolean]
129
- def password_required?
130
- if Devise.mappings[:user].modules.include?(:database_authenticatable)
131
- !persisted? || !password.nil? || !password_confirmation.nil?
132
- end
133
- end
134
-
135
- # ユーザが特定の権限を持っているかどうかをチェックします。
136
- # @param [String] role_in_question 権限名
137
- # @return [Boolean]
138
- def has_role?(role_in_question)
139
- return false unless role
140
- return true if role.name == role_in_question
141
- case role.name
142
- when 'Administrator'
143
- return true
144
- when 'Librarian'
145
- return true if role_in_question == 'User'
146
- else
147
- false
148
- end
149
- end
150
-
151
- # ユーザに使用不可の設定を反映させます。
152
- def set_lock_information
153
- if locked == '1' and self.active_for_authentication?
154
- lock_access!
155
- elsif locked == '0' and !self.active_for_authentication?
156
- unlock_access!
157
- end
158
- end
159
-
160
- def set_confirmation
161
- if respond_to?(:confirm!)
162
- reload
163
- confirm!
164
- end
165
- end
166
-
167
- # ユーザが有効期限切れかどうかをチェックし、期限切れであれば使用不可に設定します。
168
- # @return [Object]
169
- def check_expiration
170
- return if has_role?('Administrator')
171
- if expired_at
172
- if expired_at.beginning_of_day < Time.zone.now.beginning_of_day
173
- lock_access! if active_for_authentication?
174
- end
175
- end
176
- end
177
-
178
- # ユーザの削除前に、管理者ユーザが不在にならないかどうかをチェックします。
179
- # @return [Object]
180
- def check_role_before_destroy
181
- if has_role?('Administrator')
182
- if Role.where(name: 'Administrator').first.users.count == 1
183
- raise username + 'This is the last administrator in this system.'
184
- end
185
- end
186
- end
187
-
188
- # ユーザに自動生成されたパスワードを設定します。
189
- # @return [String]
190
- def set_auto_generated_password
191
- password = Devise.friendly_token[0..7]
192
- self.password = password
193
- self.password_confirmation = password
194
- end
195
-
196
- # ユーザが有効期限切れかどうかをチェックします。
197
- # @return [Boolean]
198
- def expired?
199
- if expired_at
200
- true if expired_at.beginning_of_day < Time.zone.now.beginning_of_day
201
- end
202
- end
203
-
204
- # ユーザが管理者かどうかをチェックします。
205
- # @return [Boolean]
206
- def is_admin?
207
- return true if has_role?('Administrator')
208
- false
209
- end
210
-
211
- # ユーザがシステム上の最後のLibrarian権限ユーザかどうかをチェックします。
212
- # @return [Boolean]
213
- def last_librarian?
214
- if has_role?('Librarian')
215
- role = Role.where(name: 'Librarian').first
216
- return true if role.users.count == 1
217
- false
218
- end
219
- end
220
-
221
- def send_confirmation_instructions
222
- Devise::Mailer.confirmation_instructions(self).deliver if email.present?
223
- end
224
-
225
- # ユーザが削除可能かどうかをチェックします。
226
- # @param [User] current_user ユーザ
227
- # @return [Object]
228
- def deletable_by?(current_user)
229
- return nil unless current_user
230
- if defined?(EnjuCirculation)
231
- # 未返却の資料のあるユーザを削除しようとした
232
- if checkouts.count > 0
233
- errors[:base] << I18n.t('user.this_user_has_checked_out_item')
234
- end
235
- end
236
-
237
- if has_role?('Librarian')
238
- # 管理者以外のユーザが図書館員を削除しようとした。図書館員の削除は管理者しかできない
239
- unless current_user.has_role?('Administrator')
240
- errors[:base] << I18n.t('user.only_administrator_can_destroy')
241
- end
242
- # 最後の図書館員を削除しようとした
243
- if last_librarian?
244
- errors[:base] << I18n.t('user.last_librarian')
245
- end
246
- end
247
-
248
- # 最後の管理者を削除しようとした
249
- if has_role?('Administrator')
250
- if Role.where(name: 'Administrator').first.users.count == 1
251
- errors[:base] << I18n.t('user.last_administrator')
252
- end
253
- end
254
-
255
- if errors[:base] == []
256
- true
257
- else
258
- false
259
- end
260
- end
261
- end
262
- end
263
-
264
-
265
- # == Schema Information
266
- #
267
- # Table name: users
268
- #
269
- # id :integer not null, primary key
270
- # email :string(255) default(""), not null
271
- # encrypted_password :string(255) default(""), not null
272
- # reset_password_token :string(255)
273
- # reset_password_sent_at :datetime
274
- # remember_created_at :datetime
275
- # sign_in_count :integer default(0)
276
- # current_sign_in_at :datetime
277
- # last_sign_in_at :datetime
278
- # current_sign_in_ip :string(255)
279
- # last_sign_in_ip :string(255)
280
- # password_salt :string(255)
281
- # confirmation_token :string(255)
282
- # confirmed_at :datetime
283
- # confirmation_sent_at :datetime
284
- # unconfirmed_email :string(255)
285
- # failed_attempts :integer default(0)
286
- # unlock_token :string(255)
287
- # locked_at :datetime
288
- # authentication_token :string(255)
289
- # created_at :datetime not null
290
- # updated_at :datetime not null
291
- # deleted_at :datetime
292
- # username :string(255) not null
293
- # library_id :integer default(1), not null
294
- # user_group_id :integer default(1), not null
295
- # expired_at :datetime
296
- # required_role_id :integer default(1), not null
297
- # note :text
298
- # keyword_list :text
299
- # user_number :string(255)
300
- # state :string(255)
301
- # locale :string(255)
302
- # enju_access_key :string(255)
303
- # save_checkout_history :boolean
304
- # checkout_icalendar_token :string(255)
305
- # share_bookmarks :boolean
306
- # save_search_history :boolean
307
- # answer_feed_token :string(255)
308
- #
309
-
@@ -1,19 +0,0 @@
1
- module ExportFile
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- belongs_to :user
6
- validates :user, presence: true
7
- attr_accessor :mode
8
- end
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.transition_to!(:sent)
18
- end
19
- end
@@ -1,89 +0,0 @@
1
- module ImportFile
2
- extend ActiveSupport::Concern
3
-
4
- # 失敗したインポート処理を一括削除します。
5
- def self.expire
6
- self.stucked.find_each do |file|
7
- file.destroy
8
- end
9
- end
10
-
11
- def import_start
12
- case edit_mode
13
- when 'create'
14
- import
15
- when 'update'
16
- modify
17
- when 'destroy'
18
- remove
19
- else
20
- import
21
- end
22
- end
23
-
24
- # インポートするファイルの文字コードをUTF-8に変換します。
25
- # @param [String] line 変換する文字列
26
- def convert_encoding(line)
27
- if defined?(CharlockHolmes::EncodingDetector)
28
- begin
29
- case user_encoding
30
- when 'auto_detect'
31
- encoding = CharlockHolmes::EncodingDetector.detect(line)[:encoding]
32
- when nil
33
- encoding = CharlockHolmes::EncodingDetector.detect(line)[:encoding]
34
- else
35
- encoding = user_encoding
36
- end
37
- line.encode('UTF-8', encoding, universal_newline: true)
38
- rescue StandardError
39
- nkf_encode(line)
40
- end
41
- else
42
- nkf_encode(line)
43
- end
44
- end
45
-
46
- # インポート完了時のメッセージを送信します。
47
- def send_message
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)
55
- end
56
-
57
- private
58
- def nkf_encode(line)
59
- case user_encoding
60
- when 'auto_detect'
61
- output_encoding = '-w'
62
- when 'UTF-8'
63
- output_encoding = ''
64
- when 'Shift_JIS'
65
- output_encoding = '-Sw'
66
- when 'EUC-JP'
67
- output_encoding = '-Ew'
68
- else
69
- output_encoding = '-w'
70
- end
71
- NKF.nkf("#{output_encoding} -Lu", line)
72
- end
73
-
74
- def create_import_temp_file(attachment)
75
- tempfile = Tempfile.new(self.class.name.underscore)
76
- if ENV['ENJU_STORAGE'] == 's3'
77
- tempfile.write Faraday.get(attachment.expiring_url(10)).body.force_encoding('UTF-8')
78
- else
79
- uploaded_file_path = attachment.path
80
- open(uploaded_file_path){|f|
81
- f.each{|line|
82
- tempfile.puts(convert_encoding(line))
83
- }
84
- }
85
- end
86
- tempfile.close
87
- tempfile
88
- end
89
- end