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
|
2019-03-14 02:05:29 +08:00
|
|
|
result_type = if @result.is_text
|
|
|
|
t('activities.result_type.text')
|
|
|
|
elsif @result.is_table
|
|
|
|
t('activities.result_type.table')
|
|
|
|
elsif @result.is_asset
|
|
|
|
t('activities.result_type.asset')
|
|
|
|
end
|
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: :destroy_result,
|
|
|
|
owner: current_user,
|
|
|
|
subject: @result,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: @my_module.team,
|
|
|
|
project: @my_module.project,
|
2019-03-14 02:05:29 +08:00
|
|
|
message_items: { result: @result.id,
|
2019-03-26 18:39:54 +08:00
|
|
|
type_of_result: result_type })
|
2016-09-06 22:16:39 +08:00
|
|
|
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
|
2021-01-20 16:00:45 +08:00
|
|
|
render_403 unless can_delete_result?(@result)
|
2016-09-06 22:16:39 +08:00
|
|
|
end
|
|
|
|
end
|