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.
This commit is contained in:
evazion
2022-02-03 21:51:13 -06:00
parent 2b1c58c959
commit 2c0feaf943
2 changed files with 6 additions and 4 deletions

View File

@@ -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 %>
<div class="text-center text-muted text-xs h-12">
<% if media_asset.post.present? %>
@@ -18,8 +20,8 @@
</div>
<% 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 %>
<em>No source</em>
<% end %>