From 2ebb88c300d8e8d187378422ab720dbc786362ec Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Wed, 28 Aug 2024 11:19:27 +0200 Subject: [PATCH 1/2] Fix shared tasks [SCI-11007] --- app/models/my_module.rb | 19 +++++++++++++++++++ .../my_module_protocol_show.html.erb | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 6f6b3724a..36b7578ff 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -202,6 +202,25 @@ class MyModule < ApplicationRecord (live_repositories + selected_snapshots).sort_by { |r| r.name.downcase } end + def live_and_snapshot_repositories_list + snapshots = repository_snapshots.left_outer_joins(:original_repository) + + selected_snapshots = snapshots.where(selected: true) + .or(snapshots.where(original_repositories_repositories: { id: nil })) + .or(snapshots.where.not(parent_id: assigned_repositories.select(:id))) + .select('DISTINCT ON ("repositories"."parent_id") "repositories".*') + .select('COUNT(repository_rows.id) AS assigned_rows_count') + .joins(:repository_rows) + .group(:parent_id, :id) + .order(:parent_id, updated_at: :desc) + + live_repositories = assigned_repositories + .select('repositories.*, COUNT(DISTINCT repository_rows.id) AS assigned_rows_count') + .where.not(id: repository_snapshots.where(selected: true).select(:parent_id)) + + (live_repositories + selected_snapshots).sort_by { |r| r.name.downcase } + end + def update_report_repository_references(repository) ids = if repository.is_a?(Repository) RepositorySnapshot.where(parent_id: repository.id).pluck(:id) diff --git a/app/views/shareable_links/my_module_protocol_show.html.erb b/app/views/shareable_links/my_module_protocol_show.html.erb index 3c9caf7a3..6e1d46ec6 100644 --- a/app/views/shareable_links/my_module_protocol_show.html.erb +++ b/app/views/shareable_links/my_module_protocol_show.html.erb @@ -57,7 +57,7 @@ - <% assigned_repositories = @my_module.readable_live_and_snapshot_repositories_list(current_user) %> + <% assigned_repositories = @my_module.live_and_snapshot_repositories_list %>