From fe6724431ea715932bc836cb230a17013e669136 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 7 Nov 2016 09:29:56 +0100 Subject: [PATCH] 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