Find media attachments by URL
flag=media_links_use_attachment_id Test plan - Test with NQ -> NQ copy to - Add a media attachment link into a New Quiz - Use "copy to" to copy the NQ to a new course - Ensure media_attachment link is updated with new file ID Change-Id: I051f7fb8f93fb79759aacc8576fc5179e0b3e766 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/333489 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Eric Saupe <eric.saupe@instructure.com> Reviewed-by: Jacob DeWar <jacob.dewar@instructure.com> QA-Review: Jacob DeWar <jacob.dewar@instructure.com> Product-Review: Mysti Lilla <mysti@instructure.com>
This commit is contained in:
parent
f804e3ad1f
commit
0316e7ad0e
|
@ -253,10 +253,7 @@ module Context
|
|||
user = User.find(params[:user_id]) if params[:user_id]
|
||||
context = course || group || user
|
||||
|
||||
media_obj = MediaObject.where(media_id: params[:media_object_id]).first if params[:media_object_id]
|
||||
context = media_obj.context if media_obj
|
||||
|
||||
return nil unless context
|
||||
return nil unless context || params[:controller] == "media_objects"
|
||||
|
||||
case params[:controller]
|
||||
when "files"
|
||||
|
@ -296,7 +293,12 @@ module Context
|
|||
context.context_modules.find_by(id: params[:id])
|
||||
end
|
||||
when "media_objects"
|
||||
object = media_obj
|
||||
object = if params[:media_object_id]
|
||||
MediaObject.where(media_id: params[:media_object_id]).first
|
||||
elsif params[:attachment_id]
|
||||
# get possibly replaced attachment, see app/models/attachment.rb find_attachment_possibly_replaced
|
||||
Attachment.find_by(id: params[:attachment_id])&.context&.attachments&.find_by(id: params[:attachment_id])
|
||||
end
|
||||
when "context"
|
||||
object = context.users.find(params[:id]) if params[:action] == "roster_user" && params[:id]
|
||||
else
|
||||
|
|
|
@ -127,6 +127,7 @@ describe Context do
|
|||
expect(Context.find_asset_by_url("/courses/#{@course.id}/files/#{@attachment.id}/download?wrap=1")).to eq @attachment
|
||||
expect(Context.find_asset_by_url("/courses/#{@course.id}/files/#{@attachment.id}/?wrap=1")).to eq @attachment
|
||||
expect(Context.find_asset_by_url("/courses/#{@course.id}/file_contents/course%20files//#{@attachment.name}")).to eq @attachment
|
||||
expect(Context.find_asset_by_url("/media_attachments_iframe/#{@attachment.id}?type=video&embedded=true")).to eq @attachment
|
||||
end
|
||||
|
||||
it "finds folders" do
|
||||
|
|
Loading…
Reference in New Issue