Merge pull request #2722 from okriuchykhin/ok_SCI_4845

Fix missing unshared inventories with snapshots in reports [SCI-4845]
This commit is contained in:
Miha Mencin 2020-07-10 09:21:58 +02:00 committed by GitHub
commit 12a8d50098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -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 }

View file

@ -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

View file

@ -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)
}