From 2c0feaf943de2febbe71171c8268cc9a4dc37feb Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 3 Feb 2022 21:51:13 -0600 Subject: [PATCH] Fix #4988: 'my uploads' page has different links on 'gallery' mode vs 'table' mode Fix a bug where images on the My Uploads page would link to the wrong upload. If an image had been uploaded by multiple users, then it would link to the first upload belonging to the first person to upload the image. This would lead to an Access Denied error when you tried to open the upload. Also fix a bug where uploads on the My Uploads page were ordered incorrectly. They were ordered by most recent asset first, rather than most recent upload first. This meant if you uploaded an image someone else had already uploaded, then it would appear behind your other more recent uploads. --- app/controllers/uploads_controller.rb | 2 +- app/views/uploads/_gallery.html.erb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index a5b06fad4..ba43441d7 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -37,7 +37,7 @@ class UploadsController < ApplicationController @uploads = @uploads.includes(:uploader, media_assets: [:post]) if request.format.html? respond_with(@uploads) when "gallery" - @media_assets = authorize MediaAsset.distinct.visible(CurrentUser.user).joins(:uploads).where(uploads: { uploader: CurrentUser.user }).paginated_search(params, count_pages: true) + @media_assets = authorize MediaAsset.active.visible(CurrentUser.user).includes(:post, uploads: [:uploader]).where(uploads: { uploader: CurrentUser.user }).paginated_search(params, count_pages: true).reorder("uploads.id DESC") respond_with(@media_assets) else raise "Invalid mode '#{mode}'" diff --git a/app/views/uploads/_gallery.html.erb b/app/views/uploads/_gallery.html.erb index afdc86c04..0683ae0dd 100644 --- a/app/views/uploads/_gallery.html.erb +++ b/app/views/uploads/_gallery.html.erb @@ -9,7 +9,9 @@ <%= render(MediaAssetGalleryComponent.new) do |gallery| %> <% @media_assets.each do |media_asset| %> - <% gallery.media_asset(media_asset: media_asset, size: gallery.size, link_target: media_asset.post || media_asset.uploads.first) do |preview| %> + <% @upload = media_asset.uploads.order(id: :desc).select { |upload| upload.uploader == CurrentUser.user }.first %> + + <% gallery.media_asset(media_asset: media_asset, size: gallery.size, link_target: media_asset.post || @upload) do |preview| %> <% preview.footer do %>
<% if media_asset.post.present? %> @@ -18,8 +20,8 @@
<% end %> - <% if media_asset.uploads.first.source.present? %> - <%= external_link_to media_asset.uploads.first.source, Addressable::URI.parse(media_asset.uploads.first.source).domain %> + <% if @upload.source.present? %> + <%= external_link_to @upload.source, Addressable::URI.parse(@upload.source).domain %> <% else %> No source <% end %>