diff --git a/app/controllers/bio_eddie_assets_controller.rb b/app/controllers/bio_eddie_assets_controller.rb index a9d5e0ce7..a7964b0af 100644 --- a/app/controllers/bio_eddie_assets_controller.rb +++ b/app/controllers/bio_eddie_assets_controller.rb @@ -16,7 +16,7 @@ class BioEddieAssetsController < ApplicationController create_create_bio_eddie_activity(asset, current_user) if asset && bio_eddie_params[:object_type] == 'Step' - log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true' + create_register_bio_eddie_activity(asset, current_user) if bio_eddie_params[:schedule_for_registration] == 'true' render json: { html: render_to_string(partial: 'assets/asset.html.erb', locals: { asset: asset, @@ -24,7 +24,7 @@ class BioEddieAssetsController < ApplicationController }) } elsif asset && bio_eddie_params[:object_type] == 'Result' - log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true' + create_register_bio_eddie_activity(asset, current_user) if bio_eddie_params[:schedule_for_registration] == 'true' render json: { status: 'created' }, status: :ok else render json: asset.errors, status: :unprocessable_entity @@ -37,7 +37,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' + create_register_bio_eddie_activity(asset, current_user) 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'] } @@ -46,6 +46,21 @@ class BioEddieAssetsController < ApplicationController end end + def destroy + asset = current_team.assets.find(bio_eddie_params[:id]) + + if asset + create_delete_bio_eddie_activity(asset, current_user) + if asset.destroy + render json: { flash: I18n.t('assets.file_deleted', file_name: asset.file_name) } + else + render json: {}, status: :unprocessable_entity + end + else + render json: { error: t('bio_eddie.no_molecules_found') }, status: :unprocessable_entity + end + end + def license license_file_path = Rails.root.join('data/bioeddie/license.cxl') if File.file?(license_file_path) @@ -130,19 +145,4 @@ 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/controllers/concerns/bio_eddie_actions.rb b/app/controllers/concerns/bio_eddie_actions.rb index 2743f0ef2..74cd793a8 100644 --- a/app/controllers/concerns/bio_eddie_actions.rb +++ b/app/controllers/concerns/bio_eddie_actions.rb @@ -29,6 +29,12 @@ module BioEddieActions bio_eddie_find_target_object(asset, current_user, 'delete') end + def create_register_bio_eddie_activity(asset, current_user) + return unless bio_eddie_asset_validation(asset) + + bio_eddie_find_target_object(asset, current_user, 'register') + end + def bio_eddie_asset_validation(asset) asset && asset.file.metadata[:asset_type] == 'bio_eddie' end @@ -55,10 +61,13 @@ module BioEddieActions return unless step && protocol - default_step_items = - { step: step.id, - step_position: { id: step.id, value_for: 'position_plus_one' }, - asset_type => { id: asset.id, value_for: 'file_name' } } + default_step_items = { + step: step.id, + step_position: { id: step.id, value_for: 'position_plus_one' }, + asset_type => { id: asset.id, value_for: 'file_name' }, + description: asset.blob.metadata['description'], + name: asset.blob.metadata['name'] + } default_step_items[:action] = action if action if protocol.in_module? @@ -72,6 +81,7 @@ module BioEddieActions message_items = { protocol: protocol.id } end message_items = default_step_items.merge(message_items) + Activities::CreateActivityService .call(activity_type: type_of, owner: current_user, @@ -90,7 +100,9 @@ module BioEddieActions message_items = { result: result.id, - asset_type => { id: asset.id, value_for: 'file_name' } + asset_type => { id: asset.id, value_for: 'file_name' }, + description: asset.blob.metadata['description'], + name: asset.blob.metadata['name'] } message_items[:action] = action if action diff --git a/app/services/activities/activity_filter_matching_service.rb b/app/services/activities/activity_filter_matching_service.rb index ca181eeaf..a30413046 100644 --- a/app/services/activities/activity_filter_matching_service.rb +++ b/app/services/activities/activity_filter_matching_service.rb @@ -65,7 +65,7 @@ module Activities end def activity_subject_parents - subject_parents(@activity.subject, []) + subject_parents(@activity.subject, []).compact end def subject_parents(subject, parents) diff --git a/app/views/assets/_asset_context_menu.html.erb b/app/views/assets/_asset_context_menu.html.erb index 6eaaedb27..44f9eb060 100644 --- a/app/views/assets/_asset_context_menu.html.erb +++ b/app/views/assets/_asset_context_menu.html.erb @@ -61,7 +61,7 @@ <% if deletable %>