scinote-web/app/controllers/concerns/sample_actions.rb

53 lines
1.5 KiB
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
module SampleActions
extend ActiveSupport::Concern
include PermissionHelper
def delete_samples
check_destroy_samples_permissions
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)
if sample and can_delete_sample(sample)
sample.destroy
counter_user += 1
else
2016-02-12 23:52:43 +08:00
counter_other_users += 1
end
end
if counter_user > 0
if counter_other_users > 0
flash[:success] = t('samples.destroy.contains_other_samples_flash',
sample_number: counter_user,
other_samples_number: counter_other_users)
2016-02-12 23:52:43 +08:00
else
flash[:success] = t('samples.destroy.success_flash',
sample_number: counter_user)
2016-02-12 23:52:43 +08:00
end
else
flash[:notice] = t('samples.destroy.no_deleted_samples_flash',
other_samples_number: counter_other_users)
2016-02-12 23:52:43 +08:00
end
else
flash[:notice] = t('samples.destroy.no_sample_selected_flash')
2016-02-12 23:52:43 +08:00
end
if params[:controller] == 'my_modules'
2016-02-12 23:52:43 +08:00
redirect_to samples_my_module_path(@my_module)
elsif params[:controller] == 'projects'
2016-02-12 23:52:43 +08:00
redirect_to samples_project_path(@project)
elsif params[:controller] == 'experiments'
redirect_to samples_experiment_path(@experiment)
2016-02-12 23:52:43 +08:00
end
end
def check_destroy_samples_permissions
unless can_delete_samples(@project.team)
2016-02-12 23:52:43 +08:00
render_403
end
end
end