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 %>
  • - + <%= t("assets.context_menu.delete") %> diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 8b3e7a27f..ace2c445a 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -319,21 +319,24 @@ class Extends delete_molecule_on_step: 174, delete_molecule_on_result: 175, delete_molecule_on_step_in_repository: 176, - register_molecule: 165 + register_molecule_on_step: 177, + register_molecule_on_result: 178, + register_molecule_on_step_in_repository: 179 } ACTIVITY_GROUPS = { projects: [*0..7, 32, 33, 34, 95, 108, 65, 109, *158..162], - task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 175], + task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 175, 178], task: [8, 58, 9, 59, *10..14, 35, 36, 37, 53, 54, *60..63, 138, 139, 140, 64, 66, 106, 126, 120, 132, - *146..148, 168, 171, 174], - task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137], + *146..148, 168], + task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137, + 171, 174, 177], task_inventory: [55, 56, 146, 147], experiment: [*27..31, 57], reports: [48, 50, 49, 163, 164], inventories: [70, 71, 105, 144, 145, 72, 73, 74, 102, 142, 143, 75, 76, 77, 78, 96, 107, 113, 114, *133..136], protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82, - 83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 176], + 83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 176, 179], team: [92, 94, 93, 97, 104] } diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index fed845988..d481c1294 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -200,9 +200,9 @@ en: delete_molecule_on_step_html: "%{user} deleted molecule %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}." delete_molecule_on_result_html: "%{user} deleted molecule %{asset_name} on result %{result}." delete_molecule_on_step_in_repository_html: "%{user} deleted molecule %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}." - - - register_molecule_html: "%{user} scheduled the %{name} molecule for registration." + register_molecule_on_step_html: "%{user} registered molecule %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}." + register_molecule_on_result_html: "%{user} registered molecule %{asset_name} on result %{result}." + register_molecule_on_step_in_repository_html: "%{user} registered molecule %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}." activity_name: create_project: "Project created" @@ -360,6 +360,9 @@ en: delete_molecule_on_step: "Molecule on task step deleted" delete_molecule_on_result: "Molecule on result deleted" delete_molecule_on_step_in_repository: "Molecule on step deleted" + register_molecule_on_step: "Molecule on task step registered" + register_molecule_on_result: "Molecule on result registered" + register_molecule_on_step_in_repository: "Molecule on step registered" activity_group: diff --git a/config/routes.rb b/config/routes.rb index ce9178869..e3d235fa4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -770,7 +770,7 @@ Rails.application.routes.draw do end end - resources :bio_eddie_assets, only: %i(create update) do + resources :bio_eddie_assets, only: %i(create update destroy) do collection do get :license end