2016-09-06 22:16:39 +08:00
|
|
|
class ResultsController < ApplicationController
|
|
|
|
before_action :load_vars
|
2018-02-16 01:46:29 +08:00
|
|
|
before_action :check_destroy_permissions
|
2016-09-06 22:16:39 +08:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
act_log = t('my_modules.module_archive.table_log',
|
|
|
|
user: current_user.name,
|
|
|
|
result: @result.name,
|
|
|
|
date: l(Time.current, format: :full_date))
|
|
|
|
act_log = t('my_modules.module_archive.text_log',
|
|
|
|
user: current_user.name,
|
|
|
|
result: @result.name,
|
|
|
|
date: l(Time.current, format: :full_date)) if @result.is_text
|
|
|
|
act_log = t('my_modules.module_archive.asset_log',
|
|
|
|
user: current_user.name,
|
|
|
|
result: @result.name,
|
|
|
|
date: l(Time.current, format: :full_date)) if @result.is_asset
|
|
|
|
|
|
|
|
Activity.create(
|
|
|
|
type_of: :destroy_result,
|
|
|
|
user: current_user,
|
|
|
|
project: @my_module.experiment.project,
|
2017-04-20 16:56:25 +08:00
|
|
|
experiment: @my_module.experiment,
|
2016-09-06 22:16:39 +08:00
|
|
|
my_module: @my_module,
|
|
|
|
message: act_log
|
|
|
|
)
|
|
|
|
flash[:success] = t('my_modules.module_archive.delete_flash',
|
|
|
|
result: @result.name,
|
|
|
|
module: @my_module.name)
|
|
|
|
@result.destroy
|
|
|
|
redirect_to archive_my_module_path(@my_module)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_vars
|
|
|
|
@result = Result.find_by_id(params[:id])
|
2016-09-13 19:57:31 +08:00
|
|
|
return render_403 unless @result
|
2016-09-06 22:16:39 +08:00
|
|
|
@my_module = @result.my_module
|
|
|
|
end
|
|
|
|
|
2018-02-16 01:46:29 +08:00
|
|
|
def check_destroy_permissions
|
2018-02-19 21:47:36 +08:00
|
|
|
render_403 unless can_manage_result?(@result)
|
2016-09-06 22:16:39 +08:00
|
|
|
end
|
|
|
|
end
|