From d0877de13c291cfc2af57292431b00dc978b92fe Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Thu, 23 Nov 2023 04:12:38 +0400 Subject: [PATCH 1/3] Add activity for updating a file via AssetSync [SCI-9710] --- app/controllers/asset_sync_controller.rb | 69 ++++++++++++++++++++++++ config/initializers/extends.rb | 11 ++-- config/locales/global_activities/en.yml | 6 +++ 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index d957ee094..72d3e5f8f 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -35,6 +35,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 @@ -42,6 +44,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 @@ -74,4 +117,30 @@ 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 end diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 73cd9b033..1a6f08e06 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -492,16 +492,19 @@ 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, + edit_task_step_file_locally: 292, + edit_protocol_template_file_locally: 293, + edit_task_result_file_locally: 294 } 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, *257..273, *284..291], + task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 178, *257..273, *284..291, 294], 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, 166, 246, 247, 248], task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137, - 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226, 236, *249..252, *274..278], + 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226, 236, *249..252, *274..278, 292], 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, 221, 223, 227, 228, 229, *230..235, - *237..240, *253..256, *279..283], + *237..240, *253..256, *279..283, 293], team: [92, 94, 93, 97, 104, 244, 245], label_templates: [*216..219] } diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index 45b3756fe..bb3ae606a 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -316,6 +316,9 @@ 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}." + 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}" activity_name: create_project: "Project created" rename_project: "Project renamed" @@ -586,6 +589,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" activity_group: projects: "Projects" From b1554624967e9d64f2e7f8ca9ae0668b59f63500 Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Wed, 6 Dec 2023 11:54:46 +0400 Subject: [PATCH 2/3] updated numbering to fit develop branch --- config/initializers/extends.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 3261a98da..fd858ab75 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -493,18 +493,18 @@ class Extends sequence_on_result_deleted: 289, sequence_on_result_moved: 290, move_chemical_structure_on_result: 291, - edit_task_step_file_locally: 292, - edit_protocol_template_file_locally: 293, - edit_task_result_file_locally: 294 + edit_task_step_file_locally: 293, + edit_protocol_template_file_locally: 294, + edit_task_result_file_locally: 295 } 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, *257..273, *284..291, 294], + task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 178, *257..273, *284..291, 295], 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, 166, 246, 247, 248], task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137, - 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226, 236, *249..252, *274..278, 292], + 217, 168, 171, 177, 184, 185, 188, 189, *192..203, 222, 224, 225, 226, 236, *249..252, *274..278, 293], task_inventory: [55, 56, 146, 147, 183], experiment: [*27..31, 57, 141, 165], reports: [48, 50, 49, 163, 164], @@ -513,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, 221, 223, 227, 228, 229, *230..235, - *237..240, *253..256, *279..283, 293], + *237..240, *253..256, *279..283, 294], team: [92, 94, 93, 97, 104, 244, 245], label_templates: [*216..219] } From 544611c3fa3ce106ff986f8315496b1592629406 Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Wed, 3 Jan 2024 18:19:32 +0400 Subject: [PATCH 3/3] hound fix --- app/controllers/asset_sync_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index 226e56a3c..59a26a8f9 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -86,7 +86,6 @@ class AssetSyncController < ApplicationController end end - private def conflicting_asset_copy_token @@ -145,7 +144,7 @@ class AssetSyncController < ApplicationController result: result.id }.merge(message_items)) end - + def check_asset_sync render_404 if ENV['ASSET_SYNC_URL'].blank? end