diff --git a/app/controllers/results_controller.rb b/app/controllers/results_controller.rb new file mode 100644 index 000000000..4bf37375f --- /dev/null +++ b/app/controllers/results_controller.rb @@ -0,0 +1,45 @@ +class ResultsController < ApplicationController + before_action :load_vars + + def destroy + can_destroy_result_permission + 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, + 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]) + @my_module = @result.my_module + end + + def can_destroy_result_permission + unless can_delete_module_result(@result) + render_403 + end + end +end diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 93941d8fb..09569a506 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -563,6 +563,9 @@ module PermissionHelper ) end + def can_delete_module_result(result) + is_owner_of_project(result.my_module.experiment.project) + end # ---- RESULT TEXT PERMISSIONS ---- def can_create_result_text_in_module(my_module) diff --git a/app/models/activity.rb b/app/models/activity.rb index c0a088530..bc2c91212 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -38,7 +38,8 @@ class Activity < ActiveRecord::Base :edit_step_comment, :delete_step_comment, :edit_result_comment, - :delete_result_comment + :delete_result_comment, + :destroy_result ] validates :type_of, presence: true diff --git a/app/views/my_modules/archive/_result.html.erb b/app/views/my_modules/archive/_result.html.erb index c96415cf4..70d7d9f9f 100644 --- a/app/views/my_modules/archive/_result.html.erb +++ b/app/views/my_modules/archive/_result.html.erb @@ -16,6 +16,17 @@ <%= link_to option_text, result_table_download_path(result.result_table_id), data: {no_turbolink: true} %> <% end %> + <% if can_delete_module_result(result) %> +