add filter for current assignments to GradebookExporter
fixes CNVS-22054 Test plan: 1. Create a course with assignments in past grading periods, future grading periods, current grading periods, and assignments without due dates. 2. Export the gradebook from that course. 3. Confirm that assignments in the current grading period are exported. 4. Confirm that assignments without due dates are exported. 5. Confirm that assignments in past grading periods are NOT exported. 6. Confirm that assignments in future grading periods are NOT exported. Change-Id: Ie2dde8673196d53fc7d7fd41ae3d833b4ab50cd9 Reviewed-on: https://gerrit.instructure.com/59804 Tested-by: Jenkins Reviewed-by: Keith T. Garner <kgarner@instructure.com> QA-Review: Jason Carter <jcarter@instructure.com> Product-Review: Strand McCutchen <smccutchen@instructure.com>
This commit is contained in:
parent
8bdf173cb1
commit
32229423db
|
@ -17,6 +17,8 @@
|
|||
#
|
||||
|
||||
class GradebookExporter
|
||||
include GradebookTransformer
|
||||
|
||||
def initialize(course, options = {})
|
||||
@course = course
|
||||
@options = options
|
||||
|
@ -39,23 +41,14 @@ class GradebookExporter
|
|||
submissions = {}
|
||||
calc.submissions.each { |s| submissions[[s.user_id, s.assignment_id]] = s }
|
||||
|
||||
assignments = calc.assignments.sort_by do |a|
|
||||
assignments = select_in_current_grading_periods calc.assignments, @course
|
||||
|
||||
assignments = assignments.sort_by do |a|
|
||||
[a.assignment_group_id, a.position, a.due_at || CanvasSort::Last, a.title]
|
||||
end
|
||||
groups = calc.groups
|
||||
|
||||
read_only = I18n.t('csv.read_only_field', '(read only)')
|
||||
I18n.t 'csv.student', 'Student'
|
||||
I18n.t 'csv.id', 'ID'
|
||||
I18n.t 'csv.sis_user_id', 'SIS User ID'
|
||||
I18n.t 'csv.sis_login_id', 'SIS Login ID'
|
||||
I18n.t 'csv.root_account', 'Root Account'
|
||||
I18n.t 'csv.section', 'Section'
|
||||
I18n.t 'csv.comments', 'Comments'
|
||||
I18n.t 'csv.current_score', 'Current Score'
|
||||
I18n.t 'csv.final_score', 'Final Score'
|
||||
I18n.t 'csv.final_grade', 'Final Grade'
|
||||
I18n.t 'csv.points_possible', 'Points Possible'
|
||||
include_root_account = @course.root_account.trust_exists?
|
||||
CSV.generate do |csv|
|
||||
# First row
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
require 'csv'
|
||||
|
||||
class GradebookImporter
|
||||
include GradebookTransformer
|
||||
|
||||
class NegativeId
|
||||
class << self
|
||||
|
@ -100,7 +101,9 @@ class GradebookImporter
|
|||
process_submissions(row, @students.last)
|
||||
end
|
||||
|
||||
@assignments = select_in_current_grading_periods @assignments
|
||||
memo = @assignments
|
||||
@assignments = select_in_current_grading_periods @assignments, @context
|
||||
@assignments_outside_current_periods = memo - @assignments
|
||||
|
||||
@missing_assignments = []
|
||||
@missing_assignments = @all_assignments.values - @assignments if @missing_assignment
|
||||
|
@ -172,7 +175,6 @@ class GradebookImporter
|
|||
end
|
||||
|
||||
def process_header(csv)
|
||||
|
||||
row = csv.shift
|
||||
raise "Couldn't find header row" unless header?(row)
|
||||
|
||||
|
@ -190,25 +192,6 @@ class GradebookImporter
|
|||
true
|
||||
end
|
||||
|
||||
def select_in_current_grading_periods(assignments)
|
||||
if @context.feature_enabled?(:multiple_grading_periods)
|
||||
assignments, assignments_without_due_at = assignments.partition(&:due_at)
|
||||
current_periods = GradingPeriod.for(@context).active.current
|
||||
|
||||
current, outside = assignments.partition do |assignment|
|
||||
current_periods.any? do |period|
|
||||
period.in_date_range? assignment.due_at
|
||||
end
|
||||
end
|
||||
|
||||
@assignments_outside_current_periods = outside
|
||||
current + assignments_without_due_at
|
||||
else
|
||||
@assignments_outside_current_periods = []
|
||||
assignments
|
||||
end
|
||||
end
|
||||
|
||||
def last_student_info_column(row)
|
||||
row[@student_columns - 1]
|
||||
end
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#
|
||||
# Copyright (C) 2015 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
module GradebookTransformer
|
||||
private
|
||||
def select_in_current_grading_periods(assignments, course)
|
||||
if course.feature_enabled?(:multiple_grading_periods)
|
||||
assignments, assignments_without_due_at = assignments.partition(&:due_at)
|
||||
current_periods = GradingPeriod.for(course).active.current
|
||||
|
||||
current = assignments.select do |assignment|
|
||||
current_periods.any? { |p| p.in_date_range? assignment.due_at }
|
||||
end
|
||||
|
||||
current + assignments_without_due_at
|
||||
else
|
||||
assignments
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,140 @@
|
|||
#
|
||||
# Copyright (C) 2015 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
||||
|
||||
require 'csv'
|
||||
|
||||
describe GradebookExporter do
|
||||
describe ".initialize" do
|
||||
it "raises an error without a course argument" do
|
||||
expect { subject.new }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_csv" do
|
||||
let(:course) { Course.create }
|
||||
describe "default output with blank course" do
|
||||
let(:exporter) { GradebookExporter.new(course) }
|
||||
subject(:csv) { exporter.to_csv }
|
||||
|
||||
it "produces a String" do
|
||||
expect(subject).to be_a String
|
||||
end
|
||||
|
||||
it "is a csv with two rows" do
|
||||
expect(CSV.parse(subject).count).to be 2
|
||||
end
|
||||
|
||||
it "is a csv with seven columns" do
|
||||
expect(CSV.parse(subject).transpose.count).to be 7
|
||||
end
|
||||
|
||||
describe "default headers order" do
|
||||
let(:headers) { CSV.parse(subject, headers: true).headers }
|
||||
|
||||
it("first column") { expect(headers[0]).to eq "Student" }
|
||||
it("second column") { expect(headers[1]).to eq "ID" }
|
||||
it("third column") { expect(headers[2]).to eq "Section" }
|
||||
it("fourth column") { expect(headers[3]).to eq "Current Points" }
|
||||
it("fifth column") { expect(headers[4]).to eq "Final Points" }
|
||||
it("sixth column") { expect(headers[5]).to eq "Current Score" }
|
||||
it("seventh column") { expect(headers[6]).to eq "Final Score" }
|
||||
end
|
||||
end
|
||||
|
||||
context "a course has assignments with due dates" do
|
||||
let(:assignments) { course.assignments }
|
||||
|
||||
let!(:no_due_date_assignment) { assignments.create title: "no due date" }
|
||||
let!(:past_assignment) do
|
||||
assignments.create due_at: 5.weeks.ago, title: "past"
|
||||
end
|
||||
|
||||
let!(:current_assignment) do
|
||||
assignments.create due_at: 1.weeks.from_now, title: "current"
|
||||
end
|
||||
|
||||
let!(:future_assignment) do
|
||||
assignments.create due_at: 8.weeks.from_now, title: "future"
|
||||
end
|
||||
|
||||
let(:csv) { GradebookExporter.new(course).to_csv }
|
||||
let(:headers) { CSV.parse(csv, headers: true).headers }
|
||||
|
||||
describe "when multiple grading periods is on" do
|
||||
describe "only current assignments are exported" do
|
||||
let!(:enable_mgp) do
|
||||
course.enable_feature!(:multiple_grading_periods)
|
||||
end
|
||||
|
||||
let!(:period) do
|
||||
group = course.grading_period_groups.create!
|
||||
args = {
|
||||
start_date: 3.weeks.ago,
|
||||
end_date: 3.weeks.from_now,
|
||||
title: "present day, present time"
|
||||
}
|
||||
|
||||
group.grading_periods.create! args
|
||||
end
|
||||
|
||||
it "exports current assignments" do
|
||||
expect(headers).to include no_due_date_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "exports assignments without due dates" do
|
||||
expect(headers).to include current_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "does not export past assignments" do
|
||||
expect(headers).to_not include past_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "does not export future assignments" do
|
||||
expect(headers).to_not include future_assignment.title_with_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when multiple grading periods is off" do
|
||||
describe "all assignments are exported" do
|
||||
let!(:disable_mgp) do
|
||||
course.disable_feature!(:multiple_grading_periods)
|
||||
end
|
||||
|
||||
it "exports current assignments" do
|
||||
expect(headers).to include no_due_date_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "exports assignments without due dates" do
|
||||
expect(headers).to include current_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "exports past assignments" do
|
||||
expect(headers).to include past_assignment.title_with_id
|
||||
end
|
||||
|
||||
it "exports future assignments" do
|
||||
expect(headers).to include future_assignment.title_with_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue