Merge pull request #3500 from artoscinote/ma_SCI_6014

Added edit activities on asset deletion [SCI-6014]
This commit is contained in:
artoscinote 2021-08-30 10:00:58 +02:00 committed by GitHub
commit afc74b6b8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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