diff --git a/app/controllers/my_module_shareable_links_controller.rb b/app/controllers/my_module_shareable_links_controller.rb index a94200217..225825ab0 100644 --- a/app/controllers/my_module_shareable_links_controller.rb +++ b/app/controllers/my_module_shareable_links_controller.rb @@ -153,7 +153,7 @@ class MyModuleShareableLinksController < ApplicationController end def load_repository - @repository = @my_module.assigned_repositories.viewable_by_user(current_user).find_by(id: params[:id]) + @repository = @my_module.assigned_repositories.find_by(id: params[:id]) render_404 unless @repository end 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 %>