From 84ca6e69dde45c3a1dd9f0693f7b22c1d966d967 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Mon, 5 Jan 2026 17:33:26 -0500 Subject: [PATCH 1/5] add pretty BAC names #1531 --- .../app/models/background_activity/duplicate_task.rb | 5 +++++ BrainPortal/app/models/background_activity/move_file.rb | 8 ++++++++ BrainPortal/app/models/background_activity/sync_file.rb | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/BrainPortal/app/models/background_activity/duplicate_task.rb b/BrainPortal/app/models/background_activity/duplicate_task.rb index c7f8a179c..b5aa07857 100644 --- a/BrainPortal/app/models/background_activity/duplicate_task.rb +++ b/BrainPortal/app/models/background_activity/duplicate_task.rb @@ -28,6 +28,11 @@ class BackgroundActivity::DuplicateTask < BackgroundActivity Revision_info=CbrainFileRevision[__FILE__] #:nodoc: + def pretty_name + dest_name = RemoteResource.where(:id => self.options[:dub_bourreau_id]).first&.name.presence + [super, dest_name].compact.join(" to ") + end + def process(item) task = CbrainTask.real_tasks.find(item) new_bid = options[:dup_bourreau_id].presence || task.bourreau_id diff --git a/BrainPortal/app/models/background_activity/move_file.rb b/BrainPortal/app/models/background_activity/move_file.rb index aa3517d81..9fc0f9ce1 100644 --- a/BrainPortal/app/models/background_activity/move_file.rb +++ b/BrainPortal/app/models/background_activity/move_file.rb @@ -28,6 +28,14 @@ class BackgroundActivity::MoveFile < BackgroundActivity validates_bac_presence_of_option :dest_data_provider_id validates_dynamic_bac_presence_of_option :userfile_custom_filter_id + def pretty_name + dp_id = self.options[:dest_data_provider_id] + dp = DataProvider.find(dp_id) rescue nil + dp_name = dp&.name || "##{dp_id}" + self.class.to_s.demodulize.underscore.humanize + " to #{dp_name}" + end + + # Helper for scheduling a move of the files immediately. def self.setup!(user_id, userfile_ids, remote_resource_id, dest_data_provider_id, options={}) ba = self.local_new(user_id, userfile_ids, remote_resource_id) diff --git a/BrainPortal/app/models/background_activity/sync_file.rb b/BrainPortal/app/models/background_activity/sync_file.rb index 59a50429f..f18b3e3e4 100644 --- a/BrainPortal/app/models/background_activity/sync_file.rb +++ b/BrainPortal/app/models/background_activity/sync_file.rb @@ -27,6 +27,10 @@ class BackgroundActivity::SyncFile < BackgroundActivity validates_dynamic_bac_presence_of_option :userfile_custom_filter_id + def pretty_name # removeme + super + " to cache" + end + # Helper for scheduling a mass sync_to_cache immediately. def self.setup!(user_id, userfile_ids, remote_resource_id=nil) ba = self.local_new(user_id, userfile_ids, remote_resource_id) From 71508a46908c9503521c3b86a033660fbdb57be0 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Mon, 5 Jan 2026 18:05:45 -0500 Subject: [PATCH 2/5] add pretty BAC names - drop an empty line #1531 --- BrainPortal/app/models/background_activity/move_file.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/BrainPortal/app/models/background_activity/move_file.rb b/BrainPortal/app/models/background_activity/move_file.rb index 9fc0f9ce1..47f5d5565 100644 --- a/BrainPortal/app/models/background_activity/move_file.rb +++ b/BrainPortal/app/models/background_activity/move_file.rb @@ -35,7 +35,6 @@ def pretty_name self.class.to_s.demodulize.underscore.humanize + " to #{dp_name}" end - # Helper for scheduling a move of the files immediately. def self.setup!(user_id, userfile_ids, remote_resource_id, dest_data_provider_id, options={}) ba = self.local_new(user_id, userfile_ids, remote_resource_id) From c8bec9e36a369ce249e7d169a15150a6ff885718 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Mon, 5 Jan 2026 18:24:51 -0500 Subject: [PATCH 3/5] add pretty BAC names - polishing #1531 --- BrainPortal/app/models/background_activity/duplicate_task.rb | 2 +- BrainPortal/app/models/background_activity/move_file.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BrainPortal/app/models/background_activity/duplicate_task.rb b/BrainPortal/app/models/background_activity/duplicate_task.rb index b5aa07857..49ebe077d 100644 --- a/BrainPortal/app/models/background_activity/duplicate_task.rb +++ b/BrainPortal/app/models/background_activity/duplicate_task.rb @@ -29,7 +29,7 @@ class BackgroundActivity::DuplicateTask < BackgroundActivity Revision_info=CbrainFileRevision[__FILE__] #:nodoc: def pretty_name - dest_name = RemoteResource.where(:id => self.options[:dub_bourreau_id]).first&.name.presence + dest_name = Bourreau.find_by_id(self.options[:dub_bourreau_id])&.name.presence [super, dest_name].compact.join(" to ") end diff --git a/BrainPortal/app/models/background_activity/move_file.rb b/BrainPortal/app/models/background_activity/move_file.rb index 47f5d5565..01f6c0f35 100644 --- a/BrainPortal/app/models/background_activity/move_file.rb +++ b/BrainPortal/app/models/background_activity/move_file.rb @@ -29,8 +29,8 @@ class BackgroundActivity::MoveFile < BackgroundActivity validates_dynamic_bac_presence_of_option :userfile_custom_filter_id def pretty_name - dp_id = self.options[:dest_data_provider_id] - dp = DataProvider.find(dp_id) rescue nil + dp_id = self.options[:dest_data_provider_id] + dp = DataProvider.find_by_id(dp_id) dp_name = dp&.name || "##{dp_id}" self.class.to_s.demodulize.underscore.humanize + " to #{dp_name}" end From 789201cd2934b1498d2423089e1b574dfcc71746 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Tue, 6 Jan 2026 18:13:45 -0500 Subject: [PATCH 4/5] add pretty BAC names - fix typo #1531 --- BrainPortal/app/models/background_activity/duplicate_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BrainPortal/app/models/background_activity/duplicate_task.rb b/BrainPortal/app/models/background_activity/duplicate_task.rb index 49ebe077d..f32c731d1 100644 --- a/BrainPortal/app/models/background_activity/duplicate_task.rb +++ b/BrainPortal/app/models/background_activity/duplicate_task.rb @@ -29,7 +29,7 @@ class BackgroundActivity::DuplicateTask < BackgroundActivity Revision_info=CbrainFileRevision[__FILE__] #:nodoc: def pretty_name - dest_name = Bourreau.find_by_id(self.options[:dub_bourreau_id])&.name.presence + dest_name = Bourreau.find_by_id(self.options[:dup_bourreau_id])&.name.presence [super, dest_name].compact.join(" to ") end From 5474a5a619420f02ae1cea0ff0ad6a58bff112e7 Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Tue, 6 Jan 2026 18:31:33 -0500 Subject: [PATCH 5/5] add pretty BAC names - add a unittest #1531 --- .../spec/models/background_activity_spec.rb | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 BrainPortal/spec/models/background_activity_spec.rb diff --git a/BrainPortal/spec/models/background_activity_spec.rb b/BrainPortal/spec/models/background_activity_spec.rb new file mode 100644 index 000000000..7418a1469 --- /dev/null +++ b/BrainPortal/spec/models/background_activity_spec.rb @@ -0,0 +1,88 @@ + +# +# CBRAIN Project +# +# Copyright (C) 2008-2012 +# The Royal Institution for the Advancement of Learning +# McGill University +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# spec/models/background_activity/duplicate_task_spec.rb + +require 'rails_helper' + +RSpec.describe BackgroundActivity::DuplicateTask, type: :model do + describe "#pretty_name" do + # Setup the parent class method stub + before do + allow_any_instance_of(BackgroundActivity).to receive(:pretty_name).and_return("Duplicate Task") + end + + context "when destination bourreau exists" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + let(:bourreau) { instance_double(Bourreau, name: "Test Bourreau") } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(bourreau) + end + + it "appends the bourreau name to the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task to Test Bourreau") + end + end + + context "when destination bourreau is not found" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(nil) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + + context "when dup_bourreau_id is nil" do + let(:options) { { dup_bourreau_id: nil } } + let(:activity) { described_class.new(options: options) } + + before do + # We don't expect find_by_id to be called at all with nil + # Or if it does, we need to allow it to be called with nil + allow(Bourreau).to receive(:find_by_id).with(nil).and_return(nil) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + + context "when bourreau has no name (empty string)" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + let(:bourreau) { instance_double(Bourreau, name: "") } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(bourreau) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + end +end