return lock explanation message from preview

test plan:
 - have a file that is conditionally unlocked (either by date,
   or by being part of a module that has unmet completion requirements)
 - try to preview the file as a student, using New Files
 - you should see a lock explanation instead of a canvasception 401
   "Unauthorized" error page

refs CNVS-16943

Change-Id: I22a081a1946aa9a82dee3c8b287f5454c226c00b
Reviewed-on: https://gerrit.instructure.com/44943
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2014-11-25 16:34:48 -07:00
parent 80ba61a258
commit 38ba224687
3 changed files with 28 additions and 2 deletions

View File

@ -55,7 +55,11 @@ class FilePreviewsController < ApplicationController
@show_left_side = false
return render template: 'shared/errors/404_message', status: :not_found
end
if authorized_action(@file, @current_user, :download)
if authorized_action(@file, @current_user, :read)
unless @file.grants_right?(@current_user, :download)
@lock_info = @file.locked_for?(@current_user)
return render template: 'file_previews/lock_explanation', layout: false
end
# mark item seen for module progression purposes
@file.context_module_action(@current_user, :read) if @current_user
@file.record_inline_view

View File

@ -0,0 +1,15 @@
<% content_for :head, include_common_stylesheets %>
<%= render :partial => "layouts/head" %>
<body>
<div id="content" class="file_preview_container">
<h2><%= @file.display_name %></h2>
<div>
<% if @file.folder && @file.folder.locked? %>
<%= t 'messages.folder_locked', "The folder \"%{folder},\" which includes this file, has been locked.", :folder => @file.folder.name %>
<% else %>
<%= @lock_info.is_a?(Hash) ? lock_explanation(@lock_info, 'file', @context) : t('messages.file_locked', "This file has not been unlocked yet.") %>
<% end %>
</div>
</div>
<%= render :partial => 'layouts/foot', :locals => { :include_common_bundle => true } %>
</body>

View File

@ -30,11 +30,18 @@ describe FilePreviewsController do
end
it "should require authorization to view the file" do
attachment_model locked: true
course_model
attachment_model
get :show, course_id: @course.id, file_id: @attachment.id
expect(response.status).to eq 401
end
it "should render lock information for the file" do
attachment_model locked: true
get :show, course_id: @course.id, file_id: @attachment.id
expect(response).to render_template 'lock_explanation'
end
it "should 404 (w/o canvas chrome) if the file doesn't exist" do
attachment_model
file_id = @attachment.id