From 04b94d504d0194d7207efd86ccda765d755ddf3f Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Thu, 22 Jul 2021 09:50:58 +0200 Subject: [PATCH] Moved activity logging to controller [SCI-5879] --- .../bio_eddie_assets_controller.rb | 17 +++++++++++++++++ app/services/bio_eddie_service.rb | 19 +------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/bio_eddie_assets_controller.rb b/app/controllers/bio_eddie_assets_controller.rb index b996810a9..13494f03b 100644 --- a/app/controllers/bio_eddie_assets_controller.rb +++ b/app/controllers/bio_eddie_assets_controller.rb @@ -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 diff --git a/app/services/bio_eddie_service.rb b/app/services/bio_eddie_service.rb index b5c21d0f2..6952b52ce 100644 --- a/app/services/bio_eddie_service.rb +++ b/app/services/bio_eddie_service.rb @@ -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