From a7cb519faafa9977fc3146a6b32af7f4db3fae6c Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 13 May 2024 11:29:31 +0200 Subject: [PATCH] Fix filtering archived global search results [SCI-10696] --- app/models/experiment.rb | 2 +- app/models/my_module.rb | 6 +++++- app/models/protocol.rb | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 1fac3f4d8..464de0f9e 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -73,7 +73,7 @@ class Experiment < ApplicationRecord .where(user_assignments: { team: teams }) .where_attributes_like_boolean(SEARCHABLE_ATTRIBUTES, query, options) - new_query = new_query.active unless include_archived + new_query = new_query.joins(:project).active.where(projects: { archived: false }) unless include_archived new_query end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 9ab70a638..fadfeca35 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -119,7 +119,11 @@ class MyModule < ApplicationRecord .where(user_assignments: { team: teams }) .where_attributes_like_boolean(SEARCHABLE_ATTRIBUTES, query, options) - new_query = new_query.active unless include_archived + unless include_archived + new_query = new_query.joins(experiment: :project) + .active + .where(experiments: { archived: false }, projects: { archived: false }) + end new_query end diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 9409c78f1..9d2f147be 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -184,7 +184,14 @@ class Protocol < ApplicationRecord "AND my_module_user_assignments.assignable_id = my_modules.id") .where(my_module_user_assignments: { user_id: user }) .where(team: teams) - protocols = protocols.active unless include_archived + unless include_archived + protocols = protocols.joins(my_module: { experiment: :project }) + .active + .where(my_modules: { archived: false }, + experiments: { archived: false }, + projects: { archived: false }) + end + protocols.select(:id) end || []