Class: StudiesController
Overview
rubocop:todo Metrics/ClassLength
Constant Summary
FlashTruncation::STRING_OVERHEAD
Class Method Summary
collapse
Instance Method Summary
collapse
#application, #application=, #defaults, #defaults=, #global_searchable_classes, #search_options
#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!
#max_flash_size, #truncate_flash, #truncate_flash_array
Class Method Details
.role_helper(name, success_action, error_action) ⇒ Object
rubocop:todo Metrics/MethodLength
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'app/controllers/studies_controller.rb', line 282
def self.role_helper(name, success_action, error_action) define_method(:"#{name}_role") do
ActiveRecord::Base.transaction do
@study = Study.find(params[:id])
@user = User.find(params.require(:role).fetch(:user))
if request.xhr?
yield(@user, @study, params[:role][:authorizable_type].to_s)
status, flash.now[:notice] = 200, "Role #{success_action}"
else
status, flash.now[:error] = 401, "A problem occurred while #{error_action} the role"
end
@roles = @study.roles.reload
render partial: 'roles', status: status
end
end
end
|
Instance Method Details
#accession ⇒ Object
rubocop:enable Metrics/MethodLength
235
236
237
238
239
240
241
242
243
244
|
# File 'app/controllers/studies_controller.rb', line 235
def accession
rescue_accession_errors do
@study = Study.find(params[:id])
@study.validate_ena_required_fields!
@study.accession_service.submit_study_for_user(@study, current_user)
flash[:notice] = "Accession number generated: #{@study.ebi_accession_number}"
redirect_to(study_path(@study))
end
end
|
#accession_all_samples ⇒ Object
246
247
248
249
250
251
|
# File 'app/controllers/studies_controller.rb', line 246
def accession_all_samples
@study = Study.find(params[:id])
@study.accession_all_samples
flash[:notice] = 'All of the samples in this study have been sent for accessioning.'
redirect_to(study_path(@study))
end
|
#close ⇒ Object
172
173
174
175
176
177
178
179
180
181
|
# File 'app/controllers/studies_controller.rb', line 172
def close
@study = Study.find(params[:id])
authorize! :activate, @study
= params[:comment]
@study..create(description: , user_id: current_user.id)
@study.deactivate!
@study.save
flash[:notice] = "This study has been deactivated: #{}"
redirect_to study_path(@study)
end
|
#collaborators ⇒ Object
153
154
155
156
157
158
|
# File 'app/controllers/studies_controller.rb', line 153
def collaborators
@study = Study.find(params[:id])
@all_roles = Role.distinct.pluck(:name)
@roles = Role.where(authorizable_id: @study.id, authorizable_type: 'Study')
@users = User.order(:first_name)
end
|
#create ⇒ Object
Create the Study from new with the details from its form. Redirect to the index page with a notice.
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/studies_controller.rb', line 80
def create ActiveRecord::Base.transaction do
@study = Study.new(params['study'].merge(user: current_user))
@study.save!
current_user.grant_manager(@study)
User.find(params[:study_owner_id]).grant_owner(@study) if params[:study_owner_id].present?
end
flash[:notice] = 'Your study has been created'
respond_to do |format|
format.html { redirect_to study_path(@study) }
format.xml { render xml: @study, status: :created, location: @study }
format.json { render json: @study, status: :created, location: @study }
end
rescue ActiveRecord::RecordInvalid => e
flash.now[:error] = 'Problems creating your new study'
respond_to do |format|
format.html { render action: 'new' }
format.xml { render xml: @study.errors, status: :unprocessable_entity }
format.json { render json: @study.errors, status: :unprocessable_entity }
end
end
|
#dac_accession ⇒ Object
253
254
255
256
257
258
259
260
261
|
# File 'app/controllers/studies_controller.rb', line 253
def dac_accession
rescue_accession_errors do
@study = Study.find(params[:id])
@study.accession_service.submit_dac_for_user(@study, current_user)
flash[:notice] = "Accession number generated: #{@study.dac_accession_number}"
redirect_to(study_path(@study))
end
end
|
#edit ⇒ Object
72
73
74
75
76
|
# File 'app/controllers/studies_controller.rb', line 72
def edit
@study = Study.find(params[:id])
flash.now[:warning] = @study.warnings if @study.warnings.present?
@users = User.all
end
|
#follow ⇒ Object
rubocop:todo Metrics/AbcSize
160
161
162
163
164
165
166
167
168
169
170
|
# File 'app/controllers/studies_controller.rb', line 160
def follow @study = Study.find(params[:id])
if current_user.follower_of?(@study)
current_user.remove_role 'follower', @study
flash[:notice] = "You have stopped following the '#{@study.name}' study."
else
current_user.grant_follower(@study)
flash[:notice] = "You are now following the '#{@study.name}' study."
end
redirect_to study_information_path(@study)
end
|
#index ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'app/controllers/studies_controller.rb', line 41
def index
setup_studies_from_scope(@exclude_nested_resource)
respond_to do |format|
format.html
format.xml { render(action: (@exclude_nested_resource ? 'index' : 'index_deprecated_xml')) }
format.json { render json: Study.all.to_json }
end
end
|
#new ⇒ Object
67
68
69
70
|
# File 'app/controllers/studies_controller.rb', line 67
def new
@study = Study.new
respond_to { |format| format.html }
end
|
#open ⇒ Object
183
184
185
186
187
188
189
190
|
# File 'app/controllers/studies_controller.rb', line 183
def open
@study = Study.find(params[:id])
authorize! :activate, @study
@study.activate!
@study.save
flash[:notice] = 'This study has been activated'
redirect_to study_path(@study)
end
|
#policy_accession ⇒ Object
263
264
265
266
267
268
269
270
271
|
# File 'app/controllers/studies_controller.rb', line 263
def policy_accession
rescue_accession_errors do
@study = Study.find(params[:id])
@study.accession_service.submit_policy_for_user(@study, current_user)
flash[:notice] = "Accession number generated: #{@study.policy_accession_number}"
redirect_to(study_path(@study))
end
end
|
#projects ⇒ Object
306
307
308
309
|
# File 'app/controllers/studies_controller.rb', line 306
def projects
@study = Study.find(params[:id])
@projects = @study.projects.page(params[:page])
end
|
#properties ⇒ Object
143
144
145
146
147
148
149
150
151
|
# File 'app/controllers/studies_controller.rb', line 143
def properties
@study = Study.find(params[:id])
respond_to do |format|
format.html
format.xml
format.json { render json: @study.to_json }
end
end
|
#rescue_accession_errors ⇒ Object
rubocop:todo Metrics/MethodLength
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'app/controllers/studies_controller.rb', line 217
def rescue_accession_errors yield
rescue ActiveRecord::RecordInvalid => e
flash.now[:error] = 'Please fill in the required fields'
render(action: :edit)
rescue AccessionService::NumberNotRequired => e
flash[:warning] = e.message || 'An accession number is not required for this study'
redirect_to(study_path(@study))
rescue AccessionService::NumberNotGenerated => e
flash[:warning] = 'No accession number was generated'
redirect_to(study_path(@study))
rescue AccessionService::AccessionServiceError => e
flash[:error] = e.message
redirect_to(edit_study_path(@study))
end
|
#sample_manifests ⇒ Object
311
312
313
314
|
# File 'app/controllers/studies_controller.rb', line 311
def sample_manifests
@study = Study.find(params[:id])
@sample_manifests = @study.sample_manifests.page(params[:page]).order(id: :desc)
end
|
#setup_studies_from_scope(exclude_nested_resource = false) ⇒ Object
rubocop:todo Metrics/AbcSize
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/studies_controller.rb', line 17
def setup_studies_from_scope(exclude_nested_resource = false) if logged_in? && (not exclude_nested_resource)
@alternatives = [
'interesting',
'followed',
'managed & active',
'managed & inactive',
'pending',
'pending ethical approval',
'contaminated with human dna',
'remove x and autosomes',
'active',
'inactive',
'collaborations',
'all'
]
@studies = studies_from_scope(@alternatives[params[:scope].to_i])
elsif params[:project_id] && !(project = Project.find(params[:project_id])).nil?
@studies = project.studies.newest_first.includes(:user, :roles)
else
@studies = Study.newest_first.with_user_included.with_related_users_included
end
end
|
#show ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/studies_controller.rb', line 58
def show
@study = Study.find(params[:id])
flash.keep
respond_to do |format|
format.html { redirect_to study_information_path(@study) }
format.xml { render layout: false }
format.json { render json: @study.to_json }
end
end
|
#show_accession ⇒ Object
192
193
194
195
196
197
198
|
# File 'app/controllers/studies_controller.rb', line 192
def show_accession
@study = Study.find(params[:id])
respond_to do |format|
xml_text = @study.accession_service.accession_study_xml(@study)
format.xml { render(xml: xml_text) }
end
end
|
#show_dac_accession ⇒ Object
208
209
210
211
212
213
214
|
# File 'app/controllers/studies_controller.rb', line 208
def show_dac_accession
@study = Study.find(params[:id])
respond_to do |format|
xml_text = @study.accession_service.accession_dac_xml(@study)
format.xml { render(xml: xml_text) }
end
end
|
#show_policy_accession ⇒ Object
200
201
202
203
204
205
206
|
# File 'app/controllers/studies_controller.rb', line 200
def show_policy_accession
@study = Study.find(params[:id])
respond_to do |format|
xml_text = @study.accession_service.accession_policy_xml(@study)
format.xml { render(xml: xml_text) }
end
end
|
#sra ⇒ Object
273
274
275
|
# File 'app/controllers/studies_controller.rb', line 273
def sra
@study = Study.find(params[:id])
end
|
#state ⇒ Object
277
278
279
|
# File 'app/controllers/studies_controller.rb', line 277
def state
@study = Study.find(params[:id])
end
|
#study_list ⇒ Object
51
52
53
54
55
56
|
# File 'app/controllers/studies_controller.rb', line 51
def study_list
return redirect_to(studies_path) unless request.xhr?
setup_studies_from_scope
render partial: 'study_list', locals: { studies: @studies.with_related_owners_included }
end
|
#study_reports ⇒ Object
321
322
323
324
|
# File 'app/controllers/studies_controller.rb', line 321
def study_reports
@study = Study.find(params[:id])
@study_reports = StudyReport.for_study(@study).page(params[:page]).order(id: :desc)
end
|
#study_status ⇒ Object
rubocop:enable Metrics/MethodLength
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/studies_controller.rb', line 130
def study_status
@study = Study.find(params[:id])
authorize! :activate, @study
if @study.inactive? || @study.pending?
@study.activate!
elsif @study.active?
@study.deactivate!
end
flash[:notice] = 'Study status was updated successfully'
redirect_to study_path(@study)
end
|
#suppliers ⇒ Object
316
317
318
319
|
# File 'app/controllers/studies_controller.rb', line 316
def suppliers
@study = Study.find(params[:id])
@suppliers = @study.suppliers.page(params[:page])
end
|
#update ⇒ Object
rubocop:todo Metrics/MethodLength
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'app/controllers/studies_controller.rb', line 104
def update @study = Study.find(params[:id])
ActiveRecord::Base.transaction do
@study.update!(params[:study])
if params[:study_owner_id].present?
owner = User.find(params[:study_owner_id])
unless owner.owner_of?(@study)
@study.owners.first.remove_role('owner', @study) if @study.owners.size == 1
owner.grant_owner(@study)
end
end
flash[:notice] = 'Your study has been updated'
redirect_to study_path(@study)
end
rescue ActiveRecord::RecordInvalid => e
Rails.logger.warn "Failed to update attributes: #{@study.errors.map { |error| error.to_s }}" flash.now[:error] = 'Failed to update attributes for study!'
render action: 'edit', id: @study.id
end
|