Moved activity logging to controller [SCI-5879]

This commit is contained in:
Martin Artnik 2021-07-22 09:50:58 +02:00
parent 888131a465
commit 04b94d504d
2 changed files with 18 additions and 18 deletions

View file

@ -23,6 +23,7 @@ class BioEddieAssetsController < ApplicationController
})
}
elsif asset && bio_eddie_params[:object_type] == 'Result'
log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true'
render json: { status: 'created' }, status: :ok
else
render json: asset.errors, status: :unprocessable_entity
@ -35,6 +36,7 @@ class BioEddieAssetsController < ApplicationController
create_edit_bio_eddie_activity(asset, current_user, :finish_editing)
if asset
log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true'
render json: { url: rails_representation_url(asset.medium_preview),
id: asset.id,
file_name: asset.blob.metadata['name'] }
@ -101,4 +103,19 @@ class BioEddieAssetsController < ApplicationController
def bio_eddie_params
params.permit(:id, :description, :object_id, :object_type, :name, :image, :schedule_for_registration)
end
def log_registration_activity(asset)
Activities::CreateActivityService
.call(
activity_type: :register_molecule,
owner: current_user,
team: asset.team,
project: asset.my_module.experiment.project,
subject: asset,
message_items: {
description: asset.blob.metadata['description'],
name: asset.blob.metadata['name']
}
)
end
end

View file

@ -58,7 +58,7 @@ class BioEddieService
StringIO.new(params[:image])
end
def attach_file(attachment, file, params, current_user)
def attach_file(attachment, file, params)
attachment.attach(
io: file,
filename: "#{prepare_name(params[:name])}.svg",
@ -70,27 +70,10 @@ class BioEddieService
asset_type: 'bio_eddie'
}
)
log_activity(attachment.record, current_user) if params[:schedule_for_registration] == 'true'
end
def prepare_name(sketch_name)
sketch_name.presence || I18n.t('bio_eddie.new_molecule')
end
def log_activity(asset, current_user)
Activities::CreateActivityService
.call(
activity_type: :register_molecule,
owner: current_user,
team: asset.team,
project: asset.my_module.experiment.project,
subject: asset,
message_items: {
description: asset.blob.metadata['description'],
name: asset.blob.metadata['name']
}
)
end
end
end