enju_leaf 1.2.0.beta.1 → 1.2.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/enju_leaf/engine.rb +1 -15
- data/lib/enju_leaf/version.rb +1 -1
- data/lib/generators/enju_leaf/quick_install/quick_install_generator.rb +3 -3
- data/lib/generators/enju_leaf/setup/setup_generator.rb +0 -1
- data/spec/controllers/page_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +0 -1
- data/spec/dummy/app/helpers/application_helper.rb +2 -1
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/config/application.rb +1 -2
- data/{db → spec/dummy/db}/migrate/041_create_roles.rb +0 -0
- data/spec/dummy/db/migrate/059_create_libraries.rb +1 -5
- data/spec/dummy/db/migrate/069_create_shelves.rb +1 -5
- data/{db → spec/dummy/db}/migrate/077_create_user_groups.rb +0 -0
- data/spec/dummy/db/migrate/130_create_request_status_types.rb +1 -5
- data/spec/dummy/db/migrate/131_create_request_types.rb +1 -5
- data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +9 -0
- data/{db → spec/dummy/db}/migrate/20100606065209_create_user_has_roles.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +0 -0
- data/spec/dummy/db/migrate/20111129044509_add_pickup_location_to_reserve.rb +6 -0
- data/{db → spec/dummy/db}/migrate/20130221154434_add_additional_attributes_to_user.rb +0 -0
- data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +6 -0
- data/{db → spec/dummy/db}/migrate/20140110122216_create_user_import_files.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140110131010_create_user_import_results.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140122054321_create_profiles.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140524074813_create_user_import_file_transitions.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140628072217_add_user_encoding_to_user_import_file.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140709113413_create_user_export_files.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140709113905_create_user_export_file_transitions.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140720170714_add_default_library_id_to_user_import_file.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140720170735_add_default_user_group_id_to_user_import_file.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20140811031145_add_expired_at_to_profile.rb +0 -0
- data/spec/dummy/db/migrate/20140821151023_create_colors.rb +14 -0
- data/{db → spec/dummy/db}/migrate/20141003181336_add_full_name_transcription_to_profile.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20141003182825_add_date_of_birth_to_profile.rb +0 -0
- data/spec/dummy/db/migrate/20141020120523_add_library_id_to_checkout.rb +6 -0
- data/spec/dummy/db/migrate/20150106001709_create_demands.rb +14 -0
- data/{db → spec/dummy/db}/migrate/20150421023923_create_identities.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20150506105356_add_error_message_to_user_import_result.rb +0 -0
- data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
- data/{db → spec/dummy/db}/migrate/20151126005552_add_provider_to_identity.rb +0 -0
- data/spec/dummy/db/migrate/20160610093229_add_html_snippet_to_library_group.rb +5 -0
- data/{db → spec/dummy/db}/migrate/20160627232219_add_most_recent_to_user_import_file_transitions.rb +0 -0
- data/{db → spec/dummy/db}/migrate/20160627232316_add_most_recent_to_user_export_file_transitions.rb +0 -0
- data/spec/dummy/db/migrate/20160703184619_add_most_recent_to_reserve_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703184650_add_most_recent_to_manifestation_checkout_stat_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703184723_add_most_recent_to_manifestation_reserve_stat_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703184747_add_most_recent_to_user_checkout_stat_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703184805_add_most_recent_to_user_reserve_stat_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703185015_add_most_recent_to_message_transitions.rb +9 -0
- data/spec/dummy/db/migrate/20160703190209_add_foreign_key_on_manifestation_id_to_reserve.rb +5 -0
- data/spec/dummy/db/schema.rb +47 -12
- data/spec/fixtures/library_groups.yml +1 -4
- data/spec/models/user_spec.rb +0 -22
- data/spec/rails_helper.rb +1 -1
- data/spec/views/page/index.html.erb_spec.rb +0 -2
- metadata +96 -337
- data/app/controllers/concerns/enju_leaf/controller.rb +0 -225
- data/app/controllers/my_accounts_controller.rb +0 -93
- data/app/controllers/names_controller.rb +0 -60
- data/app/controllers/profiles_controller.rb +0 -219
- data/app/controllers/roles_controller.rb +0 -61
- data/app/controllers/user_export_files_controller.rb +0 -116
- data/app/controllers/user_groups_controller.rb +0 -118
- data/app/controllers/user_import_files_controller.rb +0 -129
- data/app/controllers/user_import_results_controller.rb +0 -57
- data/app/mailers/notifier.rb +0 -30
- data/app/models/identity.rb +0 -9
- data/app/models/profile.rb +0 -101
- data/app/models/role.rb +0 -50
- data/app/models/user_export_file.rb +0 -67
- data/app/models/user_export_file_state_machine.rb +0 -15
- data/app/models/user_export_file_transition.rb +0 -20
- data/app/models/user_group.rb +0 -29
- data/app/models/user_has_role.rb +0 -19
- data/app/models/user_import_file.rb +0 -352
- data/app/models/user_import_file_state_machine.rb +0 -19
- data/app/models/user_import_file_transition.rb +0 -20
- data/app/models/user_import_result.rb +0 -20
- data/app/policies/application_policy.rb +0 -53
- data/app/policies/name_policy.rb +0 -21
- data/app/policies/profile_policy.rb +0 -55
- data/app/policies/role_policy.rb +0 -21
- data/app/policies/user_export_file_policy.rb +0 -21
- data/app/policies/user_group_policy.rb +0 -22
- data/app/policies/user_import_file_policy.rb +0 -21
- data/app/policies/user_import_result_policy.rb +0 -21
- data/app/views/my_accounts/_edit_credential.html.erb +0 -99
- data/app/views/my_accounts/_form.html.erb +0 -24
- data/app/views/my_accounts/_show.html.erb +0 -1
- data/app/views/my_accounts/edit.html.erb +0 -32
- data/app/views/my_accounts/show.html+phone.erb +0 -1
- data/app/views/my_accounts/show.html.erb +0 -49
- data/app/views/names/_form.html.erb +0 -41
- data/app/views/names/edit.html.erb +0 -6
- data/app/views/names/index.html.erb +0 -37
- data/app/views/names/new.html.erb +0 -5
- data/app/views/names/show.html.erb +0 -34
- data/app/views/profiles/_edit_credential.html.erb +0 -88
- data/app/views/profiles/_edit_profile.html.erb +0 -42
- data/app/views/profiles/_form.html.erb +0 -15
- data/app/views/profiles/_show.html.erb +0 -1
- data/app/views/profiles/edit.html.erb +0 -33
- data/app/views/profiles/index.html.erb +0 -70
- data/app/views/profiles/new.html.erb +0 -88
- data/app/views/profiles/show.html+phone.erb +0 -1
- data/app/views/profiles/show.html.erb +0 -71
- data/app/views/roles/_form.html.erb +0 -19
- data/app/views/roles/edit.html.erb +0 -13
- data/app/views/roles/index.html.erb +0 -32
- data/app/views/roles/new.html.erb +0 -12
- data/app/views/roles/show.html.erb +0 -46
- data/app/views/user_export_files/_form.html.erb +0 -12
- data/app/views/user_export_files/edit.html.erb +0 -6
- data/app/views/user_export_files/index.html.erb +0 -44
- data/app/views/user_export_files/new.html.erb +0 -16
- data/app/views/user_export_files/show.html.erb +0 -36
- data/app/views/user_groups/_form.html.erb +0 -40
- data/app/views/user_groups/edit.html.erb +0 -13
- data/app/views/user_groups/index.html.erb +0 -51
- data/app/views/user_groups/new.html.erb +0 -12
- data/app/views/user_groups/show.html.erb +0 -68
- data/app/views/user_import_files/_form.html.erb +0 -61
- data/app/views/user_import_files/_results.html.erb +0 -22
- data/app/views/user_import_files/edit.html.erb +0 -6
- data/app/views/user_import_files/index.html.erb +0 -45
- data/app/views/user_import_files/new.html.erb +0 -60
- data/app/views/user_import_files/show.html.erb +0 -85
- data/app/views/user_import_results/_form.html.erb +0 -29
- data/app/views/user_import_results/_list.html.erb +0 -22
- data/app/views/user_import_results/_list_lines.html.erb +0 -24
- data/app/views/user_import_results/index.html.erb +0 -25
- data/app/views/user_import_results/index.txt.erb +0 -3
- data/app/views/user_import_results/show.html.erb +0 -33
- data/db/migrate/20091202124834_create_versions.rb +0 -18
- data/spec/controllers/my_accounts_controller_spec.rb +0 -229
- data/spec/controllers/profiles_controller_spec.rb +0 -594
- data/spec/controllers/roles_controller_spec.rb +0 -136
- data/spec/controllers/user_export_files_controller_spec.rb +0 -296
- data/spec/controllers/user_groups_controller_spec.rb +0 -443
- data/spec/controllers/user_import_files_controller_spec.rb +0 -305
- data/spec/controllers/user_import_results_controller_spec.rb +0 -157
- data/spec/fixtures/user_export_files.yml +0 -25
- data/spec/fixtures/user_import_files.yml +0 -51
- data/spec/fixtures/user_import_results.yml +0 -26
- data/spec/fixtures/user_reserve_stats.yml +0 -27
- data/spec/models/basket_spec.rb +0 -23
- data/spec/models/profile_spec.rb +0 -98
- data/spec/models/role_spec.rb +0 -40
- data/spec/models/user_export_file_spec.rb +0 -30
- data/spec/models/user_group_spec.rb +0 -37
- data/spec/models/user_has_role_spec.rb +0 -18
- data/spec/models/user_import_file_spec.rb +0 -220
- data/spec/models/user_import_result_spec.rb +0 -20
- data/spec/requests/profiles_spec.rb +0 -9
- data/spec/routing/profiles_routing_spec.rb +0 -35
- data/spec/routing/resource_import_files_routing_spec.rb +0 -35
- data/spec/routing/roles_routing_spec.rb +0 -35
- data/spec/routing/users_spec.rb +0 -14
- data/spec/views/my_accounts/show.html.erb_spec.rb +0 -43
- data/spec/views/profiles/edit.html.erb_spec.rb +0 -42
- data/spec/views/profiles/index.html.erb_spec.rb +0 -19
- data/spec/views/profiles/new.html.erb_spec.rb +0 -25
- data/spec/views/profiles/show.html.erb_spec.rb +0 -31
- data/spec/views/user_export_files/new.html.erb_spec.rb +0 -19
- data/spec/views/user_import_results/index.html.erb_spec.rb +0 -29
@@ -1,225 +0,0 @@
|
|
1
|
-
module EnjuLeaf
|
2
|
-
module Controller
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
before_action :get_library_group, :set_locale, :set_available_languages, :set_mobile_request
|
7
|
-
before_action :store_current_location, unless: :devise_controller?
|
8
|
-
rescue_from Pundit::NotAuthorizedError, with: :render_403
|
9
|
-
#rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
10
|
-
rescue_from Errno::ECONNREFUSED, with: :render_500_nosolr
|
11
|
-
#rescue_from ActionView::MissingTemplate, with: :render_404_invalid_format
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def render_403
|
17
|
-
return if performed?
|
18
|
-
if user_signed_in?
|
19
|
-
respond_to do |format|
|
20
|
-
format.html {render template: 'page/403', status: 403}
|
21
|
-
#format.html.phone {render template: 'page/403', status: 403}
|
22
|
-
format.xml {render template: 'page/403', status: 403}
|
23
|
-
format.json { render text: '{"error": "forbidden"}' }
|
24
|
-
format.rss {render template: 'page/403.xml', status: 403}
|
25
|
-
end
|
26
|
-
else
|
27
|
-
respond_to do |format|
|
28
|
-
format.html { redirect_to main_app.new_user_session_url }
|
29
|
-
#format.html.phone { redirect_to new_user_session_url }
|
30
|
-
format.xml { render template: 'page/403', status: 403 }
|
31
|
-
format.json { render text: '{"error": "forbidden"}' }
|
32
|
-
format.rss { render template: 'page/403.xml', status: 403 }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def render_404
|
38
|
-
return if performed?
|
39
|
-
respond_to do |format|
|
40
|
-
format.html { render template: 'page/404', status: 404 }
|
41
|
-
#format.html.phone { render template: 'page/404', status: 404 }
|
42
|
-
format.xml { render template: 'page/404', status: 404 }
|
43
|
-
format.json { render text: '{"error": "not_found"}' }
|
44
|
-
format.rss { render template: 'page/404.xml', status: 404 }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def render_404_invalid_format
|
49
|
-
return if performed?
|
50
|
-
render file: "#{Rails.root}/public/404", formats: [:html]
|
51
|
-
end
|
52
|
-
|
53
|
-
def render_500
|
54
|
-
return if performed?
|
55
|
-
respond_to do |format|
|
56
|
-
format.html {render file: "#{Rails.root}/public/500", layout: false, status: 500}
|
57
|
-
#format.html.phone {render file: "#{Rails.root}/public/500", layout: false, status: 500}
|
58
|
-
format.xml {render template: 'page/500', status: 500}
|
59
|
-
format.json { render text: '{"error": "server_error"}' }
|
60
|
-
format.xml {render template: 'page/500.xml', status: 500}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def render_500_nosolr
|
65
|
-
Rails.logger.fatal("please confirm that the Solr is running.")
|
66
|
-
return if performed?
|
67
|
-
#flash[:notice] = t('page.connection_failed')
|
68
|
-
respond_to do |format|
|
69
|
-
format.html {render template: "page/500_nosolr", layout: false, status: 500}
|
70
|
-
#format.html.phone {render template: "page/500_nosolr", layout: false, status: 500}
|
71
|
-
format.xml {render template: 'page/500', status: 500}
|
72
|
-
format.json { render text: '{"error": "server_error"}' }
|
73
|
-
format.xml {render template: 'page/500.xml', status: 500}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def after_sign_in_path_for(resource)
|
78
|
-
session[:locale] = nil
|
79
|
-
super
|
80
|
-
end
|
81
|
-
|
82
|
-
def set_locale
|
83
|
-
if params[:locale]
|
84
|
-
unless I18n.available_locales.include?(params[:locale].to_s.intern)
|
85
|
-
raise InvalidLocaleError
|
86
|
-
end
|
87
|
-
end
|
88
|
-
if user_signed_in?
|
89
|
-
locale = params[:locale] || session[:locale] || current_user.profile.try(:locale).try(:to_sym)
|
90
|
-
else
|
91
|
-
locale = params[:locale] || session[:locale]
|
92
|
-
end
|
93
|
-
if locale
|
94
|
-
I18n.locale = @locale = session[:locale] = locale.to_sym
|
95
|
-
else
|
96
|
-
I18n.locale = @locale = session[:locale] = I18n.default_locale
|
97
|
-
end
|
98
|
-
rescue InvalidLocaleError
|
99
|
-
@locale = I18n.default_locale
|
100
|
-
end
|
101
|
-
|
102
|
-
def default_url_options(options={})
|
103
|
-
{locale: nil}
|
104
|
-
end
|
105
|
-
|
106
|
-
def set_available_languages
|
107
|
-
if Rails.env == 'production'
|
108
|
-
@available_languages = Rails.cache.fetch('available_languages'){
|
109
|
-
Language.where(iso_639_1: I18n.available_locales.map{|l| l.to_s}).select([:id, :iso_639_1, :name, :native_name, :display_name, :position]).all
|
110
|
-
}
|
111
|
-
else
|
112
|
-
@available_languages = Language.where(iso_639_1: I18n.available_locales.map{|l| l.to_s})
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def reset_params_session
|
117
|
-
session[:params] = nil
|
118
|
-
end
|
119
|
-
|
120
|
-
def not_found
|
121
|
-
raise ActiveRecord::RecordNotFound
|
122
|
-
end
|
123
|
-
|
124
|
-
def access_denied
|
125
|
-
raise Pundit::NotAuthorizedError
|
126
|
-
end
|
127
|
-
|
128
|
-
def get_user
|
129
|
-
@user = User.where(username: params[:user_id]).first if params[:user_id]
|
130
|
-
#authorize! :show, @user if @user
|
131
|
-
end
|
132
|
-
|
133
|
-
def get_user_group
|
134
|
-
@user_group = UserGroup.find(params[:user_group_id]) if params[:user_group_id]
|
135
|
-
end
|
136
|
-
|
137
|
-
def convert_charset
|
138
|
-
case params[:format]
|
139
|
-
when 'csv'
|
140
|
-
return unless LibraryGroup.site_config.settings[:csv_charset_conversion]
|
141
|
-
# TODO: 他の言語
|
142
|
-
if @locale.to_sym == :ja
|
143
|
-
headers["Content-Type"] = "text/csv; charset=Shift_JIS"
|
144
|
-
response.body = NKF::nkf('-Ws', response.body)
|
145
|
-
end
|
146
|
-
when 'xml'
|
147
|
-
if @locale.to_sym == :ja
|
148
|
-
headers["Content-Type"] = "application/xml; charset=Shift_JIS"
|
149
|
-
response.body = NKF::nkf('-Ws', response.body)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def store_page
|
155
|
-
if request.get? and request.format.try(:html?) and !request.xhr?
|
156
|
-
flash[:page] = params[:page] if params[:page].to_i > 0
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def set_role_query(user, search)
|
161
|
-
role = user.try(:role) || Role.default_role
|
162
|
-
search.build do
|
163
|
-
with(:required_role_id).less_than_or_equal_to role.id
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def get_version
|
168
|
-
@version = params[:version_id].to_i if params[:version_id]
|
169
|
-
@version = nil if @version == 0
|
170
|
-
end
|
171
|
-
|
172
|
-
def clear_search_sessions
|
173
|
-
session[:query] = nil
|
174
|
-
session[:params] = nil
|
175
|
-
session[:search_params] = nil
|
176
|
-
session[:manifestation_ids] = nil
|
177
|
-
end
|
178
|
-
|
179
|
-
def api_request?
|
180
|
-
true unless params[:format].nil? or params[:format] == 'html'
|
181
|
-
end
|
182
|
-
|
183
|
-
def get_top_page_content
|
184
|
-
if defined?(EnjuNews)
|
185
|
-
@news_feeds = Rails.cache.fetch('news_feed_all'){NewsFeed.order(:position)}
|
186
|
-
@news_posts = NewsPost.limit(LibraryGroup.site_config.settings[:news_post_number_top_page] || 10)
|
187
|
-
end
|
188
|
-
@libraries = Library.real
|
189
|
-
end
|
190
|
-
|
191
|
-
def set_mobile_request
|
192
|
-
case params[:view]
|
193
|
-
when 'phone'
|
194
|
-
session[:enju_view] = :phone
|
195
|
-
when 'desktop'
|
196
|
-
session[:enju_view] = :desktop
|
197
|
-
when 'reset'
|
198
|
-
session[:enju_view] = nil
|
199
|
-
end
|
200
|
-
|
201
|
-
case session[:enju_view].try(:to_sym)
|
202
|
-
when :phone
|
203
|
-
request.variant = :phone
|
204
|
-
when :desktop
|
205
|
-
request.variant = nil
|
206
|
-
else
|
207
|
-
request.variant = :phone if browser.device.mobile?
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def move_position(resource, direction, redirect = true)
|
212
|
-
if ['higher', 'lower'].include?(direction)
|
213
|
-
resource.send("move_#{direction}")
|
214
|
-
if redirect
|
215
|
-
redirect_to url_for(controller: resource.class.to_s.pluralize.underscore)
|
216
|
-
return
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def store_current_location
|
222
|
-
store_location_for(:user, request.url)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
class MyAccountsController < ApplicationController
|
2
|
-
before_action :authenticate_user!
|
3
|
-
before_action :set_profile
|
4
|
-
|
5
|
-
def show
|
6
|
-
respond_to do |format|
|
7
|
-
format.html
|
8
|
-
format.html.phone
|
9
|
-
format.json { render json: @profile }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def edit
|
14
|
-
prepare_options
|
15
|
-
end
|
16
|
-
|
17
|
-
def update
|
18
|
-
user_attrs = [
|
19
|
-
:id, :email, :current_password, :password, :password_confirmation
|
20
|
-
]
|
21
|
-
user_attrs += [
|
22
|
-
{:user_has_role_attributes => [:id, :role_id]}
|
23
|
-
] if current_user.has_role?('Administrator')
|
24
|
-
|
25
|
-
user_params = ActionController::Parameters.new(params[:profile][:user_attributes]).permit(*user_attrs)
|
26
|
-
|
27
|
-
respond_to do |format|
|
28
|
-
saved = current_user.update_attributes(user_params)
|
29
|
-
@profile.assign_attributes(profile_params)
|
30
|
-
|
31
|
-
if saved
|
32
|
-
if @profile.save
|
33
|
-
bypass_sign_in(current_user)
|
34
|
-
format.html { redirect_to my_account_url, notice: t('controller.successfully_updated', model: t('activerecord.models.user')) }
|
35
|
-
format.json { head :no_content }
|
36
|
-
else
|
37
|
-
prepare_options
|
38
|
-
format.html { render action: "edit" }
|
39
|
-
format.json { render json: current_user.errors, status: :unprocessable_entity }
|
40
|
-
end
|
41
|
-
else
|
42
|
-
current_user.errors.full_messages.each do |msg|
|
43
|
-
@profile.errors[:base] << msg
|
44
|
-
end
|
45
|
-
prepare_options
|
46
|
-
format.html { render action: "edit" }
|
47
|
-
format.json { render json: current_user.errors, status: :unprocessable_entity }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def destroy
|
53
|
-
@profile.destroy
|
54
|
-
|
55
|
-
respond_to do |format|
|
56
|
-
format.html { redirect_to my_account_url, notice: 'devise.registrations.destroyed' }
|
57
|
-
format.json { head :no_content }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
def set_profile
|
63
|
-
@profile = current_user.profile
|
64
|
-
authorize @profile
|
65
|
-
end
|
66
|
-
|
67
|
-
def profile_params
|
68
|
-
attrs = [
|
69
|
-
:full_name, :full_name_transcription, :user_number,
|
70
|
-
:library_id, :keyword_list, :note,
|
71
|
-
:locale, :required_role_id, :expired_at,
|
72
|
-
:locked, :birth_date,
|
73
|
-
:save_checkout_history, :checkout_icalendar_token, # EnjuCirculation
|
74
|
-
:save_search_history # EnjuSearchLog
|
75
|
-
]
|
76
|
-
if current_user.has_role?('Librarian')
|
77
|
-
attrs << :user_group_id
|
78
|
-
end
|
79
|
-
params.require(:profile).permit(*attrs)
|
80
|
-
end
|
81
|
-
|
82
|
-
def prepare_options
|
83
|
-
@user_groups = UserGroup.order(:position)
|
84
|
-
@roles = Role.order(:position)
|
85
|
-
@libraries = Library.order(:position)
|
86
|
-
@languages = Language.order(:position)
|
87
|
-
if current_user.active_for_authentication?
|
88
|
-
current_user.locked = '0'
|
89
|
-
else
|
90
|
-
current_user.locked = '1'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
class NamesController < ApplicationController
|
2
|
-
before_action :set_name, only: [:show, :edit, :update, :destroy]
|
3
|
-
before_action :check_policy, only: [:index, :new, :create]
|
4
|
-
|
5
|
-
# GET /names
|
6
|
-
def index
|
7
|
-
@names = Name.paginate(params[:page])
|
8
|
-
end
|
9
|
-
|
10
|
-
# GET /names/1
|
11
|
-
def show
|
12
|
-
end
|
13
|
-
|
14
|
-
# GET /names/new
|
15
|
-
def new
|
16
|
-
@name = Name.new
|
17
|
-
end
|
18
|
-
|
19
|
-
# GET /names/1/edit
|
20
|
-
def edit
|
21
|
-
end
|
22
|
-
|
23
|
-
# POST /names
|
24
|
-
def create
|
25
|
-
@name = Name.new(name_params)
|
26
|
-
|
27
|
-
if @name.save
|
28
|
-
redirect_to @name, notice: 'Name was successfully created.'
|
29
|
-
else
|
30
|
-
render :new
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# PATCH/PUT /names/1
|
35
|
-
def update
|
36
|
-
if @name.update(name_params)
|
37
|
-
redirect_to @name, notice: 'Name was successfully updated.'
|
38
|
-
else
|
39
|
-
render :edit
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# DELETE /names/1
|
44
|
-
def destroy
|
45
|
-
@name.destroy
|
46
|
-
redirect_to names_url, notice: 'Name was successfully destroyed.'
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
# Use callbacks to share common setup or constraints between actions.
|
51
|
-
def set_name
|
52
|
-
@name = Name.find(params[:id])
|
53
|
-
authorize @name
|
54
|
-
end
|
55
|
-
|
56
|
-
# Only allow a trusted parameter "white list" through.
|
57
|
-
def name_params
|
58
|
-
params.require(:name).permit(:first_name, :middle_name, :last_name, :language_id, :profile_id, :position)
|
59
|
-
end
|
60
|
-
end
|
@@ -1,219 +0,0 @@
|
|
1
|
-
class ProfilesController < ApplicationController
|
2
|
-
before_action :set_profile, only: [:show, :edit, :update, :destroy]
|
3
|
-
before_action :check_policy, only: [:index, :new, :create]
|
4
|
-
before_action :prepare_options, only: [:new, :edit]
|
5
|
-
|
6
|
-
# GET /profiles
|
7
|
-
# GET /profiles.json
|
8
|
-
def index
|
9
|
-
if params[:username].present?
|
10
|
-
profile = User.where(username: params[:username]).first.try(:profile)
|
11
|
-
if profile
|
12
|
-
redirect_to profile
|
13
|
-
return
|
14
|
-
end
|
15
|
-
end
|
16
|
-
query = flash[:query] = params[:query].to_s
|
17
|
-
@query = query.dup
|
18
|
-
@count = {}
|
19
|
-
|
20
|
-
sort = {sort_by: 'created_at', order: 'desc'}
|
21
|
-
case params[:sort_by]
|
22
|
-
when 'username'
|
23
|
-
sort[:sort_by] = 'username'
|
24
|
-
end
|
25
|
-
case params[:order]
|
26
|
-
when 'asc'
|
27
|
-
sort[:order] = 'asc'
|
28
|
-
when 'desc'
|
29
|
-
sort[:order] = 'desc'
|
30
|
-
end
|
31
|
-
|
32
|
-
query = params[:query]
|
33
|
-
page = params[:page] || 1
|
34
|
-
role = current_user.try(:role) || Role.default_role
|
35
|
-
|
36
|
-
search = Profile.search
|
37
|
-
search.build do
|
38
|
-
fulltext query if query
|
39
|
-
with(:required_role_id).less_than_or_equal_to role.id
|
40
|
-
order_by sort[:sort_by], sort[:order]
|
41
|
-
end
|
42
|
-
search.query.paginate(page.to_i, Profile.default_per_page)
|
43
|
-
@profiles = search.execute!.results
|
44
|
-
@count[:query_result] = @profiles.total_entries
|
45
|
-
|
46
|
-
respond_to do |format|
|
47
|
-
format.html # index.html.erb
|
48
|
-
format.json { render json: @profiles }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# GET /profiles/1
|
53
|
-
# GET /profiles/1.json
|
54
|
-
def show
|
55
|
-
if @profile.user == current_user
|
56
|
-
redirect_to my_account_url
|
57
|
-
return
|
58
|
-
end
|
59
|
-
|
60
|
-
respond_to do |format|
|
61
|
-
format.html # show.html.erb
|
62
|
-
format.html.phone
|
63
|
-
format.json { render json: @profile }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# GET /profiles/new
|
68
|
-
def new
|
69
|
-
@profile = Profile.new
|
70
|
-
@profile.user = User.new
|
71
|
-
@profile.user_group = current_user.profile.user_group
|
72
|
-
@profile.library = current_user.profile.library
|
73
|
-
@profile.locale = current_user.profile.locale
|
74
|
-
|
75
|
-
respond_to do |format|
|
76
|
-
format.html # new.html.erb
|
77
|
-
format.json { render json: @profile }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# GET /profiles/1/edit
|
82
|
-
def edit
|
83
|
-
if defined?(EnjuCirculation)
|
84
|
-
if params[:mode] == 'feed_token'
|
85
|
-
if params[:disable] == 'true'
|
86
|
-
@profile.delete_checkout_icalendar_token
|
87
|
-
else
|
88
|
-
@profile.reset_checkout_icalendar_token
|
89
|
-
end
|
90
|
-
render partial: 'feed_token', locals: {profile: @profile}
|
91
|
-
return
|
92
|
-
end
|
93
|
-
end
|
94
|
-
if @profile.user == current_user
|
95
|
-
redirect_to edit_my_account_url
|
96
|
-
return
|
97
|
-
end
|
98
|
-
if @profile.user.try(:locked_at?)
|
99
|
-
@profile.user.locked = true
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# POST /profiles
|
104
|
-
# POST /profiles.json
|
105
|
-
def create
|
106
|
-
if current_user.has_role?('Librarian')
|
107
|
-
@profile = Profile.new(profile_params)
|
108
|
-
if @profile.user
|
109
|
-
password = @profile.user.set_auto_generated_password
|
110
|
-
end
|
111
|
-
else
|
112
|
-
@profile = Profile.new(profile_params)
|
113
|
-
end
|
114
|
-
|
115
|
-
respond_to do |format|
|
116
|
-
if @profile.save
|
117
|
-
if @profile.user
|
118
|
-
@profile.user.role = Role.where(name: 'User').first
|
119
|
-
flash[:temporary_password] = password
|
120
|
-
end
|
121
|
-
format.html { redirect_to @profile, notice: t('controller.successfully_created', model: t('activerecord.models.profile')) }
|
122
|
-
format.json { render json: @profile, status: :created, location: @profile }
|
123
|
-
else
|
124
|
-
prepare_options
|
125
|
-
format.html { render action: "new" }
|
126
|
-
format.json { render json: @profile.errors, status: :unprocessable_entity }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# PUT /profiles/1
|
132
|
-
# PUT /profiles/1.json
|
133
|
-
def update
|
134
|
-
@profile.update_attributes(profile_update_params)
|
135
|
-
if @profile.user
|
136
|
-
if @profile.user.auto_generated_password == "1"
|
137
|
-
password = @profile.user.set_auto_generated_password
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
respond_to do |format|
|
142
|
-
if @profile.save
|
143
|
-
flash[:temporary_password] = password
|
144
|
-
format.html { redirect_to @profile, notice: t('controller.successfully_updated', model: t('activerecord.models.profile')) }
|
145
|
-
format.json { head :no_content }
|
146
|
-
else
|
147
|
-
prepare_options
|
148
|
-
format.html { render action: "edit" }
|
149
|
-
format.json { render json: @profile.errors, status: :unprocessable_entity }
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# DELETE /profiles/1
|
155
|
-
# DELETE /profiles/1.json
|
156
|
-
def destroy
|
157
|
-
@profile.destroy
|
158
|
-
|
159
|
-
respond_to do |format|
|
160
|
-
format.html { redirect_to profiles_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.profile')) }
|
161
|
-
format.json { head :no_content }
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
private
|
166
|
-
def set_profile
|
167
|
-
@profile = Profile.find(params[:id])
|
168
|
-
authorize @profile
|
169
|
-
end
|
170
|
-
|
171
|
-
def check_policy
|
172
|
-
authorize Profile
|
173
|
-
end
|
174
|
-
|
175
|
-
def profile_params
|
176
|
-
attrs = [
|
177
|
-
:full_name, :full_name_transcription,
|
178
|
-
:keyword_list, :locale,
|
179
|
-
:save_checkout_history, :checkout_icalendar_token, # EnjuCirculation
|
180
|
-
:save_search_history, # EnjuSearchLog
|
181
|
-
]
|
182
|
-
attrs += [
|
183
|
-
:library_id, :expired_at, :birth_date,
|
184
|
-
:user_group_id, :required_role_id, :note, :user_number, {
|
185
|
-
:user_attributes => [
|
186
|
-
:id, :username, :email, :current_password, :locked,
|
187
|
-
{:user_has_role_attributes => [:id, :role_id]}
|
188
|
-
]
|
189
|
-
}
|
190
|
-
] if current_user.has_role?('Librarian')
|
191
|
-
params.require(:profile).permit(*attrs)
|
192
|
-
end
|
193
|
-
|
194
|
-
def profile_update_params
|
195
|
-
attrs = [
|
196
|
-
:full_name, :full_name_transcription,
|
197
|
-
:keyword_list, :locale,
|
198
|
-
:save_checkout_history, :checkout_icalendar_token, # EnjuCirculation
|
199
|
-
:save_search_history, # EnjuSearchLog
|
200
|
-
]
|
201
|
-
attrs += [
|
202
|
-
:library_id, :expired_at, :birth_date,
|
203
|
-
:user_group_id, :required_role_id, :note, :user_number, {
|
204
|
-
:user_attributes => [
|
205
|
-
:id, :email, :current_password, :auto_generated_password, :locked,
|
206
|
-
{:user_has_role_attributes => [:id, :role_id]}
|
207
|
-
]
|
208
|
-
}
|
209
|
-
] if current_user.has_role?('Librarian')
|
210
|
-
params.require(:profile).permit(*attrs)
|
211
|
-
end
|
212
|
-
|
213
|
-
def prepare_options
|
214
|
-
@user_groups = UserGroup.all
|
215
|
-
@roles = Role.all
|
216
|
-
@libraries = Library.all
|
217
|
-
@languages = Language.all
|
218
|
-
end
|
219
|
-
end
|