diff --git a/app/controllers/concerns/assets_actions.rb b/app/controllers/concerns/assets_actions.rb index 9971d2433..0d20e61e6 100644 --- a/app/controllers/concerns/assets_actions.rb +++ b/app/controllers/concerns/assets_actions.rb @@ -48,6 +48,19 @@ module AssetsActions asset_name: { id: asset.id, value_for: 'file_name' }, action: action }) + elsif asset.repository_cell.present? + repository = asset.repository_cell.repository_row.repository + Activities::CreateActivityService + .call(activity_type: :edit_image_on_inventory_item, + owner: current_user, + subject: repository, + team: repository.team, + message_items: { + repository: repository.id, + repository_row: asset.repository_cell.repository_row.id, + asset_name: { id: asset.id, value_for: 'file_name' }, + action: action + }) end end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f889cb214..eb29de025 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -357,6 +357,7 @@ class RepositoriesController < ApplicationController if repositories.present? && current_user.has_available_exports? current_user.increase_daily_exports_counter! RepositoriesExportJob.perform_later(repositories.pluck(:id), user_id: current_user.id, team_id: current_team.id) + log_activity(:export_inventories, inventories: repositories.pluck(:name).join(', ')) render json: { message: t('zip_export.export_request_success') } else render json: { message: t('zip_export.export_error') }, status: :unprocessable_entity @@ -364,14 +365,18 @@ class RepositoriesController < ApplicationController end def export_repository_stock_items - row_ids = @repository.repository_rows.where(id: params[:row_ids]).pluck(:id) - if row_ids.any? + repository_rows = @repository.repository_rows.where(id: params[:row_ids]).pluck(:id, :name) + if repository_rows.any? RepositoryStockZipExportJob.perform_later( user_id: current_user.id, params: { - repository_row_ids: row_ids + repository_row_ids: repository_rows.map { |row| row[0] } } ) + log_activity( + :export_inventory_stock_consumption, + inventory_items: repository_rows.map { |row| row[1] }.join(', ') + ) render json: { message: t('zip_export.export_request_success') } else render json: { message: t('zip_export.export_error') }, status: :unprocessable_entity @@ -532,14 +537,23 @@ class RepositoriesController < ApplicationController end def log_activity(type_of, message_items = {}) - message_items = { repository: @repository.id }.merge(message_items) + if @repository.present? + message_items = { repository: @repository.id }.merge(message_items) - Activities::CreateActivityService - .call(activity_type: type_of, - owner: current_user, - subject: @repository, - team: @repository.team, - message_items: message_items) + Activities::CreateActivityService + .call(activity_type: type_of, + owner: current_user, + subject: @repository, + team: @repository.team, + message_items: message_items) + else + Activities::CreateActivityService + .call(activity_type: type_of, + owner: current_user, + subject: @current_team, + team: @current_team, + message_items: message_items) + end end def set_breadcrumbs_items diff --git a/app/utilities/wopi_util.rb b/app/utilities/wopi_util.rb index e649836ee..74da50292 100644 --- a/app/utilities/wopi_util.rb +++ b/app/utilities/wopi_util.rb @@ -149,6 +149,19 @@ module WopiUtil asset_name: { id: @asset.id, value_for: 'file_name' }, action: action }) + elsif @assoc.is_a?(RepositoryCell) + repository = @assoc.repository_row.repository + Activities::CreateActivityService + .call(activity_type: :edit_wopi_file_on_inventory_item, + owner: current_user, + subject: repository, + team: repository.team, + message_items: { + repository: repository.id, + repository_row: @assoc.repository_row.id, + asset_name: { id: @asset.id, value_for: 'file_name' }, + action: action + }) end end end diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 01e126e19..295756ec5 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -485,7 +485,11 @@ class Extends sequence_on_result_edited: 288, sequence_on_result_deleted: 289, sequence_on_result_moved: 290, - move_chemical_structure_on_result: 291 + move_chemical_structure_on_result: 291, + export_inventories: 292, + edit_image_on_inventory_item: 293, + edit_wopi_file_on_inventory_item: 294, + export_inventory_stock_consumption: 295 } ACTIVITY_GROUPS = { @@ -499,7 +503,7 @@ class Extends experiment: [*27..31, 57, 141, 165], 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, 180, 181, 182], + 78, 96, 107, 113, 114, *133..136, 180, 181, 182, *292..295], 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, 179, 187, 186, 190, 191, *204..215, 220, 221, 223, 227, 228, 229, *230..235, diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index 45b3756fe..c2956313f 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -316,6 +316,10 @@ en: result_text_moved_html: "%{user} moved text %{text_name} from result %{result_original} to result %{result_destination}." result_table_moved_html: "%{user} moved table %{table_name} from result %{result_original} to result %{result_destination}." move_chemical_structure_on_result_html: "%{user} moved chemical structure %{file} from result %{result_original} to result %{result_destination}." + export_inventories_html: "%{user} exported inventory %{inventories}" + edit_image_on_inventory_item_html: "%{user} edited image %{asset_name} on inventory item %{repository_row} in inventory %{repository}: %{action}." + edit_wopi_file_on_inventory_item_html: "%{user} edited Office online file %{asset_name} on inventory item %{repository_row} in inventory %{repository}: %{action}." + export_inventory_stock_consumption_html: "%{user} exported stock consumption for inventory item(s) %{inventory_items} in inventory %{repository}." activity_name: create_project: "Project created" rename_project: "Project renamed" @@ -586,7 +590,10 @@ en: result_text_moved: "Result text moved" result_table_moved: "Result table moved" move_chemical_structure_on_result: "Chemical structure on result moved" - + export_inventories: "Inventories exported" + edit_image_on_inventory_item: "Inventory item image edited" + edit_wopi_file_on_inventory_item: "Inventory item wopi file edited" + export_inventory_stock_consumption: "Inventory stock consumptions exported" activity_group: projects: "Projects" task_results: "Task results"