diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-10-13 15:27:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 15:27:19 +0200 |
commit | 5159ba26e485daaeded2288c1b02bd1e516e1ca6 (patch) | |
tree | 409023bc5a521a321205265d9c1d8fd6d3eb3273 /app | |
parent | 8818622feb9454684e51cd9b977b967883779432 (diff) |
Fix error when rendering public pages with media attachments (#16763)
* Add tests * Fix error when rendering public pages with media attachments * Add tests * Fix tests * Please CodeClimate
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/media_controller.rb | 7 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index ce015dd1b..ee82625a0 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -27,7 +27,12 @@ class MediaController < ApplicationController private def set_media_attachment - @media_attachment = MediaAttachment.attached.find_by!(shortcode: params[:id] || params[:medium_id]) + id = params[:id] || params[:medium_id] + return if id.nil? + + scope = MediaAttachment.local.attached + # If id is 19 characters long, it's a shortcode, otherwise it's an identifier + @media_attachment = id.size == 19 ? scope.find_by!(shortcode: id) : scope.find_by!(id: id) end def verify_permitted_status! diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 97d619f35..1741d20e9 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -217,7 +217,7 @@ class MediaAttachment < ApplicationRecord end def to_param - shortcode + shortcode.presence || id&.to_s end def focus=(point) |