mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
Merge pull request #6692 from G-Chubinidze/gc_SCI_9710
Add activity for updating a file via AssetSync [SCI-9710]
This commit is contained in:
commit
29705b9a49
3 changed files with 82 additions and 4 deletions
|
@ -36,6 +36,8 @@ class AssetSyncController < ApplicationController
|
|||
@asset.file.attach(io: request.body, filename: @asset.file.filename)
|
||||
@asset.touch
|
||||
|
||||
log_activity
|
||||
|
||||
render json: AssetSyncTokenSerializer.new(@asset_sync_token).as_json
|
||||
end
|
||||
|
||||
|
@ -43,6 +45,47 @@ class AssetSyncController < ApplicationController
|
|||
render plain: Constants::ASSET_SYNC_URL
|
||||
end
|
||||
|
||||
def log_activity
|
||||
assoc ||= @asset.step
|
||||
assoc ||= @asset.result
|
||||
|
||||
case assoc
|
||||
when Step
|
||||
if assoc.protocol.in_module?
|
||||
log_step_activity(
|
||||
:edit_task_step_file_locally,
|
||||
assoc,
|
||||
assoc.my_module.project,
|
||||
my_module: assoc.my_module.id,
|
||||
file: @asset.file_name,
|
||||
user: current_user.id,
|
||||
step_position_original: @asset.step.position + 1,
|
||||
step: assoc.id
|
||||
)
|
||||
else
|
||||
log_step_activity(
|
||||
:edit_protocol_template_file_locally,
|
||||
assoc,
|
||||
nil,
|
||||
{
|
||||
file: @asset.file_name,
|
||||
user: current_user.id,
|
||||
step_position_original: @asset.step.position + 1,
|
||||
step: assoc.id
|
||||
}
|
||||
)
|
||||
end
|
||||
when Result
|
||||
log_result_activity(
|
||||
:edit_task_result_file_locally,
|
||||
assoc,
|
||||
file: @asset.file_name,
|
||||
user: current_user.id,
|
||||
result: Result.first.id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def conflicting_asset_copy_token
|
||||
|
@ -76,6 +119,32 @@ class AssetSyncController < ApplicationController
|
|||
head :forbidden unless can_manage_asset?(@asset)
|
||||
end
|
||||
|
||||
def log_step_activity(type_of, step, project = nil, message_items = {})
|
||||
default_items = { step: step.id,
|
||||
step_position: { id: step.id, value_for: 'position_plus_one' } }
|
||||
message_items = default_items.merge(message_items)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: User.first,
|
||||
subject: step.protocol,
|
||||
team: step.protocol.team,
|
||||
project: project,
|
||||
message_items: message_items)
|
||||
end
|
||||
|
||||
def log_result_activity(type_of, result, message_items)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
subject: result,
|
||||
team: result.my_module.team,
|
||||
project: result.my_module.project,
|
||||
message_items: {
|
||||
result: result.id
|
||||
}.merge(message_items))
|
||||
end
|
||||
|
||||
def check_asset_sync
|
||||
render_404 if ENV['ASSET_SYNC_URL'].blank?
|
||||
end
|
||||
|
|
|
@ -492,16 +492,19 @@ class Extends
|
|||
export_inventories: 293,
|
||||
edit_image_on_inventory_item: 294,
|
||||
edit_wopi_file_on_inventory_item: 295,
|
||||
export_inventory_stock_consumption: 296
|
||||
export_inventory_stock_consumption: 296,
|
||||
edit_task_step_file_locally: 297,
|
||||
edit_protocol_template_file_locally: 298,
|
||||
edit_task_result_file_locally: 299
|
||||
}
|
||||
|
||||
ACTIVITY_GROUPS = {
|
||||
projects: [*0..7, 32, 33, 34, 95, 108, 65, 109, *158..162, 241, 242, 243],
|
||||
task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 178, *246..248, *257..273, *284..291],
|
||||
task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 178, *246..248, *257..273, *284..291, 299],
|
||||
task: [8, 58, 9, 59, *10..14, 35, 36, 37, 53, 54, *60..63, 138, 139, 140, 64, 66, 106, 126, 120, 132,
|
||||
148, 166],
|
||||
task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137,
|
||||
168, 171, 177, 184, 185, 188, 189, *192..203, 221, 222, 224, 225, 226, 236, *249..252, *274..278],
|
||||
168, 171, 177, 184, 185, 188, 189, *192..203, 221, 222, 224, 225, 226, 236, *249..252, *274..278, 297],
|
||||
task_inventory: [55, 56, 146, 147, 183],
|
||||
experiment: [*27..31, 57, 141, 165],
|
||||
reports: [48, 50, 49, 163, 164],
|
||||
|
@ -510,7 +513,7 @@ class Extends
|
|||
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, 223, 227, 228, 229, *230..235,
|
||||
*237..240, *253..256, *279..283],
|
||||
*237..240, *253..256, *279..283, 298],
|
||||
team: [92, 94, 93, 97, 104, 244, 245],
|
||||
label_templates: [*216..219]
|
||||
}
|
||||
|
|
|
@ -317,6 +317,9 @@ 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}."
|
||||
edit_task_step_file_locally_html: "%{user} locally edited file %{file} on protocol's step %{step_position_original} %{step} on task %{my_module}"
|
||||
edit_protocol_template_file_locally_html: "%{user} locally edited file %{file} on protocol's step %{step_position_original} %{step} with SciNote Edit in Protocol repository"
|
||||
edit_task_result_file_locally_html: "%{user} locally edited file %{file} on result %{result}"
|
||||
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}."
|
||||
|
@ -592,6 +595,9 @@ en:
|
|||
result_text_moved: "Result text moved"
|
||||
result_table_moved: "Result table moved"
|
||||
move_chemical_structure_on_result: "Chemical structure on result moved"
|
||||
edit_task_step_file_locally: "File on task step edited locally"
|
||||
edit_protocol_template_file_locally: "File on protocol templates edited locally"
|
||||
edit_task_result_file_locally: "File on task result edited locally"
|
||||
export_inventories: "Inventories exported"
|
||||
edit_image_on_inventory_item: "Inventory item image edited"
|
||||
edit_wopi_file_on_inventory_item: "Inventory item wopi file edited"
|
||||
|
|
Loading…
Reference in a new issue