mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 18:21:50 +08:00
enabled to delete results in task archive [fixes SCI-370]
This commit is contained in:
parent
ed72996523
commit
691ae94d2c
6 changed files with 68 additions and 2 deletions
45
app/controllers/results_controller.rb
Normal file
45
app/controllers/results_controller.rb
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,6 +16,17 @@
|
|||
<%= link_to option_text, result_table_download_path(result.result_table_id), data: {no_turbolink: true} %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% if can_delete_module_result(result) %>
|
||||
<li>
|
||||
<%= link_to t('my_modules.module_archive.option_delete'),
|
||||
result_path(action: :delete, id: result.id),
|
||||
data: {
|
||||
no_turbolink: true ,
|
||||
confirm: t('my_modules.module_archive.confirm_delete')
|
||||
},
|
||||
method: :delete %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -464,6 +464,12 @@ en:
|
|||
head_title: "%{project} | %{module} | Sample library"
|
||||
module_archive:
|
||||
head_title: "%{project} | %{module} | Archive"
|
||||
option_delete: "Delete"
|
||||
confirm_delete: "Are you sure you want to permanently delete result?"
|
||||
delete_flash: "Sucessfully removed result <strong>%{result}</strong> from task <strong>%{module}</strong>."
|
||||
table_log: "%{user} deleted table result <strong>%{result}</strong> on %{date}"
|
||||
text_log: "%{user} deleted text result <strong>%{result}</strong> on %{date}"
|
||||
asset_log: "%{user} deleted file result <strong>%{result}</strong> on %{date}"
|
||||
archived_on: "Archived on"
|
||||
archived_on_title: "Result archived on %{date} at %{time}."
|
||||
option_download: "Download"
|
||||
|
|
|
@ -188,7 +188,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :results, only: [:update] do
|
||||
resources :results, only: [:update, :destroy] do
|
||||
resources :result_comments,
|
||||
path: '/comments',
|
||||
only: [:new, :create, :index, :edit, :update, :destroy]
|
||||
|
|
Loading…
Reference in a new issue