2016-02-12 23:52:43 +08:00
|
|
|
module SampleActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include PermissionHelper
|
|
|
|
|
|
|
|
def delete_samples
|
|
|
|
check_destroy_samples_permissions
|
2017-01-06 19:56:14 +08:00
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
if params[:sample_ids].present?
|
|
|
|
counter_user = 0
|
|
|
|
counter_other_users = 0
|
|
|
|
params[:sample_ids].each do |id|
|
|
|
|
sample = Sample.find_by_id(id)
|
|
|
|
|
2017-12-07 23:40:27 +08:00
|
|
|
if sample && can_update_or_delete_sample?(sample)
|
2016-02-12 23:52:43 +08:00
|
|
|
sample.destroy
|
|
|
|
counter_user += 1
|
2017-01-06 19:56:14 +08:00
|
|
|
else
|
2016-02-12 23:52:43 +08:00
|
|
|
counter_other_users += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if counter_user > 0
|
|
|
|
if counter_other_users > 0
|
2017-01-06 19:56:14 +08:00
|
|
|
flash[:success] = t('samples.destroy.contains_other_samples_flash',
|
2017-01-06 21:13:30 +08:00
|
|
|
sample_number: counter_user,
|
|
|
|
other_samples_number: counter_other_users)
|
2016-02-12 23:52:43 +08:00
|
|
|
else
|
2017-01-06 19:56:14 +08:00
|
|
|
flash[:success] = t('samples.destroy.success_flash',
|
2017-01-06 21:13:30 +08:00
|
|
|
sample_number: counter_user)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2017-01-06 19:56:14 +08:00
|
|
|
else
|
|
|
|
flash[:notice] = t('samples.destroy.no_deleted_samples_flash',
|
2017-01-06 21:13:30 +08:00
|
|
|
other_samples_number: counter_other_users)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
else
|
2017-01-06 19:56:14 +08:00
|
|
|
flash[:notice] = t('samples.destroy.no_sample_selected_flash')
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-01-06 21:13:30 +08:00
|
|
|
if params[:controller] == 'my_modules'
|
2016-02-12 23:52:43 +08:00
|
|
|
redirect_to samples_my_module_path(@my_module)
|
2017-01-06 21:13:30 +08:00
|
|
|
elsif params[:controller] == 'projects'
|
2016-02-12 23:52:43 +08:00
|
|
|
redirect_to samples_project_path(@project)
|
2017-01-06 21:13:30 +08:00
|
|
|
elsif params[:controller] == 'experiments'
|
2017-01-06 19:56:14 +08:00
|
|
|
redirect_to samples_experiment_path(@experiment)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_destroy_samples_permissions
|
2017-12-07 23:40:27 +08:00
|
|
|
unless can_delete_samples?(@project.team)
|
2016-02-12 23:52:43 +08:00
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|