enju_standalone_interface 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/app/assets/javascripts/enju_standalone_interface/application.js +15 -0
- data/app/assets/javascripts/enju_standalone_interface/batch_action.js +2 -0
- data/app/assets/stylesheets/enju_standalone_interface/application.css +13 -0
- data/app/assets/stylesheets/enju_standalone_interface/batch_action.css +4 -0
- data/app/controllers/application_controller.rb +4 -0
- data/app/controllers/batch_action_controller.rb +9 -0
- data/app/helpers/enju_standalone_interface/application_helper.rb +4 -0
- data/app/helpers/enju_standalone_interface/batch_action_helper.rb +4 -0
- data/app/views/enju_standalone_interface/batch_action/recept.html.erb +1 -0
- data/app/views/layouts/enju_standalone_interface/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/lib/enju_standalone_interface.rb +233 -0
- data/lib/enju_standalone_interface/engine.rb +5 -0
- data/lib/enju_standalone_interface/version.rb +3 -0
- data/lib/tasks/enju_standalone_interface_tasks.rake +4 -0
- data/spec/controllers/enju_standalone_interface/batch_action_controller_spec.rb +21 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +36 -0
- data/spec/dummy/app/models/basket.rb +70 -0
- data/spec/dummy/app/models/carrier_type.rb +33 -0
- data/spec/dummy/app/models/checked_item.rb +177 -0
- data/spec/dummy/app/models/checkout.rb +307 -0
- data/spec/dummy/app/models/checkout_type.rb +33 -0
- data/spec/dummy/app/models/circulation_status.rb +23 -0
- data/spec/dummy/app/models/event.rb +124 -0
- data/spec/dummy/app/models/item.rb +1234 -0
- data/spec/dummy/app/models/item_has_use_restriction.rb +23 -0
- data/spec/dummy/app/models/lending_policy.rb +32 -0
- data/spec/dummy/app/models/library.rb +105 -0
- data/spec/dummy/app/models/library_group.rb +88 -0
- data/spec/dummy/app/models/manifestation.rb +698 -0
- data/spec/dummy/app/models/patron.rb +342 -0
- data/spec/dummy/app/models/role.rb +47 -0
- data/spec/dummy/app/models/shelf.rb +83 -0
- data/spec/dummy/app/models/use_restriction.rb +22 -0
- data/spec/dummy/app/models/user.rb +580 -0
- data/spec/dummy/app/models/user_group.rb +43 -0
- data/spec/dummy/app/models/user_group_has_checkout_type.rb +80 -0
- data/spec/dummy/app/models/user_has_role.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +57 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/locales/translation_en.yml +1724 -0
- data/spec/dummy/config/locales/validates_timeliness.en.yml +16 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20120322223037_create_users.rb +71 -0
- data/spec/dummy/db/migrate/20120323053037_create_roles.rb +15 -0
- data/spec/dummy/db/migrate/20120323060718_create_user_has_roles.rb +10 -0
- data/spec/dummy/db/migrate/20120323062239_create_libraries.rb +37 -0
- data/spec/dummy/db/migrate/20120323063602_create_items.rb +33 -0
- data/spec/dummy/db/migrate/20120323064619_craete_circulation_statuses.rb +13 -0
- data/spec/dummy/db/migrate/20120323065157_craete_checkout_types.rb +13 -0
- data/spec/dummy/db/migrate/20120323070102_craete_shelves.rb +17 -0
- data/spec/dummy/db/migrate/20120323071616_craete_library_groups.rb +24 -0
- data/spec/dummy/db/migrate/20120323073022_craete_patrons.rb +72 -0
- data/spec/dummy/db/migrate/20120323141030_create_manifestations.rb +97 -0
- data/spec/dummy/db/migrate/20120323142330_create_carrier_types.rb +12 -0
- data/spec/dummy/db/migrate/20120324132708_create_baskets.rb +20 -0
- data/spec/dummy/db/migrate/20120324135409_checked_items.rb +16 -0
- data/spec/dummy/db/migrate/20120324141007_create_user_groups.rb +22 -0
- data/spec/dummy/db/migrate/20120324141950_create_user_group_has_checkout_type.rb +26 -0
- data/spec/dummy/db/migrate/20120324151951_create_lending_policies.rb +22 -0
- data/spec/dummy/db/migrate/20120324153756_create_use_restrictions.rb +15 -0
- data/spec/dummy/db/migrate/20120324154009_create_item_has_use_restrictions.rb +16 -0
- data/spec/dummy/db/migrate/20120324164815_create_checkouts.rb +26 -0
- data/spec/dummy/db/migrate/20120325160112_create_events.rb +23 -0
- data/spec/dummy/db/schema.rb +518 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/enju_leaf.rb +6 -0
- data/spec/dummy/lib/enju_leaf/master_model.rb +41 -0
- data/spec/dummy/lib/enju_leaf/url_validator.rb +10 -0
- data/spec/dummy/log/development.log +116 -0
- data/spec/dummy/log/test.log +17849 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/item.rb +9 -0
- data/spec/factories/manifestation.rb +6 -0
- data/spec/factories/user.rb +27 -0
- data/spec/fixtures/carrier_types.yml +38 -0
- data/spec/fixtures/checkout_types.yml +34 -0
- data/spec/fixtures/circulation_statuses.yml +135 -0
- data/spec/fixtures/libraries.yml +40 -0
- data/spec/fixtures/roles.yml +21 -0
- data/spec/fixtures/shelves.yml +53 -0
- data/spec/fixtures/user_group_has_checkout_types.yml +14 -0
- data/spec/fixtures/user_groups.yml +7 -0
- data/spec/libs/enju_standalone_interface_spec.rb +133 -0
- data/spec/spec_helper.rb +36 -0
- metadata +358 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class UseRestriction < ActiveRecord::Base
|
|
2
|
+
include MasterModel
|
|
3
|
+
default_scope :order => 'position'
|
|
4
|
+
scope :available, where(:name => ['Not For Loan', 'Limited Circulation, Normal Loan Period'])
|
|
5
|
+
has_many :item_has_use_restrictions
|
|
6
|
+
has_many :items, :through => :item_has_use_restrictions
|
|
7
|
+
attr_protected :name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# == Schema Information
|
|
11
|
+
#
|
|
12
|
+
# Table name: use_restrictions
|
|
13
|
+
#
|
|
14
|
+
# id :integer not null, primary key
|
|
15
|
+
# name :string(255) not null
|
|
16
|
+
# display_name :text
|
|
17
|
+
# note :text
|
|
18
|
+
# position :integer
|
|
19
|
+
# created_at :datetime
|
|
20
|
+
# updated_at :datetime
|
|
21
|
+
#
|
|
22
|
+
|
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
class User < ActiveRecord::Base
|
|
2
|
+
self.extend UsersHelper
|
|
3
|
+
# Include default devise modules. Others available are:
|
|
4
|
+
# :token_authenticatable, :lockable and :timeoutable
|
|
5
|
+
|
|
6
|
+
# Setup accessible (or protected) attributes for your model
|
|
7
|
+
attr_accessible :email, :email_confirmation, :password, :password_confirmation, :username, :current_password, :user_number, :remember_me, :auto_generated_password, :expired_at, :locked, :unable, :user_group_id, :library_id, :locale, :role_id, :keyword_list
|
|
8
|
+
cattr_accessor :current_user
|
|
9
|
+
attr_accessor :new_user_number
|
|
10
|
+
|
|
11
|
+
scope :administrators, where('roles.name = ?', 'Administrator').includes(:role)
|
|
12
|
+
scope :librarians, where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian').includes(:role)
|
|
13
|
+
scope :suspended, where('locked_at IS NOT NULL')
|
|
14
|
+
scope :adults, joins(:patron).where(["patrons.date_of_birth <= ?", Date.today.years_ago(18).change(:month => 4, :day => 1)])
|
|
15
|
+
scope :students, joins(:patron).where(["patrons.date_of_birth < ? AND patrons.date_of_birth >= ?", Date.today.years_ago(15).change(:month => 4, :day => 1), Date.today.years_ago(18).change(:month => 4, :day => 1)])
|
|
16
|
+
scope :juniors, joins(:patron).where(["patrons.date_of_birth < ? AND patrons.date_of_birth >= ?", Date.today.years_ago(12).change(:month => 4, :day => 1), Date.today.years_ago(15).change(:month => 4, :day => 1)])
|
|
17
|
+
scope :elementaries, joins(:patron).where(["patrons.date_of_birth < ? AND patrons.date_of_birth >= ?", Date.today.years_ago(6).change(:month => 4, :day => 1), Date.today.years_ago(12).change(:month => 4, :day => 1)])
|
|
18
|
+
scope :children, joins(:patron).where(["patrons.date_of_birth >= ?", Date.today.years_ago(6).change(:month => 4, :day => 1)])
|
|
19
|
+
scope :provisional, where(:user_number => nil)
|
|
20
|
+
scope :corporate, joins(:patron => :patron_type).where(["patron_types.name = ? ", "CorporateBody"])
|
|
21
|
+
has_one :patron
|
|
22
|
+
has_many :checkouts
|
|
23
|
+
has_many :import_requests
|
|
24
|
+
has_many :sent_messages, :foreign_key => 'sender_id', :class_name => 'Message'
|
|
25
|
+
has_many :received_messages, :foreign_key => 'receiver_id', :class_name => 'Message'
|
|
26
|
+
has_one :user_has_role
|
|
27
|
+
has_one :role, :through => :user_has_role
|
|
28
|
+
has_many :reserves, :dependent => :destroy
|
|
29
|
+
has_many :reserved_manifestations, :through => :reserves, :source => :manifestation
|
|
30
|
+
has_many :search_histories, :dependent => :destroy
|
|
31
|
+
has_many :baskets, :dependent => :destroy
|
|
32
|
+
has_many :purchase_requests
|
|
33
|
+
has_many :order_lists
|
|
34
|
+
has_many :subscriptions
|
|
35
|
+
has_many :checkout_stat_has_users
|
|
36
|
+
has_many :user_checkout_stats, :through => :checkout_stat_has_users
|
|
37
|
+
has_many :reserve_stat_has_users
|
|
38
|
+
has_many :user_reserve_stats, :through => :reserve_stat_has_users
|
|
39
|
+
belongs_to :library, :validate => true
|
|
40
|
+
belongs_to :user_group
|
|
41
|
+
belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id' #, :validate => true
|
|
42
|
+
|
|
43
|
+
validates :username, :presence => true, :uniqueness => true
|
|
44
|
+
|
|
45
|
+
#validates_associated :library
|
|
46
|
+
|
|
47
|
+
attr_accessor :first_name, :middle_name, :last_name, :full_name,
|
|
48
|
+
:first_name_transcription, :middle_name_transcription,
|
|
49
|
+
:last_name_transcription, :full_name_transcription,
|
|
50
|
+
:zip_code, :address, :address_1, :telephone_number, :fax_number, :address_note,
|
|
51
|
+
:role_id, :patron_id, :operator, :password_not_verified,
|
|
52
|
+
:update_own_account, :auto_generated_password,
|
|
53
|
+
:locked, :current_password, :birth_date, :death_date #, :email
|
|
54
|
+
|
|
55
|
+
def has_role?(role_in_question)
|
|
56
|
+
return false unless role
|
|
57
|
+
return true if role.name == role_in_question
|
|
58
|
+
case role.name
|
|
59
|
+
when 'Administrator'
|
|
60
|
+
return true
|
|
61
|
+
when 'Librarian'
|
|
62
|
+
return true if role_in_question == 'User'
|
|
63
|
+
else
|
|
64
|
+
false
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def set_role_and_patron
|
|
69
|
+
#self.required_role = Role.find_by_name('Librarian')
|
|
70
|
+
# self.locale = I18n.default_locale.to_s
|
|
71
|
+
unless self.patron
|
|
72
|
+
# self.patron = Patron.create(:full_name => self.username) if self.username
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def set_lock_information
|
|
77
|
+
if self.locked == '1' and self.active_for_authentication?
|
|
78
|
+
lock_access!
|
|
79
|
+
elsif self.locked == '0' and !self.active_for_authentication?
|
|
80
|
+
unlock_access!
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def index_patron
|
|
85
|
+
if self.patron
|
|
86
|
+
self.patron.index
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def check_expiration
|
|
91
|
+
return if self.has_role?('Administrator')
|
|
92
|
+
if expired_at
|
|
93
|
+
if expired_at.beginning_of_day < Time.zone.now.beginning_of_day
|
|
94
|
+
lock_access! if self.active_for_authentication?
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def check_item_before_destroy
|
|
100
|
+
# TODO: 貸出記録を残す場合
|
|
101
|
+
if checkouts.size > 0
|
|
102
|
+
raise 'This user has items still checked out.'
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def check_role_before_destroy
|
|
107
|
+
if self.has_role?('Administrator')
|
|
108
|
+
raise 'This is the last administrator in this system.' if Role.find_by_name('Administrator').users.size == 1
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def reset_checkout_icalendar_token
|
|
113
|
+
self.checkout_icalendar_token = Devise.friendly_token
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def expired?
|
|
117
|
+
if expired_at
|
|
118
|
+
true if expired_at.beginning_of_day < Time.zone.now.beginning_of_day
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def checked_item_count
|
|
123
|
+
checkout_count = {}
|
|
124
|
+
CheckoutType.all.each do |checkout_type|
|
|
125
|
+
# 資料種別ごとの貸出中の冊数を計算
|
|
126
|
+
checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql(["
|
|
127
|
+
SELECT count(item_id) FROM checkouts
|
|
128
|
+
WHERE item_id IN (
|
|
129
|
+
SELECT id FROM items
|
|
130
|
+
WHERE checkout_type_id = ?
|
|
131
|
+
)
|
|
132
|
+
AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id]
|
|
133
|
+
)
|
|
134
|
+
end
|
|
135
|
+
return checkout_count
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def reached_reservation_limit?(manifestation)
|
|
139
|
+
return true if self.user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => self.user_group.id).collect(&:reservation_limit).max.to_i <= self.reserves.waiting.size
|
|
140
|
+
false
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def is_admin?
|
|
144
|
+
true if self.has_role?('Administrator')
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def last_librarian?
|
|
148
|
+
if self.has_role?('Librarian')
|
|
149
|
+
role = Role.where(:name => 'Librarian').first
|
|
150
|
+
true if role.users.size == 1
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def check_update_own_account(user)
|
|
155
|
+
if user == self
|
|
156
|
+
self.update_own_account = true
|
|
157
|
+
return true
|
|
158
|
+
end
|
|
159
|
+
false
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def deletable_by(current_user)
|
|
163
|
+
# 未返却の資料のあるユーザを削除しようとした
|
|
164
|
+
if self.checkouts.count > 0
|
|
165
|
+
errors[:base] << I18n.t('user.this_user_has_checked_out_item')
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
if self.has_role?('Librarian')
|
|
169
|
+
# 管理者以外のユーザが図書館員を削除しようとした。図書館員の削除は管理者しかできない
|
|
170
|
+
unless current_user.has_role?('Administrator')
|
|
171
|
+
errors[:base] << I18n.t('user.only_administrator_can_destroy')
|
|
172
|
+
end
|
|
173
|
+
# 最後の図書館員を削除しようとした
|
|
174
|
+
if self.last_librarian?
|
|
175
|
+
errors[:base] << I18n.t('user.last_librarian')
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# 最後の管理者を削除しようとした
|
|
180
|
+
if self.has_role?('Administrator')
|
|
181
|
+
if Role.where(:name => 'Administrator').first.users.size == 1
|
|
182
|
+
errors[:base] << I18n.t('user.last_administrator')
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
if errors[:base] == []
|
|
187
|
+
true
|
|
188
|
+
else
|
|
189
|
+
false
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def self.create_with_params(params, has_role_id)
|
|
194
|
+
logger.debug "create_with_params start."
|
|
195
|
+
user = User.new(params)
|
|
196
|
+
user_group = UserGroup.find(params[:user_group_id])
|
|
197
|
+
user.user_group = user_group if user_group
|
|
198
|
+
user.locale = params[:locale]
|
|
199
|
+
library = Library.find(params[:library_id])
|
|
200
|
+
user.library = library if library
|
|
201
|
+
user.operator = current_user
|
|
202
|
+
|
|
203
|
+
logger.debug "create_with_params create-1"
|
|
204
|
+
|
|
205
|
+
if params
|
|
206
|
+
#self.username = params[:user][:login]
|
|
207
|
+
user.note = params[:note]
|
|
208
|
+
user.user_group_id = params[:user_group_id] ||= 1
|
|
209
|
+
user.library_id = params[:library_id] ||= 1
|
|
210
|
+
# user.role_id = params[:role_id] ||= 1
|
|
211
|
+
|
|
212
|
+
if !params[:role_id].blank? and has_role_id.blank?
|
|
213
|
+
user.role_id = params[:role_id] ||= 1
|
|
214
|
+
user.role = Role.find(user.role_id)
|
|
215
|
+
elsif !has_role_id.blank?
|
|
216
|
+
user.role_id = has_role_id ||= 1
|
|
217
|
+
user.role = Role.find(has_role_id)
|
|
218
|
+
else
|
|
219
|
+
user.role_id = Role.where(:name => 'User').first.id ||= 1
|
|
220
|
+
user.role = Role.where(:name => 'User').first
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
user.required_role_id = params[:required_role_id] ||= 1
|
|
224
|
+
user.required_role = Role.find(user.required_role_id)
|
|
225
|
+
user.keyword_list = params[:keyword_list]
|
|
226
|
+
user.user_number = params[:user_number]
|
|
227
|
+
user.locale = params[:locale]
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
logger.debug "create_with_params create-10"
|
|
231
|
+
|
|
232
|
+
if user.patron_id
|
|
233
|
+
user.patron = Patron.find(user.patron_id) rescue nil
|
|
234
|
+
end
|
|
235
|
+
logger.debug "create_with_params end."
|
|
236
|
+
user
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def update_with_params(params)
|
|
240
|
+
self.operator = current_user
|
|
241
|
+
self.openid_identifier = params[:openid_identifier]
|
|
242
|
+
self.keyword_list = params[:keyword_list]
|
|
243
|
+
self.checkout_icalendar_token = params[:checkout_icalendar_token]
|
|
244
|
+
self.email = params[:email]
|
|
245
|
+
#self.note = params[:note]
|
|
246
|
+
#self.username = params[:login]
|
|
247
|
+
|
|
248
|
+
if current_user.has_role?('Librarian')
|
|
249
|
+
self.email = params[:email]
|
|
250
|
+
self.expired_at = params[:expired_at]
|
|
251
|
+
self.note = params[:note]
|
|
252
|
+
self.user_group_id = params[:user_group_id] || 1
|
|
253
|
+
self.library_id = params[:library_id] || 1
|
|
254
|
+
self.role_id = params[:role_id]
|
|
255
|
+
self.required_role_id = params[:required_role_id] || 1
|
|
256
|
+
self.locale = params[:locale]
|
|
257
|
+
self.user_number = params[:user_number]
|
|
258
|
+
self.locked = params[:locked]
|
|
259
|
+
self.expired_at = params[:expired_at]
|
|
260
|
+
self.unable = params[:unable]
|
|
261
|
+
end
|
|
262
|
+
self
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def deletable?
|
|
266
|
+
true if checkouts.not_returned.empty? and id != 1
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def set_family(user_id)
|
|
270
|
+
family = User.find(user_id).family rescue nil
|
|
271
|
+
if family
|
|
272
|
+
family.users << self
|
|
273
|
+
else
|
|
274
|
+
family = Family.create()
|
|
275
|
+
user = User.find(user_id)
|
|
276
|
+
family.users << self
|
|
277
|
+
family.users << user
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def out_of_family
|
|
282
|
+
begin
|
|
283
|
+
family_user = FamilyUser.find(:first, :conditions => ['user_id=?', self.id])
|
|
284
|
+
family_id = family_user.family_id
|
|
285
|
+
family_user.destroy
|
|
286
|
+
all_users = FamilyUser.find(:all, :conditions => ['family_id=?', family_id])
|
|
287
|
+
if all_users && all_users.length == 1
|
|
288
|
+
all_users.each do |user|
|
|
289
|
+
user.destroy
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
rescue Exception => e
|
|
293
|
+
logger.error e
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def family
|
|
298
|
+
FamilyUser.find(:first, :conditions => ['user_id=?', id]).family
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def user_notice
|
|
302
|
+
@messages = []
|
|
303
|
+
overdues = self.checkouts.overdue(Time.zone.now) rescue nil
|
|
304
|
+
@messages << I18n.t('user.overdue_item', :user => self.username, :count => overdues.length) unless overdues.empty?
|
|
305
|
+
reserves = self.reserves.hold rescue nil
|
|
306
|
+
@messages << I18n.t('user.retained_reserve', :user => self.username, :count => reserves.length) unless reserves.empty?
|
|
307
|
+
return @messages
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def age
|
|
311
|
+
Date.today.year - patron.date_of_birth.year
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def set_color
|
|
315
|
+
@color = nil
|
|
316
|
+
@color = SystemConfiguration.get("user.unable.background") if self.unable == true
|
|
317
|
+
@color = SystemConfiguration.get("user.locked.background") unless self.locked_at.blank?
|
|
318
|
+
return @color
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def self.output_userlist_pdf(users)
|
|
322
|
+
report = ThinReports::Report.new :layout => File.join(Rails.root, 'report', 'userlist.tlf')
|
|
323
|
+
|
|
324
|
+
# set page_num
|
|
325
|
+
report.events.on :page_create do |e|
|
|
326
|
+
e.page.item(:page).value(e.page.no)
|
|
327
|
+
end
|
|
328
|
+
report.events.on :generate do |e|
|
|
329
|
+
e.pages.each do |page|
|
|
330
|
+
page.item(:total).value(e.report.page_count)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
report.start_new_page do |page|
|
|
335
|
+
page.item(:date).value(Time.now)
|
|
336
|
+
users.each do |user|
|
|
337
|
+
page.list(:list).add_row do |row|
|
|
338
|
+
row.item(:full_name).value(user.patron.full_name)
|
|
339
|
+
row.item(:username).value(user.username)
|
|
340
|
+
row.item(:user_number).value(user.user_number)
|
|
341
|
+
row.item(:tel1).value(user.patron.telephone_number_1) if user.patron.telephone_number_1
|
|
342
|
+
row.item(:tel2).value(user.patron.telephone_number_2) if user.patron.telephone_number_2
|
|
343
|
+
row.item(:created_at).value(user.created_at)
|
|
344
|
+
row.item(:locked).value(I18n.t('activerecord.attributes.user.locked_yes')) if user.active_for_authentication?
|
|
345
|
+
row.item(:locked).value(I18n.t('activerecord.attributes.user.locked_no')) unless user.active_for_authentication?
|
|
346
|
+
row.item(:unable).value(I18n.t('activerecord.attributes.user.unable_yes')) if user.unable
|
|
347
|
+
row.item(:unable).value(I18n.t('activerecord.attributes.user.unable_no')) unless user.unable
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
return report
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def self.output_userlist_tsv(users)
|
|
355
|
+
columns = [
|
|
356
|
+
[:full_name, 'activerecord.attributes.patron.full_name'],
|
|
357
|
+
[:full_name_transcription, 'activerecord.attributes.patron.full_name_transcription'],
|
|
358
|
+
[:full_name_alternative, 'activerecord.attributes.patron.full_name_alternative'],
|
|
359
|
+
['username', 'activerecord.attributes.user.username'],
|
|
360
|
+
['user_number', 'activerecord.attributes.user.user_number'],
|
|
361
|
+
[:library, 'activerecord.attributes.user.library'],
|
|
362
|
+
[:expired_at, 'activerecord.attributes.user.expired_at'],
|
|
363
|
+
[:locked, 'activerecord.attributes.user.locked'],
|
|
364
|
+
[:unable, 'activerecord.attributes.user.unable'],
|
|
365
|
+
[:patron_type, 'activerecord.models.patron_type'],
|
|
366
|
+
[:email, 'activerecord.attributes.patron.email'],
|
|
367
|
+
[:url, 'activerecord.attributes.patron.url'],
|
|
368
|
+
[:other_designation, 'activerecord.attributes.patron.other_designation'],
|
|
369
|
+
[:place, 'activerecord.attributes.patron.place'],
|
|
370
|
+
[:language, 'activerecord.models.language'],
|
|
371
|
+
[:zip_code_1, 'activerecord.attributes.patron.zip_code_1'],
|
|
372
|
+
[:address_1, 'activerecord.attributes.patron.address_1'],
|
|
373
|
+
[:telephone_number_1, 'activerecord.attributes.patron.telephone_number_1'],
|
|
374
|
+
[:extelephone_number_1, 'activerecord.attributes.patron.extelephone_number_1'],
|
|
375
|
+
[:fax_number_1, 'activerecord.attributes.patron.fax_number_1'],
|
|
376
|
+
[:address_1_note, 'activerecord.attributes.patron.address_1_note'],
|
|
377
|
+
[:zip_code_2, 'activerecord.attributes.patron.zip_code_2'],
|
|
378
|
+
[:address_2, 'activerecord.attributes.patron.address_2'],
|
|
379
|
+
[:telephone_number_2, 'activerecord.attributes.patron.telephone_number_2'],
|
|
380
|
+
[:extelephone_number_2, 'activerecord.attributes.patron.extelephone_number_2'],
|
|
381
|
+
[:fax_number_2, 'activerecord.attributes.patron.fax_number_2'],
|
|
382
|
+
[:address_2_note, 'activerecord.attributes.patron.address_2_note'],
|
|
383
|
+
[:date_of_birth, 'activerecord.attributes.patron.date_of_birth'],
|
|
384
|
+
[:date_of_death, 'activerecord.attributes.patron.date_of_death'],
|
|
385
|
+
[:note, 'activerecord.attributes.patron.note'],
|
|
386
|
+
[:note_update_at, 'activerecord.attributes.patron.note_update_at'],
|
|
387
|
+
[:patron_identifier, 'patron.patron_identifier'],
|
|
388
|
+
[:created_at, 'page.created_at'],
|
|
389
|
+
[:updated_at, 'page.updated_at'],
|
|
390
|
+
]
|
|
391
|
+
|
|
392
|
+
data = String.new
|
|
393
|
+
|
|
394
|
+
data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
|
|
395
|
+
# title column
|
|
396
|
+
row = []
|
|
397
|
+
columns.each do |column|
|
|
398
|
+
row << I18n.t(column[1])
|
|
399
|
+
end
|
|
400
|
+
data << '"'+row.join("\"\t\"")+"\"\n"
|
|
401
|
+
|
|
402
|
+
users.each do |user|
|
|
403
|
+
row = []
|
|
404
|
+
columns.each do |column|
|
|
405
|
+
case column[0]
|
|
406
|
+
when :full_name
|
|
407
|
+
row << user.patron.full_name
|
|
408
|
+
when :full_name_transcription
|
|
409
|
+
row << user.patron.full_name_transcription
|
|
410
|
+
when :full_name_alternative
|
|
411
|
+
row << user.patron.full_name_alternative
|
|
412
|
+
when :library
|
|
413
|
+
row << user.library.display_name
|
|
414
|
+
when :expired_at
|
|
415
|
+
expired_at = ""
|
|
416
|
+
if user.expired_at
|
|
417
|
+
year = user.expired_at.strftime("%Y")
|
|
418
|
+
month = user.expired_at.strftime("%m")
|
|
419
|
+
date = user.expired_at.strftime("%d")
|
|
420
|
+
expired_at = I18n.t('expense.date_format', :year => year, :month => month, :date => date)
|
|
421
|
+
end
|
|
422
|
+
row << expired_at
|
|
423
|
+
when :locked
|
|
424
|
+
row << I18n.t('activerecord.attributes.user.locked_yes') if user.active_for_authentication?
|
|
425
|
+
row << I18n.t('activerecord.attributes.user.locked_no') unless user.active_for_authentication?
|
|
426
|
+
when :unable
|
|
427
|
+
row << I18n.t('activerecord.attributes.user.unable_yes') if user.unable
|
|
428
|
+
row << I18n.t('activerecord.attributes.user.unable_no') unless user.unable
|
|
429
|
+
when :patron_type
|
|
430
|
+
row << user.patron.patron_type.display_name.localize
|
|
431
|
+
when :email
|
|
432
|
+
row << user.patron.email
|
|
433
|
+
when :url
|
|
434
|
+
row << user.patron.url
|
|
435
|
+
when :other_designation
|
|
436
|
+
row << user.patron.other_designation
|
|
437
|
+
when :place
|
|
438
|
+
row << user.patron.place
|
|
439
|
+
when :language
|
|
440
|
+
row << user.patron.language.display_name.localize
|
|
441
|
+
when :zip_code_1
|
|
442
|
+
row << user.patron.zip_code_1
|
|
443
|
+
when :address_1
|
|
444
|
+
row << user.patron.address_1
|
|
445
|
+
when :telephone_number_1
|
|
446
|
+
telephone_number_1 = user.patron.telephone_number_1
|
|
447
|
+
telephone_number_1 += ' (' + I18n.t(i18n_telephone_type(user.patron.telephone_number_1_type_id).strip_tags) +')' unless user.patron.telephone_number_1.blank?
|
|
448
|
+
row << telephone_number_1
|
|
449
|
+
when :extelephone_number_1
|
|
450
|
+
extelephone_number_1 = user.patron.extelephone_number_1
|
|
451
|
+
extelephone_number_1 += ' (' + I18n.t(i18n_telephone_type(user.patron.extelephone_number_1_type_id).strip_tags) +')' unless user.patron.extelephone_number_1.blank?
|
|
452
|
+
row << extelephone_number_1
|
|
453
|
+
when :fax_number_1
|
|
454
|
+
fax_number_1 = user.patron.fax_number_1
|
|
455
|
+
fax_number_1 += ' (' + I18n.t(i18n_telephone_type(user.patron.fax_number_1_type_id).strip_tags) +')' unless user.patron.fax_number_1.blank?
|
|
456
|
+
row << fax_number_1
|
|
457
|
+
when :address_1_note
|
|
458
|
+
row << user.patron.address_1_note
|
|
459
|
+
when :zip_code_2
|
|
460
|
+
row << user.patron.zip_code_2
|
|
461
|
+
when :address_2
|
|
462
|
+
row << user.patron.address_2
|
|
463
|
+
when :telephone_number_2
|
|
464
|
+
telephone_number_2 = user.patron.telephone_number_2
|
|
465
|
+
telephone_number_2 += ' (' + I18n.t(i18n_telephone_type(user.patron.telephone_number_2_type_id).strip_tags) +')' unless user.patron.telephone_number_2.blank?
|
|
466
|
+
row << telephone_number_2
|
|
467
|
+
when :extelephone_number_2
|
|
468
|
+
extelephone_number_2 = user.patron.extelephone_number_2
|
|
469
|
+
extelephone_number_2 += ' (' + I18n.t(i18n_telephone_type(user.patron.extelephone_number_2_type_id).strip_tags) +')' unless user.patron.extelephone_number_2.blank?
|
|
470
|
+
row << extelephone_number_2
|
|
471
|
+
when :fax_number_2
|
|
472
|
+
fax_number_2 = user.patron.fax_number_2
|
|
473
|
+
fax_number_2 += ' (' + I18n.t(i18n_telephone_type(user.patron.fax_number_2_type_id).strip_tags) +')' unless user.patron.fax_number_2.blank?
|
|
474
|
+
row << fax_number_2
|
|
475
|
+
when :address_2_note
|
|
476
|
+
row << user.patron.address_2_note
|
|
477
|
+
when :date_of_birth
|
|
478
|
+
date_of_birth = ""
|
|
479
|
+
if user.patron.date_of_birth
|
|
480
|
+
year = user.patron.date_of_birth.strftime("%Y")
|
|
481
|
+
month = user.patron.date_of_birth.strftime("%m")
|
|
482
|
+
date = user.patron.date_of_birth.strftime("%d")
|
|
483
|
+
date_of_birth = I18n.t('expense.date_format', :year => year, :month => month, :date => date)
|
|
484
|
+
end
|
|
485
|
+
row << date_of_birth
|
|
486
|
+
when :date_of_death
|
|
487
|
+
date_of_death = ""
|
|
488
|
+
if user.patron.date_of_death
|
|
489
|
+
year = user.patron.date_of_death.strftime("%Y")
|
|
490
|
+
month = user.patron.date_of_death.strftime("%m")
|
|
491
|
+
date = user.patron.date_of_death.strftime("%d")
|
|
492
|
+
date_of_death = I18n.t('expense.date_format', :year => year, :month => month, :date => date)
|
|
493
|
+
end
|
|
494
|
+
row << date_of_death
|
|
495
|
+
when :note
|
|
496
|
+
row << user.patron.note
|
|
497
|
+
when :note_update_at
|
|
498
|
+
note_update = user.patron.note_update_at.strftime("%Y/%m/%d %H:%M:%S") if user.patron.note_update_at
|
|
499
|
+
note_update += ' ' + I18n.t('patron.last_update_by') + ':' + user.patron.note_update_by if user.patron.note_update_by
|
|
500
|
+
note_update += '(' + user.patron.note_update_library + ')' if user.patron.note_update_library
|
|
501
|
+
row << note_update
|
|
502
|
+
when :patron_identifier
|
|
503
|
+
row << user.patron.patron_identifier
|
|
504
|
+
when :created_at
|
|
505
|
+
row << user.created_at.strftime("%Y/%m/%d %H:%M:%S")
|
|
506
|
+
when :updated_at
|
|
507
|
+
row << user.updated_at.strftime("%Y/%m/%d %H:%M:%S")
|
|
508
|
+
else
|
|
509
|
+
row << get_object_method(user, column[0].split('.')).to_s.gsub(/\r\n|\r|\n/," ").gsub(/\"/,"\"\"")
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
data << '"'+row.join("\"\t\"")+"\"\n"
|
|
513
|
+
end
|
|
514
|
+
return data
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
private
|
|
518
|
+
def self.get_object_method(obj,array)
|
|
519
|
+
_obj = obj.send(array.shift)
|
|
520
|
+
return get_object_method(_obj, array) if array.present?
|
|
521
|
+
return _obj
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# == Schema Information
|
|
526
|
+
#
|
|
527
|
+
# Table name: users
|
|
528
|
+
#
|
|
529
|
+
# id :integer not null, primary key
|
|
530
|
+
# email :string(255) default("")
|
|
531
|
+
# encrypted_password :string(255)
|
|
532
|
+
# confirmation_token :string(255)
|
|
533
|
+
# confirmed_at :datetime
|
|
534
|
+
# confirmation_sent_at :datetime
|
|
535
|
+
# reset_password_token :string(255)
|
|
536
|
+
# reset_password_sent_at :datetime
|
|
537
|
+
# remember_token :string(255)
|
|
538
|
+
# remember_created_at :datetime
|
|
539
|
+
# sign_in_count :integer default(0)
|
|
540
|
+
# current_sign_in_at :datetime
|
|
541
|
+
# last_sign_in_at :datetime
|
|
542
|
+
# current_sign_in_ip :string(255)
|
|
543
|
+
# last_sign_in_ip :string(255)
|
|
544
|
+
# failed_attempts :integer default(0)
|
|
545
|
+
# unlock_token :string(255)
|
|
546
|
+
# locked_at :datetime
|
|
547
|
+
# authentication_token :string(255)
|
|
548
|
+
# password_salt :string(255)
|
|
549
|
+
# created_at :datetime
|
|
550
|
+
# updated_at :datetime
|
|
551
|
+
# deleted_at :datetime
|
|
552
|
+
# username :string(255)
|
|
553
|
+
# library_id :integer default(1), not null
|
|
554
|
+
# user_group_id :integer default(1), not null
|
|
555
|
+
# reserves_count :integer default(0), not null
|
|
556
|
+
# expired_at :datetime
|
|
557
|
+
# libraries_count :integer default(0), not null
|
|
558
|
+
# bookmarks_count :integer default(0), not null
|
|
559
|
+
# checkouts_count :integer default(0), not null
|
|
560
|
+
# checkout_icalendar_token :string(255)
|
|
561
|
+
# questions_count :integer default(0), not null
|
|
562
|
+
# answers_count :integer default(0), not null
|
|
563
|
+
# answer_feed_token :string(255)
|
|
564
|
+
# due_date_reminder_days :integer default(1), not null
|
|
565
|
+
# note :text
|
|
566
|
+
# share_bookmarks :boolean default(FALSE), not null
|
|
567
|
+
# save_search_history :boolean default(FALSE), not null
|
|
568
|
+
# save_checkout_history :boolean default(FALSE), not null
|
|
569
|
+
# required_role_id :integer default(1), not null
|
|
570
|
+
# keyword_list :text
|
|
571
|
+
# user_number :string(255)
|
|
572
|
+
# state :string(255)
|
|
573
|
+
# required_score :integer default(0), not null
|
|
574
|
+
# locale :string(255)
|
|
575
|
+
# openid_identifier :string(255)
|
|
576
|
+
# oauth_token :string(255)
|
|
577
|
+
# oauth_secret :string(255)
|
|
578
|
+
# enju_access_key :string(255)
|
|
579
|
+
#
|
|
580
|
+
|