Skip to content

Commit

Permalink
fix a2 student bug & only do one submission query
Browse files Browse the repository at this point in the history
this fixes the bug I just introduced to a2 student view but it also
fixes our code to use the same query result we already were querying
the db for instead of issuing a new query for the submission

and it also fixes a bug where if the student didn’t have permission
to :read_own_submission or :read_grades (read their own grades)
that they would still get shown the submission

test plan:
* as a student, go to courses/x/assignmets/y
* you should be able to see the part where you submit the assignment

Change-Id: Iba155bcf3b841ddaf94d3bcb450fbdddd8fbd99f
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/218336
Tested-by: Service Cloud Jenkins <[email protected]>
Tested-by: Jenkins
QA-Review: Matthew Lemon <[email protected]>
Reviewed-by: Ryan Norton <[email protected]>
Reviewed-by: Matthew Lemon <[email protected]>
Product-Review: Ryan Shaw <[email protected]>
  • Loading branch information
ryankshaw committed Nov 22, 2019
1 parent caa23cb commit 9961219
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ def show
end
end

submission_to_use_for_graphql = nil
can_read_submissions = @assignment.grants_right?(@current_user, session, :read_own_submission) && @context.grants_right?(@current_user, session, :read_grades)
if can_read_submissions
@current_user_submission = @assignment.submissions.where(user_id: @current_user).first if @current_user
@current_user_submission = nil if @current_user_submission &&
!@current_user_submission.graded? &&
!@current_user_submission.submission_type
submission_to_use_for_graphql = @current_user_submission = @assignment.submissions.where(user_id: @current_user).first if @current_user
@current_user_submission = nil if @current_user_submission && !@current_user_submission.graded? && !@current_user_submission.submission_type
if @current_user_submission
Shackles.activate(:master) do
@current_user_submission.send_later(:context_module_action)
Expand Down Expand Up @@ -168,9 +167,9 @@ def show
})

if @assignment.a2_enabled? && !can_do(@context, @current_user, :read_as_admin) && (!params.key?(:assignments_2) || value_to_boolean(params[:assignments_2]))
submission = @assignment.submissions.find_by(user: @current_user)
graphql_submisison_id = @current_user_submission && CanvasSchema.id_from_object(@current_user_submission, CanvasSchema.resolve_type(submission, nil), nil)
js_env(SUBMISSION_ID: graphql_submisison_id)
if submission_to_use_for_graphql
js_env(SUBMISSION_ID: CanvasSchema.id_from_object(submission_to_use_for_graphql, CanvasSchema.resolve_type(submission_to_use_for_graphql, nil), nil))
end
css_bundle :assignments_2_student
js_bundle :assignments_2_show_student
render html: '', layout: true
Expand Down

0 comments on commit 9961219

Please sign in to comment.