From 3c69225d6b8bbdf6240863ca0361ca7f85335f1a Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Fri, 29 Mar 2019 15:09:20 +0100 Subject: [PATCH] Change activities for task protocols --- app/controllers/protocols_controller.rb | 15 ++- app/controllers/step_comments_controller.rb | 2 +- app/controllers/steps_controller.rb | 17 +-- app/utilities/wopi_util.rb | 20 ++-- .../references/_protocol.html.erb | 32 +++--- config/initializers/extends.rb | 3 +- config/locales/global_activities/en.yml | 103 +++++++++--------- 7 files changed, 101 insertions(+), 91 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 082a9e6d4..3b933fdad 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -159,7 +159,7 @@ class ProtocolsController < ApplicationController changes.each do |key| if %w(description authors keywords).include?(key) - log_activity("edit_#{key}_in_protocol_repository".to_sym) + log_activity("edit_#{key}_in_protocol_repository".to_sym, nil, protocol: @protocol.id) end end @@ -198,7 +198,7 @@ class ProtocolsController < ApplicationController end if @protocol.update_keywords(params[:keywords]) format.json do - log_activity(:edit_keywords_in_protocol_repository) + log_activity(:edit_keywords_in_protocol_repository, nil, protocol: @protocol.id) render json: { updated_at_label: render_to_string( @@ -231,7 +231,7 @@ class ProtocolsController < ApplicationController respond_to do |format| if @protocol.save - log_activity(:create_protocol_in_repository) + log_activity(:create_protocol_in_repository, nil, protocol: @protocol.id) format.json do render json: { @@ -378,6 +378,7 @@ class ProtocolsController < ApplicationController # Everything good, display flash & render 200 log_activity(:update_protocol_in_task_from_repository, @protocol.my_module.experiment.project, + my_module: @protocol.my_module.id, protocol_repository: @protocol.parent.id) flash[:success] = t( 'my_modules.protocols.revert_flash' @@ -420,6 +421,7 @@ class ProtocolsController < ApplicationController # Everything good, record activity, display flash & render 200 log_activity(:update_protocol_in_repository_from_task, @protocol.my_module.experiment.project, + my_module: @protocol.my_module.id, protocol_repository: @protocol.parent.id) flash[:success] = t( 'my_modules.protocols.update_parent_flash' @@ -462,6 +464,7 @@ class ProtocolsController < ApplicationController # Everything good, display flash & render 200 log_activity(:update_protocol_in_task_from_repository, @protocol.my_module.experiment.project, + my_module: @my_module.id, protocol_repository: @protocol.parent.id) flash[:success] = t( 'my_modules.protocols.update_from_parent_flash' @@ -504,6 +507,7 @@ class ProtocolsController < ApplicationController # Everything good, record activity, display flash & render 200 log_activity(:load_protocol_to_task_from_repository, @protocol.my_module.experiment.project, + my_module: @protocol.my_module.id, protocol_repository: @protocol.parent.id) flash[:success] = t('my_modules.protocols.load_from_repository_flash') flash.keep(:success) @@ -542,7 +546,8 @@ class ProtocolsController < ApplicationController else # Everything good, record activity, display flash & render 200 log_activity(:load_protocol_to_task_from_file, - @protocol.my_module.experiment.project) + @protocol.my_module.experiment.project, + my_module: @my_module.id) flash[:success] = t( 'my_modules.protocols.load_from_file_flash' ) @@ -1203,8 +1208,6 @@ class ProtocolsController < ApplicationController end def log_activity(type_of, project = nil, message_items = {}) - message_items = { protocol: @protocol.id }.merge(message_items) - Activities::CreateActivityService .call(activity_type: type_of, owner: current_user, diff --git a/app/controllers/step_comments_controller.rb b/app/controllers/step_comments_controller.rb index 4e410276c..4cf76b4c1 100644 --- a/app/controllers/step_comments_controller.rb +++ b/app/controllers/step_comments_controller.rb @@ -188,7 +188,7 @@ class StepCommentsController < ApplicationController team: current_team, project: @step.my_module.experiment.project, message_items: { - protocol: @protocol.id, + my_module: @step.my_module.id, step: @step.id, step_position: { id: @step.id, value_for: 'position' } }) diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index a87f38453..d863fb562 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -67,9 +67,9 @@ class StepsController < ApplicationController # Generate activity if @protocol.in_module? - log_activity(:create_step, @my_module.experiment.project) + log_activity(:create_step, @my_module.experiment.project, my_module: @my_module.id) else - log_activity(:add_step_to_protocol_repository) + log_activity(:add_step_to_protocol_repository, nil, protocol: @protocol.id) end # Update protocol timestamp @@ -174,9 +174,9 @@ class StepsController < ApplicationController # Generate activity if @protocol.in_module? - log_activity(:edit_step, @my_module.experiment.project) + log_activity(:edit_step, @my_module.experiment.project, my_module: @my_module.id) else - log_activity(:edit_step_in_protocol_repository) + log_activity(:edit_step_in_protocol_repository, nil, protocol: @protocol.id) end # Update protocol timestamp @@ -212,9 +212,9 @@ class StepsController < ApplicationController # Generate activity if @protocol.in_module? - log_activity(:destroy_step, @my_module.experiment.project) + log_activity(:destroy_step, @my_module.experiment.project, my_module: @my_module.id) else - log_activity(:delete_step_in_protocol_repository) + log_activity(:delete_step_in_protocol_repository, nil, protocol: @protocol.id) end # Destroy the step @@ -272,6 +272,7 @@ class StepsController < ApplicationController if @protocol.in_module? log_activity(type_of, @protocol.my_module.experiment.project, + my_module: @my_module.id, step: @chk_item.checklist.step.id, step_position: { id: @chk_item.checklist.step.id, value_for: 'position' }, @@ -315,6 +316,7 @@ class StepsController < ApplicationController if @protocol.in_module? log_activity(type_of, @protocol.my_module.experiment.project, + my_module: @my_module.id, num_completed: completed_steps.to_s, num_all: all_steps.to_s) end @@ -606,8 +608,7 @@ class StepsController < ApplicationController end def log_activity(type_of, project = nil, message_items = {}) - default_items = { protocol: @protocol.id, - step: @step.id, + default_items = { step: @step.id, step_position: { id: @step.id, value_for: 'position' } } message_items = default_items.merge(message_items) diff --git a/app/utilities/wopi_util.rb b/app/utilities/wopi_util.rb index 113dd418b..b9d0d5a98 100644 --- a/app/utilities/wopi_util.rb +++ b/app/utilities/wopi_util.rb @@ -79,22 +79,26 @@ module WopiUtil t('activities.wupi_file_editing.finished') end if @assoc.class == Step + type_of = :edit_wopi_file_on_step_in_repository + default_step_items = + { step: @asset.step.id, + step_position: { id: @asset.step.id, value_for: 'position' }, + asset_name: { id: @asset.id, value_for: 'file_file_name' }, + action: action } + message_items = { protocol: @protocol.id } if @protocol.in_module? project = @protocol.my_module.experiment.project + type_of = :edit_wopi_file_on_step + message_items = { my_module: @protocol.my_module.id } end + message_items = default_step_items.merge(message_items) Activities::CreateActivityService - .call(activity_type: :edit_wopi_file_on_step, + .call(activity_type: type_of, owner: current_user, subject: @protocol, team: current_team, project: project, - message_items: { - protocol: @protocol.id, - step: @asset.step.id, - step_position: { id: @asset.step.id, value_for: 'position' }, - asset_name: { id: @asset.id, value_for: 'file_file_name' }, - action: action - }) + message_items: message_items) elsif @assoc.class == Result Activities::CreateActivityService .call(activity_type: :edit_wopi_file_on_result, diff --git a/app/views/global_activities/references/_protocol.html.erb b/app/views/global_activities/references/_protocol.html.erb index 9db6d9e37..66f2b5ed7 100644 --- a/app/views/global_activities/references/_protocol.html.erb +++ b/app/views/global_activities/references/_protocol.html.erb @@ -5,23 +5,21 @@ <%= render partial: "global_activities/references/my_module.html.erb", locals: { team: team, subject: subject&.my_module, breadcrumbs: breadcrumbs } %> <% end %> -
- - <% if subject %> - <% if subject.in_repository? || subject.my_module.navigable? %> - <% path = subject.in_repository? ? protocols_path(team: subject.team) : protocols_my_module_path(subject.my_module) %> - <%= route_to_other_team path, - team, - subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), - title: subject.name %> - <% else %> - - <%= subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH) %> - - <% end %> - <% else %> +<% if subject %> + <% if subject.in_repository? %> +
+ + <%= route_to_other_team protocols_path(team: subject.team), + team, + subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), + title: subject.name %> +
+ <% end %> +<% else %> +
+ <%= breadcrumbs[:protocol]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %> - <% end %> -
+
+<% end %> diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index f684394b1..0d93f5e2c 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -208,7 +208,8 @@ class Extends export_audit_trails: 97, export_system_logs: 98, edit_wopi_file_on_result: 99, - edit_wopi_file_on_step: 100 + edit_wopi_file_on_step: 100, + edit_wopi_file_on_step_in_repository: 101 }.freeze ACTIVITY_GROUPS = { diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index 70f34a252..a580d2df1 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -58,19 +58,20 @@ en: edit_module_comment_html: "%{user} edited comment on task %{my_module}." delete_module_comment_html: "%{user} deleted comment on task %{my_module}." change_module_description_html: "%{user} edited task %{my_module}'s description." - create_step_html: "%{user} created protocol %{protocol}'s step %{step_position} %{step}." - edit_step_html: "%{user} edited protocol %{protocol}'s step %{step_position} %{step}." - destroy_step_html: "%{user} deleted protocol %{protocol}'s step %{step_position} %{step}." - load_protocol_to_task_from_repository_html: "%{user} loaded protocol %{protocol} to task from Protocol repository %{protocol_repository}." - load_protocol_to_task_from_file_html: "%{user} loaded protocol %{protocol} to task from file." - update_protocol_in_task_from_repository_html: "%{user} updated protocol %{protocol} on task with version from Protocol repository %{protocol_repository}." - check_step_checklist_item_html: "%{user} completed checklist item %{checkbox} (%{num_completed}/%{num_all} completed) in protocol %{protocol}'s step %{step_position} %{step}." - uncheck_step_checklist_item_html: "%{user} uncompleted checklist item %{checkbox} (%{num_completed}/%{num_all} completed) in protocol %{protocol}'s step %{step_position} %{step}." - add_comment_to_step_html: "%{user} commented on protocol %{protocol}'s step %{step_position} %{step}." - edit_step_comment_html: "%{user} edited comment on protocol %{protocol}'s step %{step_position} %{step}." - delete_step_comment_html: "%{user} deleted comment on protocol %{protocol}'s step %{step_position} %{step}." - complete_step_html: "%{user} completed protocol %{protocol}'s step %{step_position} %{step} (%{num_completed}/%{num_all} completed)." - uncomplete_step_html: "%{user} uncompleted protocol %{protocol}'s step %{step_position} %{step} (%{num_completed}/%{num_all} completed)." + create_step_html: "%{user} created protocol's step %{step_position} %{step} on task %{my_module}." + edit_step_html: "%{user} edited protocol's step %{step_position} %{step} on task %{my_module}." + destroy_step_html: "%{user} deleted protocol's step %{step_position} %{step} on task %{my_module}." + load_protocol_to_task_from_repository_html: "%{user} loaded protocol to task %{my_module} from Protocol repository %{protocol_repository}." + load_protocol_to_task_from_file_html: "%{user} loaded protocol to task %{my_module} from file." + update_protocol_in_task_from_repository_html: "%{user} updated protocol on task %{my_module} with version from Protocol repository %{protocol_repository}." + update_protocol_in_repository_from_task_html: "%{user} updated protocol %{protocol_repository} in Protocol repository with version from task %{my_module}." + check_step_checklist_item_html: "%{user} completed checklist item %{checkbox} (%{num_completed}/%{num_all} completed) in protocol's step %{step_position} %{step} on task %{my_module}." + uncheck_step_checklist_item_html: "%{user} uncompleted checklist item %{checkbox} (%{num_completed}/%{num_all} completed) in protocol's step %{step_position} %{step} on task %{my_module}." + add_comment_to_step_html: "%{user} commented on protocol's step %{step_position} %{step} on task %{my_module}." + edit_step_comment_html: "%{user} edited comment on protocol's step %{step_position} %{step} on task %{my_module}." + delete_step_comment_html: "%{user} deleted comment on protocol's step %{step_position} %{step} on task %{my_module}." + complete_step_html: "%{user} completed protocol's step %{step_position} %{step} on task %{my_module} (%{num_completed}/%{num_all} completed)." + uncomplete_step_html: "%{user} uncompleted protocol's step %{step_position} %{step} on task %{my_module} (%{num_completed}/%{num_all} completed)." complete_task_html: "%{user} completed task %{my_module}." uncomplete_task_html: "%{user} uncompleted task %{my_module}." assign_repository_record_html: "%{user} assigned inventory item(s) %{record_names} from inventory %{repository} to task %{my_module}." @@ -86,42 +87,43 @@ en: clone_experiment_html: "%{user} copied experiment %{experiment_new} from experiment %{experiment_original} as template." archive_experiment_html: "%{user} archived experiment %{experiment}." edit_wopi_file_on_result_html: "%{user} edited Office online file %{asset_name} on result %{result}: %{action}." - edit_wopi_file_on_step_html: "%{user} edited Office online file %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}: %{action}." - restore_experiment_html: "%{user} restored experiment %{experiment}" - rename_task_html: "%{user} renamed task %{my_module}" - move_task_html: "%{user} moved task %{my_module} from experiment %{experiment_original} to experiment %{experiment_new}" - archive_task_html: "%{user} archived task %{my_module}" - set_task_due_date_html: "%{user} set due date %{my_module_duedate} on task %{my_module}" - change_task_due_date_html: "%{user} changed due date %{my_module_duedate} on task %{my_module}" - remove_task_due_date_html: "%{user} removed due date %{my_module_duedate} on task %{my_module}" - add_task_tag_html: "%{user} added tag %{tag} to task %{my_module}" - remove_task_tag_html: "%{user} removed tag %{tag} from task %{my_module}" - create_inventory_html: "%{user} created inventory %{repository}" - rename_inventory_html: "%{user} renamed inventory %{repository}" - delete_inventory_html: "%{user} deleted inventory %{repository}" - create_item_inventory_html: "%{user} created inventory item %{repository_row}" - edit_item_inventory_html: "%{user} edited inventory item %{repository_row}" - delete_item_inventory_html: "%{user} deleted inventory item %{repository_row}" - create_column_inventory_html: "%{user} created column %{repository_column} in inventory %{repository}" - edit_column_inventory_html: "%{user} edited column %{repository_column} in inventory %{repository}" - delete_column_inventory_html: "%{user} deleted column %{repository_column} in inventory %{repository}" - create_protocol_in_repository_html: "%{user} created protocol %{protocol} in Protocol repository" - add_step_to_protocol_repository_html: "%{user} created protocol %{protocol}'s step %{step} in Protocol repository" - edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step %{step} in Protocol repository" - delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step %{step} in Protocol repository" - edit_description_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s description in Protocol repository" - edit_keywords_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s keywords in Protocol repository" - edit_authors_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s authors in Protocol repository" - archive_protocol_in_repository_html: "%{user} archived protocol %{protocol} in Protocol repository" - restore_protocol_in_repository_html: "%{user} restored protocol %{protocol} from archive in Protocol repository" - move_protocol_in_repository_html: "%{user} moved protocol %{protocol} from %{storage}" - import_protocol_in_repository_html: "%{user} imported protocol %{protocol} to Protocol repository from file" - export_protocol_in_repository_html: "%{user} exported protocol %{protocol} from Protocol repository" - invite_user_to_team_html: "%{user} invited user %{user_invited} to team %{team} with user role %{role}" - remove_user_from_team_html: "%{user} removed user %{user_removed} from team %{team}" - change_users_role_on_team_html: "%{user} changed user %{user_changed}'s role in team %{team} to %{role}" - export_projects_html: "%{user} exported project(s) %{projects} to .zip" - export_inventory_items_html: "%{user} exported inventory item(s) from %{repository}" + edit_wopi_file_on_step_html: "%{user} edited Office online file %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}: %{action}." + edit_wopi_file_on_step_in_repository_html: "%{user} edited Office online file %{asset_name} on protocol %{protocol}'s step %{step_position} %{step} in Protocol repository: %{action}." + restore_experiment_html: "%{user} restored experiment %{experiment}." + rename_task_html: "%{user} renamed task %{my_module}." + move_task_html: "%{user} moved task %{my_module} from experiment %{experiment_original} to experiment %{experiment_new}." + archive_task_html: "%{user} archived task %{my_module}." + set_task_due_date_html: "%{user} set due date %{my_module_duedate} on task %{my_module}." + change_task_due_date_html: "%{user} changed due date %{my_module_duedate} on task %{my_module}." + remove_task_due_date_html: "%{user} removed due date %{my_module_duedate} on task %{my_module}." + add_task_tag_html: "%{user} added tag %{tag} to task %{my_module}." + remove_task_tag_html: "%{user} removed tag %{tag} from task %{my_module}." + create_inventory_html: "%{user} created inventory %{repository}." + rename_inventory_html: "%{user} renamed inventory %{repository}." + delete_inventory_html: "%{user} deleted inventory %{repository}." + create_item_inventory_html: "%{user} created inventory item %{repository_row}." + edit_item_inventory_html: "%{user} edited inventory item %{repository_row}." + delete_item_inventory_html: "%{user} deleted inventory item %{repository_row}." + create_column_inventory_html: "%{user} created column %{repository_column} in inventory %{repository}." + edit_column_inventory_html: "%{user} edited column %{repository_column} in inventory %{repository}." + delete_column_inventory_html: "%{user} deleted column %{repository_column} in inventory %{repository}." + create_protocol_in_repository_html: "%{user} created protocol %{protocol} in Protocol repository." + add_step_to_protocol_repository_html: "%{user} created protocol %{protocol}'s step %{step} in Protocol repository." + edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step %{step} in Protocol repository." + delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step %{step} in Protocol repository." + edit_description_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s description in Protocol repository." + edit_keywords_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s keywords in Protocol repository." + edit_authors_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s authors in Protocol repository." + archive_protocol_in_repository_html: "%{user} archived protocol %{protocol} in Protocol repository." + restore_protocol_in_repository_html: "%{user} restored protocol %{protocol} from archive in Protocol repository." + move_protocol_in_repository_html: "%{user} moved protocol %{protocol} from %{storage} in Protocol repository." + import_protocol_in_repository_html: "%{user} imported protocol %{protocol} to Protocol repository from file." + export_protocol_in_repository_html: "%{user} exported protocol %{protocol} from Protocol repository." + invite_user_to_team_html: "%{user} invited user %{user_invited} to team %{team} with user role %{role}." + remove_user_from_team_html: "%{user} removed user %{user_removed} from team %{team}." + change_users_role_on_team_html: "%{user} changed user %{user_changed}'s role in team %{team} to %{role}." + export_projects_html: "%{user} exported project(s) %{projects} to .zip." + export_inventory_items_html: "%{user} exported inventory item(s) from %{repository}." activity_name: create_project: "Project created" rename_project: "Project renamed" @@ -177,7 +179,8 @@ en: clone_experiment: "Experiment copied as template" archive_experiment: "Experiment archived" edit_wopi_file_on_result: "Office online file on result edited" - edit_wopi_file_on_step: "Office online file on step edited" + edit_wopi_file_on_step: "Office online file on task step edited" + edit_wopi_file_on_step_in_repository: "Office online file on step edited" restore_experiment: "Experiment restored" rename_task: "Task renamed" move_task: "Task moved"