@@ -2621,4 +2621,221 @@ def course_with_student_and_submitted_homework
26212621 action : 'mark_submission_unread' , controller : 'submissions_api' , format : 'json' } )
26222622 expect ( @submission . reload . read? ( @teacher ) ) . to be_falsey
26232623 end
2624+
2625+ context 'bulk update' do
2626+ before :each do
2627+ @student1 = user ( :active_all => true )
2628+ @student2 = user ( :active_all => true )
2629+ course_with_teacher ( :active_all => true )
2630+ @default_section = @course . default_section
2631+ @section = @course . course_sections . create! ( :name => "section2" )
2632+ @course . enroll_user ( @student1 , 'StudentEnrollment' , :section => @section ) . accept!
2633+ @course . enroll_user ( @student2 , 'StudentEnrollment' ) . accept!
2634+ @a1 = @course . assignments . create! ( { :title => 'assignment1' , :grading_type => 'percent' , :points_possible => 10 } )
2635+ end
2636+
2637+ it "should queue bulk update through courses" do
2638+ grade_data = {
2639+ :grade_data => {
2640+ @student1 . id => { :posted_grade => '75%' } ,
2641+ @student2 . id => { :posted_grade => '95%' }
2642+ }
2643+ }
2644+
2645+ json = api_call ( :post ,
2646+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2647+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2648+ :format => 'json' , :course_id => @course . id . to_s ,
2649+ :assignment_id => @a1 . id . to_s } , grade_data )
2650+
2651+ run_jobs
2652+ progress = Progress . find ( json [ "id" ] )
2653+ expect ( progress . completed? ) . to be_truthy
2654+
2655+ expect ( Submission . count ) . to eq 2
2656+ s1 = @student1 . submissions . first
2657+ expect ( s1 . grade ) . to eq "75%"
2658+ s2 = @student2 . submissions . first
2659+ expect ( s2 . grade ) . to eq "95%"
2660+ end
2661+
2662+ it "should find users through sis api ids" do
2663+ student3 = user_with_pseudonym ( :active_all => true )
2664+ student3 . pseudonym . update_attribute ( :sis_user_id , 'my-student-id' )
2665+ @course . enroll_user ( student3 , 'StudentEnrollment' ) . accept!
2666+
2667+ grade_data = {
2668+ :grade_data => {
2669+ 'sis_user_id:my-student-id' => { :posted_grade => '75%' }
2670+ }
2671+ }
2672+
2673+ @user = @teacher
2674+ json = api_call ( :post ,
2675+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2676+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2677+ :format => 'json' , :course_id => @course . id . to_s ,
2678+ :assignment_id => @a1 . id . to_s } , grade_data )
2679+
2680+ run_jobs
2681+ progress = Progress . find ( json [ "id" ] )
2682+ expect ( progress . completed? ) . to be_truthy
2683+
2684+ expect ( Submission . count ) . to eq 1
2685+ s1 = student3 . submissions . first
2686+ expect ( s1 . grade ) . to eq "75%"
2687+ end
2688+
2689+ it "should restrict with differentiated assignments" do
2690+ @a1 . only_visible_to_overrides = true
2691+ @a1 . save!
2692+ create_section_override_for_assignment ( @a1 , course_section : @section )
2693+ @course . enable_feature! ( :differentiated_assignments )
2694+
2695+ student3 = user_with_pseudonym ( :active_all => true )
2696+ student3 . pseudonym . update_attribute ( :sis_user_id , 'my-student-id' )
2697+ @course . enroll_user ( student3 , 'StudentEnrollment' ) . accept!
2698+
2699+ grade_data = {
2700+ :grade_data => {
2701+ @student1 . id => { :posted_grade => '75%' } ,
2702+ @student2 . id => { :posted_grade => '95%' } ,
2703+ 'sis_user_id:my-student-id' => { :posted_grade => '85%' } ,
2704+ }
2705+ }
2706+
2707+ @user = @teacher
2708+ json = api_call ( :post ,
2709+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2710+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2711+ :format => 'json' , :course_id => @course . id . to_s ,
2712+ :assignment_id => @a1 . id . to_s } , grade_data )
2713+
2714+ run_jobs
2715+ progress = Progress . find ( json [ "id" ] )
2716+ expect ( progress . failed? ) . to be_truthy
2717+ expect ( progress . message ) . to eq "Couldn't find User(s) with API ids '#{ @student2 . id } ', 'sis_user_id:my-student-id'"
2718+
2719+ @course . disable_feature! ( :differentiated_assignments )
2720+ json = api_call ( :post ,
2721+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2722+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2723+ :format => 'json' , :course_id => @course . id . to_s ,
2724+ :assignment_id => @a1 . id . to_s } , grade_data )
2725+
2726+ run_jobs
2727+ progress = Progress . find ( json [ "id" ] )
2728+ expect ( progress . completed? ) . to be_truthy
2729+
2730+ expect ( Submission . count ) . to eq 3
2731+ s1 = @student1 . submissions . first
2732+ expect ( s1 . grade ) . to eq "75%"
2733+ s2 = @student2 . submissions . first
2734+ expect ( s2 . grade ) . to eq "95%"
2735+ s3 = student3 . submissions . first
2736+ expect ( s3 . grade ) . to eq "85%"
2737+ end
2738+
2739+ it "should queue bulk update through sections" do
2740+ grade_data = {
2741+ :grade_data => {
2742+ @student1 . id => { :posted_grade => '75%' }
2743+ }
2744+ }
2745+
2746+ json = api_call ( :post ,
2747+ "/api/v1/sections/#{ @section . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2748+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2749+ :format => 'json' , :section_id => @section . id . to_s ,
2750+ :assignment_id => @a1 . id . to_s } , grade_data )
2751+
2752+ run_jobs
2753+ progress = Progress . find ( json [ "id" ] )
2754+ expect ( progress . completed? ) . to be_truthy
2755+
2756+ expect ( Submission . count ) . to eq 1
2757+ s1 = @student1 . submissions . first
2758+ expect ( s1 . grade ) . to eq "75%"
2759+ end
2760+
2761+ it "should allow bulk grading with rubric assessments" do
2762+ rubric = rubric_model ( :user => @user , :context => @course , :data => larger_rubric_data )
2763+ @a1 . create_rubric_association ( :rubric => rubric , :purpose => 'grading' , :use_for_grading => true , :context => @course )
2764+
2765+ grade_data = {
2766+ :grade_data => {
2767+ @student1 . id => { :posted_grade => '75%' } ,
2768+ @student2 . id => {
2769+ :rubric_assessment => {
2770+ :crit1 => { :points => 7 } ,
2771+ :crit2 => { :points => 2 , :comments => 'Rock on' }
2772+ }
2773+ }
2774+ }
2775+ }
2776+
2777+ json = api_call ( :post ,
2778+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2779+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2780+ :format => 'json' , :course_id => @course . id . to_s ,
2781+ :assignment_id => @a1 . id . to_s } , grade_data )
2782+
2783+ run_jobs
2784+ progress = Progress . find ( json [ "id" ] )
2785+ expect ( progress . completed? ) . to be_truthy
2786+
2787+ expect ( Submission . count ) . to eq 2
2788+ s1 = @student1 . submissions . first
2789+ expect ( s1 . grade ) . to eq "75%"
2790+ s2 = @student2 . submissions . first
2791+ expect ( s2 . rubric_assessment ) . not_to be_nil
2792+ expect ( s2 . rubric_assessment . data ) . to eq (
2793+ [ { :description => "B" ,
2794+ :criterion_id => "crit1" ,
2795+ :comments_enabled => true ,
2796+ :points => 7 ,
2797+ :learning_outcome_id => nil ,
2798+ :id => "rat2" ,
2799+ :comments => nil } ,
2800+ { :description => "Pass" ,
2801+ :criterion_id => "crit2" ,
2802+ :comments_enabled => true ,
2803+ :points => 2 ,
2804+ :learning_outcome_id => nil ,
2805+ :id => "rat1" ,
2806+ :comments => "Rock on" ,
2807+ :comments_html => "Rock on" } ]
2808+ )
2809+ end
2810+
2811+ it "should require authorization" do
2812+ @user = @student1
2813+ raw_api_call ( :post ,
2814+ "/api/v1/courses/#{ @course . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2815+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2816+ :format => 'json' , :course_id => @course . id . to_s ,
2817+ :assignment_id => @a1 . id . to_s } , { } )
2818+ assert_status ( 401 )
2819+ end
2820+
2821+ it "should check user ids for sections" do
2822+ grade_data = {
2823+ :grade_data => {
2824+ @student1 . id => { :posted_grade => '75%' } ,
2825+ @student2 . id => { :posted_grade => '95%' }
2826+ }
2827+ }
2828+
2829+ json = api_call ( :post ,
2830+ "/api/v1/sections/#{ @section . id } /assignments/#{ @a1 . id } /submissions/update_grades" ,
2831+ { :controller => 'submissions_api' , :action => 'bulk_update' ,
2832+ :format => 'json' , :section_id => @section . id . to_s ,
2833+ :assignment_id => @a1 . id . to_s } , grade_data )
2834+
2835+ run_jobs
2836+ progress = Progress . find ( json [ "id" ] )
2837+ expect ( progress . failed? ) . to be_truthy
2838+ expect ( progress . message ) . to eq "Couldn't find User(s) with API ids '#{ @student2 . id } '"
2839+ end
2840+ end
26242841end
0 commit comments