From 7efe5c32eb79bb28b6109039f26e3c9cd19eda6a Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 9 Jul 2020 14:50:01 +0200 Subject: [PATCH] Fix missing unshared and unassigned inventories with snapshots in reports [SCI-4845] --- app/helpers/reports_helper.rb | 2 +- app/models/project.rb | 2 +- app/models/repository_snapshot.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 5f9106c99..f44f2b5f3 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -139,7 +139,7 @@ module ReportsHelper def assigned_repositories_in_project_list(project) live_repositories = Repository.assigned_to_project(project) - snapshots = RepositorySnapshot.assigned_to_project(project) + snapshots = RepositorySnapshot.of_unassigned_from_project(project) snapshots.each { |snapshot| snapshot.name = "#{snapshot.name} #{t('projects.reports.index.deleted')}" } (live_repositories + snapshots).sort_by { |r| r.name.downcase } diff --git a/app/models/project.rb b/app/models/project.rb index 501927bd3..9a8e8661d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -212,7 +212,7 @@ class Project < ApplicationRecord def assigned_repositories_and_snapshots live_repositories = Repository.assigned_to_project(self) - snapshots = RepositorySnapshot.assigned_to_project(self) + snapshots = RepositorySnapshot.of_unassigned_from_project(self) (live_repositories + snapshots).sort_by { |r| r.name.downcase } end diff --git a/app/models/repository_snapshot.rb b/app/models/repository_snapshot.rb index 942e82f4a..f29ad80d4 100644 --- a/app/models/repository_snapshot.rb +++ b/app/models/repository_snapshot.rb @@ -17,11 +17,11 @@ class RepositorySnapshot < RepositoryBase validates :status, presence: true validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? 'selected' } - scope :assigned_to_project, lambda { |project| + scope :of_unassigned_from_project, lambda { |project| joins(my_module: { experiment: :project }) - .where('experiments.project_id = ?', project.id) + .where(my_modules: { experiments: { project: project } }) .left_outer_joins(:original_repository) - .where(original_repositories_repositories: { id: nil }) + .where.not(original_repository: Repository.assigned_to_project(project)) .select('DISTINCT ON ("repositories"."parent_id") "repositories".*') .order(:parent_id, updated_at: :desc) }