Class: CanvasInlinePdf::Plugin::OverrideFilePreview
- Inherits:
-
Object
- Object
- CanvasInlinePdf::Plugin::OverrideFilePreview
- Defined in:
- lib/canvas_inline_pdf/plugin/override_file_preview.rb
Overview
Callback Class, used to override FilePreviewController#show and use this plugin if applicable, if not - it returns controll to the controller.
This should only happen IF we have the setting turned on. And, this should be removed once Canvas upstream changes their controller to allow for additional plugins beyond croc and canvasdoc.
Instance Method Summary collapse
-
#before(controller) ⇒ Object
Runs before the FilePreviewsController#show method is called If the file can be rendered inline, it will call a redirect which because the controller this is modifying uses an iframe: will render the pdf within the iframe.
Instance Method Details
#before(controller) ⇒ Object
Runs before the FilePreviewsController#show method is called If the file can be rendered inline, it will call a redirect which because the controller this is modifying uses an iframe: will render the pdf within the iframe.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/canvas_inline_pdf/plugin/override_file_preview.rb', line 36 def before(controller) # Do nothing unless this setting is true. return unless enabled? context = controller.instance_variable_get(:@context) file = context..not_deleted.find_by(id: controller.params[:file_id]) # Continue to the FilePreviewsController#show action. return unless file.present? return unless allowed?(controller, file) return unless CanvasInlinePdf.previewable?(nil, file) # Per Canvas: mark item seen for module progression purposes mark_seen(controller, file) verifier = controller.params[:verifier] fallback_url = controller.send( :context_url, context, :context_file_download_url, file.id, download_frd: 1, verifier: verifier ) file_url = controller.send( :safe_domain_file_url, file, fallback_url: fallback_url, verifier: verifier ) # Ideally we would update FilePreviewController in instructure/canvas to # call this if it can be rendered inline. # controller.send(:render, layout: false, template: template, locals: { file_url: file_url }) controller.send(:redirect_to, file_url) end |