mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-29 03:01:58 +08:00
Merge pull request #3500 from artoscinote/ma_SCI_6014
Added edit activities on asset deletion [SCI-6014]
This commit is contained in:
commit
afc74b6b8f
1 changed files with 43 additions and 0 deletions
|
@ -212,6 +212,22 @@ class AssetsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if @asset.destroy
|
||||
case @assoc
|
||||
when Step
|
||||
if @assoc.protocol.in_module?
|
||||
log_step_activity(:edit_step, @assoc, @assoc.my_module.experiment.project, my_module: @assoc.my_module.id)
|
||||
else
|
||||
log_step_activity(
|
||||
:edit_step_in_protocol_repository,
|
||||
@assoc,
|
||||
nil,
|
||||
protocol: @assoc.protocol.id
|
||||
)
|
||||
end
|
||||
when Result
|
||||
log_result_activity(:edit_result, @assoc)
|
||||
end
|
||||
|
||||
render json: { flash: I18n.t('assets.file_deleted', file_name: @asset.file_name) }
|
||||
else
|
||||
render json: {}, status: :unprocessable_entity
|
||||
|
@ -265,4 +281,31 @@ class AssetsController < ApplicationController
|
|||
|
||||
'file'
|
||||
end
|
||||
|
||||
def log_step_activity(type_of, step, project = nil, message_items = {})
|
||||
default_items = { step: step.id,
|
||||
step_position: { id: step.id, value_for: 'position_plus_one' } }
|
||||
message_items = default_items.merge(message_items)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
subject: step.protocol,
|
||||
team: current_team,
|
||||
project: project,
|
||||
message_items: message_items)
|
||||
end
|
||||
|
||||
def log_result_activity(type_of, result)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
subject: result,
|
||||
team: result.my_module.experiment.project.team,
|
||||
project: result.my_module.experiment.project,
|
||||
message_items: {
|
||||
result: result.id,
|
||||
type_of_result: t('activities.result_type.text')
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue