From e8d20dfc01a46b2def612b6fc7a37fa03b707637 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 2 Nov 2016 09:18:06 +0100 Subject: [PATCH 1/4] Added additional activities [SCI-605] --- app/controllers/experiments_controller.rb | 30 +++++++++++++++++ app/controllers/my_modules_controller.rb | 28 ++++++++++++++++ app/controllers/protocols_controller.rb | 39 +++++++++++++++++++++-- app/controllers/reports_controller.rb | 33 +++++++++++++++++++ app/models/activity.rb | 13 +++++++- config/locales/en.yml | 13 +++++++- 6 files changed, 151 insertions(+), 5 deletions(-) diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index f181505da..30d8d8d0b 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -39,6 +39,16 @@ class ExperimentsController < ApplicationController @experiment.last_modified_by = current_user @experiment.project = @project if @experiment.save + Activity.create( + type_of: :create_experiment, + project: @experiment.project, + user: current_user, + message: I18n.t( + 'activities.create_experiment', + user: current_user.full_name, + experiment: @experiment.name + ) + ) flash[:success] = t('experiments.create.success_flash', experiment: @experiment.name) respond_to do |format| @@ -76,6 +86,16 @@ class ExperimentsController < ApplicationController @experiment.update_attributes(experiment_params) @experiment.last_modified_by = current_user if @experiment.save + Activity.create( + type_of: :edit_experiment, + project: @experiment.project, + user: current_user, + message: I18n.t( + 'activities.edit_experiment', + user: current_user.full_name, + experiment: @experiment.name + ) + ) @experiment.touch(:workflowimg_updated_at) flash[:success] = t('experiments.update.success_flash', experiment: @experiment.name) @@ -106,6 +126,16 @@ class ExperimentsController < ApplicationController @experiment.archived_by = current_user @experiment.archived_on = DateTime.now if @experiment.save + Activity.create( + type_of: :archive_experiment, + project: @experiment.project, + user: current_user, + message: I18n.t( + 'activities.archive_experiment', + user: current_user.full_name, + experiment: @experiment.name + ) + ) flash[:success] = t('experiments.archive.success_flash', experiment: @experiment.name) diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 0fdd0b23d..79be59daa 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -271,10 +271,24 @@ class MyModulesController < ApplicationController end end + task_names = [] @my_module.get_downstream_modules.each do |my_module| new_samples = samples.select { |el| my_module.samples.exclude?(el) } my_module.samples.push(*new_samples) + task_names << my_module.name end + Activity.create( + type_of: :assign_sample, + project: @my_module.experiment.project, + my_module: @my_module, + user: current_user, + message: I18n.t( + 'activities.assign_sample', + user: current_user.full_name, + tasks: task_names.join(', '), + samples: samples.map(&:name).join(', ') + ) + ) end redirect_to samples_my_module_path(@my_module) end @@ -293,9 +307,23 @@ class MyModulesController < ApplicationController end end + task_names = [] @my_module.get_downstream_modules.each do |my_module| + task_names << my_module.name my_module.samples.destroy(samples & my_module.samples) end + Activity.create( + type_of: :unassign_sample, + project: @my_module.experiment.project, + my_module: @my_module, + user: current_user, + message: I18n.t( + 'activities.unassign_sample', + user: current_user.full_name, + tasks: task_names.join(', '), + samples: samples.map(&:name).join(', ') + ) + ) end redirect_to samples_my_module_path(@my_module) end diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 93cccf17c..01f97ad93 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -364,7 +364,18 @@ class ProtocolsController < ApplicationController status: :bad_request } else - # Everything good, display flash & render 200 + # Everything good, record activity, display flash & render 200 + Activity.create( + type_of: :revert_protocol, + project: @protocol.my_module.experiment.project, + my_module: @protocol.my_module, + user: current_user, + message: I18n.t( + 'activities.revert_protocol', + user: current_user.full_name, + protocol: @protocol.name + ) + ) flash[:success] = t( "my_modules.protocols.update_parent_flash", ) @@ -426,7 +437,18 @@ class ProtocolsController < ApplicationController status: :bad_request } else - # Everything good, display flash & render 200 + # Everything good, record activity, display flash & render 200 + Activity.create( + type_of: :load_protocol_from_repository, + project: @protocol.my_module.experiment.project, + my_module: @protocol.my_module, + user: current_user, + message: I18n.t( + 'activities.load_protocol_from_repository', + user: current_user.full_name, + protocol: @source.name + ) + ) flash[:success] = t( "my_modules.protocols.load_from_repository_flash", ) @@ -454,7 +476,18 @@ class ProtocolsController < ApplicationController render json: { status: :error }, status: :bad_request } else - # Everything good, display flash & render 200 + # Everything good, record activity, display flash & render 200 + Activity.create( + type_of: :load_protocol_from_file, + project: @protocol.my_module.experiment.project, + my_module: @protocol.my_module, + user: current_user, + message: I18n.t( + 'activities.load_protocol_from_file', + user: current_user.full_name, + protocol: @protocol_json.name + ) + ) flash[:success] = t( "my_modules.protocols.load_from_file_flash", ) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index cdfaf700f..52a8b8569 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -84,6 +84,17 @@ class ReportsController < ApplicationController @report.last_modified_by = current_user if continue and @report.save_with_contents(report_contents) + # record an activity + Activity.create( + type_of: :create_report, + project: @report.project, + user: current_user, + message: I18n.t( + 'activities.create_report', + user: current_user.full_name, + report: @report.name + ) + ) respond_to do |format| format.json { render json: { url: project_reports_path(@project) }, status: :ok @@ -119,6 +130,17 @@ class ReportsController < ApplicationController @report.assign_attributes(report_params) if continue and @report.save_with_contents(report_contents) + # record an activity + Activity.create( + type_of: :edit_report, + project: @report.project, + user: current_user, + message: I18n.t( + 'activities.edit_report', + user: current_user.full_name, + report: @report.name + ) + ) respond_to do |format| format.json { render json: { url: project_reports_path(@project) }, status: :ok @@ -149,6 +171,17 @@ class ReportsController < ApplicationController report = Report.find_by_id(report_id) if report.present? + # record an activity + Activity.create( + type_of: :delete_report, + project: report.project, + user: current_user, + message: I18n.t( + 'activities.delete_report', + user: current_user.full_name, + report: report.name + ) + ) report.destroy end end diff --git a/app/models/activity.rb b/app/models/activity.rb index 9d00b9453..57967d082 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -29,6 +29,9 @@ class Activity < ActiveRecord::Base :add_comment_to_result, :archive_result, :edit_result, + :create_experiment, + :edit_experiment, + :archive_experiment, :clone_experiment, :move_experiment, :add_comment_to_project, @@ -41,7 +44,15 @@ class Activity < ActiveRecord::Base :delete_step_comment, :edit_result_comment, :delete_result_comment, - :destroy_result + :destroy_result, + :load_protocol_from_file, + :load_protocol_from_repository, + :revert_protocol, + :create_report, + :delete_report, + :edit_report, + :assign_sample, + :unassign_sample ] validates :type_of, presence: true diff --git a/config/locales/en.yml b/config/locales/en.yml index ce68913e1..3f2a29ada 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1038,7 +1038,10 @@ en: edit_asset_result: "%{user} edited file result %{result}." edit_text_result: "%{user} edited text result %{result}." edit_table_result: "%{user} edited table result %{result}." - clone_experiment: "%{user} cloned %{experiment_new} from %{experiment_original}." + archive_experiment: "%{user} archived experiment %{experiment}." + create_experiment: "%{user} created experiment %{experiment}." + edit_experiment: "%{user} edited experiment %{experiment}." + clone_experiment: "%{user} cloned experiment %{experiment_new} from %{experiment_original}." move_experiment: "%{user} moved experiment %{experiment} from project %{project_original} to project %{project_new}." add_comment_to_project: "%{user} commented on project %{project}." edit_project_comment: "%{user} edited comment on project %{project}." @@ -1050,6 +1053,14 @@ en: delete_step_comment: "%{user} deleted comment on Step %{step} %{step_name}." edit_result_comment: "%{user} edited comment on result %{result}." delete_result_comment: "%{user} deleted comment on result %{result}." + load_protocol_from_file: "%{user} loaded protocol %{protocol} from file." + load_protocol_from_repository: "%{user} loaded protocol %{protocol} from repository." + revert_protocol: "%{user} reverted protocol %{protocol} from repository." + create_report: "%{user} created report %{report}." + delete_report: "%{user} deleted report %{report}." + edit_report: "%{user} edited report %{report}." + assign_sample: "%{user} assigned sample(s) %{samples} to task(s) %{tasks}." + unassign_sample: "%{user} unassigned sample(s) %{samples} from task(s) %{tasks}." user_my_modules: new: From 3d25da5db7d2ba5a035e89cc13185c13e74b4688 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 3 Nov 2016 14:15:22 +0100 Subject: [PATCH 2/4] Fixed bug with protocol loading from file [SCI-605] --- app/controllers/protocols_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 01f97ad93..7778d5c08 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -485,7 +485,7 @@ class ProtocolsController < ApplicationController message: I18n.t( 'activities.load_protocol_from_file', user: current_user.full_name, - protocol: @protocol_json.name + protocol: @protocol_json[:name] ) ) flash[:success] = t( From a1bfacef8649755a3fd3b4dd53104b8b1ba8f405 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 3 Nov 2016 17:59:32 +0100 Subject: [PATCH 3/4] Improved samples assign/unassign logging [SCI-605] --- app/controllers/my_modules_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 79be59daa..a2d0f5c59 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -272,6 +272,7 @@ class MyModulesController < ApplicationController end task_names = [] + new_samples = [] @my_module.get_downstream_modules.each do |my_module| new_samples = samples.select { |el| my_module.samples.exclude?(el) } my_module.samples.push(*new_samples) @@ -286,7 +287,7 @@ class MyModulesController < ApplicationController 'activities.assign_sample', user: current_user.full_name, tasks: task_names.join(', '), - samples: samples.map(&:name).join(', ') + samples: new_samples.map(&:name).join(', ') ) ) end @@ -302,7 +303,7 @@ class MyModulesController < ApplicationController sample.last_modified_by = current_user sample.save - if sample + if sample && @my_module.samples.include?(sample) samples << sample end end From fe6724431ea715932bc836cb230a17013e669136 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 7 Nov 2016 09:29:56 +0100 Subject: [PATCH 4/4] Futher improvement of samples assign/unassign logging [SCI-605] --- app/controllers/my_modules_controller.rb | 48 +++++++++++++----------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index a2d0f5c59..d75b622c4 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -278,18 +278,20 @@ class MyModulesController < ApplicationController my_module.samples.push(*new_samples) task_names << my_module.name end - Activity.create( - type_of: :assign_sample, - project: @my_module.experiment.project, - my_module: @my_module, - user: current_user, - message: I18n.t( - 'activities.assign_sample', - user: current_user.full_name, - tasks: task_names.join(', '), - samples: new_samples.map(&:name).join(', ') + if new_samples.any? + Activity.create( + type_of: :assign_sample, + project: @my_module.experiment.project, + my_module: @my_module, + user: current_user, + message: I18n.t( + 'activities.assign_sample', + user: current_user.full_name, + tasks: task_names.join(', '), + samples: new_samples.map(&:name).join(', ') + ) ) - ) + end end redirect_to samples_my_module_path(@my_module) end @@ -313,18 +315,20 @@ class MyModulesController < ApplicationController task_names << my_module.name my_module.samples.destroy(samples & my_module.samples) end - Activity.create( - type_of: :unassign_sample, - project: @my_module.experiment.project, - my_module: @my_module, - user: current_user, - message: I18n.t( - 'activities.unassign_sample', - user: current_user.full_name, - tasks: task_names.join(', '), - samples: samples.map(&:name).join(', ') + if samples.any? + Activity.create( + type_of: :unassign_sample, + project: @my_module.experiment.project, + my_module: @my_module, + user: current_user, + message: I18n.t( + 'activities.unassign_sample', + user: current_user.full_name, + tasks: task_names.join(', '), + samples: samples.map(&:name).join(', ') + ) ) - ) + end end redirect_to samples_my_module_path(@my_module) end