Skip to content

Commit

Permalink
add grade_by_question_enabled query param
Browse files Browse the repository at this point in the history
closes EVAL-2726
flag=new_quizzes_grade_by_question_in_speedgrader

Test Plan:
1. Enable the SiteAdmin feature flag
   "Quizzes.Next Grade by Question in SpeedGrader".
2. Create a Quizzes.Next quiz, submit as a student, and
   go to SpeedGrader as the teacher.
3. Verify that the iframe URL that Quizzes.Next launches
   with includes a `grade_by_question_enabled` query param.

Change-Id: I7f3ca092e4a030069b5f2c65026d6b0ee3287287
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/304222
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Eduardo Escobar <[email protected]>
Reviewed-by: Christopher Soto <[email protected]>
QA-Review: Kai Bjorkman <[email protected]>
Product-Review: Spencer Olson <[email protected]>
  • Loading branch information
spencerolson committed Nov 17, 2022
1 parent 5adbbdc commit eea7173
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/controllers/gradebooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ def speed_grader
log_asset_access(["speed_grader", @context], "grades", "other")
env = {
SINGLE_NQ_SESSION_ENABLED: Account.site_admin.feature_enabled?(:single_new_quiz_session_in_speedgrader),
NQ_GRADE_BY_QUESTION_ENABLED: Account.site_admin.feature_enabled?(:new_quizzes_grade_by_question_in_speedgrader),
GRADE_BY_QUESTION: !!@current_user.preferences[:enable_speedgrader_grade_by_question],
EMOJIS_ENABLED: @context.feature_enabled?(:submission_comment_emojis),
EMOJI_DENY_LIST: @context.root_account.settings[:emoji_deny_list],
MANAGE_GRADES: @context.grants_right?(@current_user, session, :manage_grades),
Expand Down
1 change: 1 addition & 0 deletions app/models/speed_grader/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def json
end

res[:GROUP_GRADING_MODE] = assignment.grade_as_group?
res[:quiz_lti] = assignment.quiz_lti?
StringifyIds.recursively_stringify_ids(res)
ensure
Attachment.skip_thumbnails = nil
Expand Down
26 changes: 23 additions & 3 deletions spec/javascripts/jsx/speed_graderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ QUnit.module('SpeedGrader', rootHooks => {

test('contains iframe with the escaped student submission url', () => {
let retrieveUrl = '/course/1/external_tools/retrieve?display=borderless&assignment_id=22'
const url = 'www.example.com/lti/launch/user/4'
const url = 'http://www.example.com/lti/launch/user/4'
const buildIframeStub = sinon.stub(SpeedGraderHelpers, 'buildIframe')
const submission = {
external_tool_url: url,
Expand All @@ -1399,10 +1399,30 @@ QUnit.module('SpeedGrader', rootHooks => {
buildIframeStub.restore()
})

test('includes the grade_by_question query param when a new quiz and flag + setting are enabled', () => {
ENV.NQ_GRADE_BY_QUESTION_ENABLED = true
ENV.GRADE_BY_QUESTION = true
const originalJsonData = window.jsonData
window.jsonData = {quiz_lti: true}
const retrieveUrl = '/course/1/external_tools/retrieve?display=borderless&assignment_id=22'
const url = 'http://www.example.com/lti/launch/user/4'
const buildIframeStub = sinon.stub(SpeedGraderHelpers, 'buildIframe')
const submission = {
external_tool_url: url,
resource_link_lookup_uuid: '0b8fbc86-fdd7-4950-852d-ffa789b37ff2',
}
SpeedGrader.EG.renderLtiLaunch($div, retrieveUrl, submission)
const [srcUrl] = buildIframeStub.firstCall.args
const {searchParams} = new URL(decodeURIComponent(unescape(srcUrl).match(/http.*/)[0]))
strictEqual(searchParams.get('grade_by_question_enabled'), 'true')
buildIframeStub.restore()
window.jsonData = originalJsonData
})

test('can be fullscreened', () => {
const retrieveUrl =
'canvas.com/course/1/external_tools/retrieve?display=borderless&assignment_id=22'
const url = 'www.example.com/lti/launch/user/4'
const url = 'http://www.example.com/lti/launch/user/4'
const buildIframeStub = sinon.stub(SpeedGraderHelpers, 'buildIframe')
const submission = {
url,
Expand All @@ -1417,7 +1437,7 @@ QUnit.module('SpeedGrader', rootHooks => {
test('allows options defined in iframeAllowances()', () => {
const retrieveUrl =
'canvas.com/course/1/external_tools/retrieve?display=borderless&assignment_id=22'
const url = 'www.example.com/lti/launch/user/4'
const url = 'http://www.example.com/lti/launch/user/4'
const buildIframeStub = sinon.stub(SpeedGraderHelpers, 'buildIframe')
const submission = {
url,
Expand Down
8 changes: 7 additions & 1 deletion ui/features/speed_grader/jquery/speed_grader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2809,7 +2809,13 @@ EG = {
},

renderLtiLaunch($div, urlBase, submission) {
const externalToolUrl = submission.external_tool_url || submission.url
let externalToolUrl = submission.external_tool_url || submission.url

if (ENV.NQ_GRADE_BY_QUESTION_ENABLED && window.jsonData.quiz_lti && externalToolUrl) {
const quizToolUrl = new URL(externalToolUrl)
quizToolUrl.searchParams.set('grade_by_question_enabled', String(ENV.GRADE_BY_QUESTION))
externalToolUrl = quizToolUrl.href
}

urlBase += SpeedgraderHelpers.resourceLinkLookupUuidParam(submission)

Expand Down

0 comments on commit eea7173

Please sign in to comment.