Skip to content

Commit

Permalink
Merge pull request #7823 from scinote-eln/develop
Browse files Browse the repository at this point in the history
Shared task fixes
  • Loading branch information
artoscinote authored Aug 28, 2024
2 parents 4f3b6f7 + 8a7ac76 commit 88462de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/my_module_shareable_links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def shareable_link_load_my_module
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

Expand Down
19 changes: 19 additions & 0 deletions app/models/my_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,25 @@ def readable_live_and_snapshot_repositories_list(user, team = user.current_team)
(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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/shareable_links/my_module_protocol_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</div>
</div>
<!-- Assigned items -->
<% assigned_repositories = @my_module.readable_live_and_snapshot_repositories_list(current_user) %>
<% assigned_repositories = @my_module.live_and_snapshot_repositories_list %>
<div class="task-section">
<div class="task-section-header">
<a class="task-section-caret" role="button" data-toggle="collapse" href="#assigned-items-container" aria-expanded="true" aria-controls="assigned-items-container">
Expand Down

0 comments on commit 88462de

Please sign in to comment.