pass user role to DocViewer

Pass the role of a user (Teacher, Student, TA) to DocViewer. This role
should only be passed when annotations are enabled.

closes GRADE-1219

Test Plan
- Create an assignment that takes doc files (or any DocViewer file).
- Submit an assignment as a student.

- Put a debugger statement before the redirect_to in
canvadoc_sessions_controller#show.
- Navigate to SpeedGrader.
- In the console after the debugger is tripped, verify that the opts
hash contains enrollment_type with value 'teacher'.

- Navigate to Submission Details of that submission as a student.
- Click View Feedback.
- In the console after the debugger is tripped, verify that the opts
hash contains enrollment_type with value 'student'.

Change-Id: I51c5cf60f90a73143c2f270126ef259426111632
Reviewed-on: https://gerrit.instructure.com/152836
Reviewed-by: Keith T. Garner <kgarner@instructure.com>
Tested-by: Jenkins
Reviewed-by: Neil Gupta <ngupta@instructure.com>
QA-Review: James Butters <jbutters@instructure.com>
Product-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
Gary Mei 2018-06-05 13:06:17 -05:00
parent e924133cb8
commit 48c917fcd5
8 changed files with 69 additions and 3 deletions

View File

@ -40,6 +40,7 @@ class CanvadocSessionsController < ApplicationController
opts[:enable_annotations] = blob["enable_annotations"] && !anonymous_grading_enabled?(attachment)
opts[:anonymous_instructor_annotations] = blob["anonymous_instructor_annotations"]
opts[:enrollment_type] = blob["enrollment_type"]
# TODO: Remove the next line after the DocViewer Data Migration project RD-4702
opts[:region] = attachment.shard.database_server.config[:region] || "none"
attachment.submit_to_canvadocs(1, opts) unless attachment.canvadoc_available?

View File

@ -20,6 +20,7 @@ module Submissions
class PreviewsBaseController < ApplicationController
include KalturaHelper
include Submissions::ShowHelper
include CoursesHelper
before_action :require_context
@ -29,6 +30,7 @@ module Submissions
@assignment = @submission_for_show.assignment
@user = @submission_for_show.user
@submission = @submission_for_show.submission
@enrollment_type = user_type(@context, @current_user)
prepare_js_env

View File

@ -21,9 +21,11 @@ module AttachmentHelper
def doc_preview_attributes(attachment, attrs={})
url_opts = {
anonymous_instructor_annotations: attrs.delete(:anonymous_instructor_annotations),
moderated_grading_whitelist: attrs[:moderated_grading_whitelist],
enable_annotations: attrs.delete(:enable_annotations)
enable_annotations: attrs.delete(:enable_annotations),
moderated_grading_whitelist: attrs[:moderated_grading_whitelist]
}
url_opts[:enrollment_type] = attrs.delete(:enrollment_type) if url_opts[:enable_annotations]
if attachment.crocodoc_available?
begin
attrs[:crocodoc_session_url] = attachment.crocodoc_url(@current_user, url_opts)

View File

@ -108,6 +108,11 @@ module CoursesHelper
cr[:count] == 0 && cr[:workflow_state] == 'inactive'
end
def user_type(course, user)
enrollment = course.enrollments.find_by(user: user)
enrollment.type.downcase.remove(/enrollment/) unless enrollment.nil?
end
def why_cant_i_enable_master_course(course)
return nil if MasterCourses::MasterTemplate.is_master_course?(course)

View File

@ -18,6 +18,7 @@
class Assignment
class SpeedGrader
include GradebookSettingsHelpers
include CoursesHelper
def initialize(assignment, user, avatars: false, grading_role: :grader)
@assignment = assignment
@ -197,6 +198,10 @@ class Assignment
moderated_grading_whitelist: moderated_grading_whitelist
}
if url_opts[:enable_annotations]
url_opts[:enrollment_type] = user_type(@course, @user)
end
if json['submission_history'] && (@assignment.quiz.nil? || too_many)
json['submission_history'] = json['submission_history'].map do |version|
# to avoid a call to the DB in Submission#missing?

View File

@ -204,7 +204,26 @@
%>
<% end %>
<% if attachment.crocodoc_available? || attachment.canvadocable? %>
<a href=<%= preview_url %> data-tooltip title="<%= preview_document %>" class="modal_preview_link Button--link" role="button" data-attachment_id="<%= attachment.id %>" data-submission_id="<%= @submission.id %>" data-dialog-title="<%= attachment.display_name %>" <%= doc_preview_attributes(attachment, anonymous_instructor_annotations: @anonymous_instructor_annotations, enable_annotations: true, moderated_grading_whitelist: @moderated_grading_whitelist) %>><%= button_text %></a>
<a
href=<%= preview_url %>
data-tooltip title="<%= preview_document %>"
class="modal_preview_link Button--link"
role="button"
data-attachment_id="<%= attachment.id %>"
data-submission_id="<%= @submission.id %>"
data-dialog-title="<%= attachment.display_name %>"
<%=
doc_preview_attributes(
attachment,
anonymous_instructor_annotations: @anonymous_instructor_annotations,
enable_annotations: true,
enrollment_type: @enrollment_type,
moderated_grading_whitelist: @moderated_grading_whitelist
)
%>
>
<%= button_text %>
</a>
<% end %>
</div>

View File

@ -52,6 +52,13 @@ describe AttachmentHelper do
expect(attrs).to match "anonymous_instructor_annotations%22:true"
end
it "includes enrollment_type in canvadoc url when annotations are enabled" do
@current_user = @teacher
allow(@att).to receive(:canvadocable?).and_return(true)
attrs = doc_preview_attributes(@att, { enable_annotations: true, enrollment_type: "teacher" })
expect(attrs).to match "enrollment_type%22:%22teacher"
end
describe "set_cache_header" do
it "should not allow caching of instfs redirects" do
allow(@att).to receive(:instfs_hosted?).and_return(true)

View File

@ -305,6 +305,31 @@ describe Assignment::SpeedGrader do
expect(canvadoc_url.include?("anonymous_instructor_annotations%22:true")).to eq true
end
it "passes enrollment type to DocViewer" do
course = student_in_course(active_all: true).course
assignment = assignment_model(course: course)
attachment = attachment_model(
context: @student,
uploaded_data: stub_png_data,
filename: "homework.png"
)
topic = course.discussion_topics.create!(assignment: assignment)
entry = topic.reply_from(user: @student, text: "entry")
entry.attachment = attachment
entry.save!
topic.ensure_submission(@student)
expect(Canvadocs).to receive(:enabled?).twice.and_return(true)
expect(Canvadocs).to receive(:config).and_return({ a: 1 })
expect(Canvadoc).to receive(:mime_types).and_return("image/png")
json = Assignment::SpeedGrader.new(assignment, @teacher).json
sub = json[:submissions].first[:submission_history].first[:submission]
canvadoc_url = sub[:versioned_attachments].first.fetch(:attachment).fetch(:canvadoc_url)
expect(canvadoc_url.include?("enrollment_type%22:%22teacher%22")).to eq true
end
it "includes submission missing status in each submission history version" do
json = Assignment::SpeedGrader.new(@assignment, @teacher).json
json[:submissions].each do |submission|