Add activities to inventories [SCI-5578] (#6588)

* Add activities for stock consumption and inventories export and inventory item file edit [SCI-5578]

* Improve check for creating inventory item asset activity [5578]

* Improve query for inventory items in consumption export [SCI-5578]
This commit is contained in:
wandji 2023-11-20 13:37:57 +01:00 committed by GitHub
parent d2662e9274
commit 7a916b7d11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 13 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -316,6 +316,10 @@ en:
result_text_moved_html: "%{user} moved text <strong>%{text_name}</strong> from result %{result_original} to result %{result_destination}."
result_table_moved_html: "%{user} moved table <strong>%{table_name}</strong> from result %{result_original} to result %{result_destination}."
move_chemical_structure_on_result_html: "%{user} moved chemical structure <strong>%{file}</strong> 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"