@@ -9,7 +9,8 @@ class AssignmentsController < MainApiController
:student_form_groups, :remark_due_date, :remark_message,
:assign_graders_to_criteria, :enable_test, :allow_remarks,
:display_grader_names_to_students, :group_name_autogenerated,
:marking_scheme_type, :repository_folder,:is_hidden]
:marking_scheme_type, :repository_folder, :is_hidden,
:vcs_submit]

# Returns a list of assignments and their attributes
# Optional: filter, fields
@@ -35,7 +35,8 @@ class AssignmentsController < ApplicationController
:allow_web_submits, :student_form_groups, :remark_due_date,
:remark_message, :assign_graders_to_criteria, :enable_test,
:allow_remarks, :display_grader_names_to_students,
:group_name_autogenerated, :marking_scheme_type, :is_hidden]
:group_name_autogenerated, :marking_scheme_type, :is_hidden,
:vcs_submit]

# Publicly accessible actions ---------------------------------------

@@ -506,16 +507,15 @@ def download_assignment_list
output = map.to_yaml
format = 'text/yml'
when 'csv'
output = CSV.generate do |csv|
assignments.map do |ass|
array = []
DEFAULT_FIELDS.map do |f|
array << ass.send(f.to_s)
end
csv << array
file_out = MarkusCSV.generate(assignments) do |assignment|
DEFAULT_FIELDS.map do |f|
assignment.send(f.to_s)
end
end
format = 'text/csv'
send_data(file_out,
type: 'text/csv', disposition: 'inline',
filename: 'assignment_list.csv')
return
else
flash[:error] = t(:incorrect_format)
redirect_to action: 'index'
@@ -541,22 +541,22 @@ def upload_assignment_list

case params[:file_format]
when 'csv'
begin
CSV.parse(assignment_list) do |row|
map = {}
row.length.times do |i|
map[DEFAULT_FIELDS[i]] = row[i]
end
map.delete(nil)
update_assignment!(map)
errors = MarkusCSV.parse(assignment_list) do |row|
assignment = Assignment.find_or_create_by(short_identifier: row[0])
attrs = Hash[DEFAULT_FIELDS.zip(row)]
attrs.delete_if { |_, v| v.nil? }
if assignment.new_record?
assignment.submission_rule = NoLateSubmissionRule.new
assignment.assignment_stat = AssignmentStat.new
end
assignment.update(attrs)
if assignment.valid?
flash_message(:success, t('assignment.create_success'))
else
raise CSVInvalidLineError
end
rescue ArgumentError
flash[:error] = I18n.t('csv.upload.non_text_file_with_csv_extension')
rescue ActiveRecord::ActiveRecordError => e
flash[:error] = e.message
redirect_to action: 'index'
return
end
flash_message(:error, errors) unless errors.empty?
when 'yml'
begin
map = YAML::load(assignment_list)
@@ -74,6 +74,7 @@ class Assignment < ActiveRecord::Base
validates_presence_of :notes_count
# "validates_presence_of" for boolean values.
validates_inclusion_of :allow_web_submits, in: [true, false]
validates_inclusion_of :vcs_submit, in: [true, false]
validates_inclusion_of :display_grader_names_to_students, in: [true, false]
validates_inclusion_of :is_hidden, in: [true, false]
validates_inclusion_of :enable_test, in: [true, false]
@@ -0,0 +1,9 @@
class AddDefaultToVcsSubmit < ActiveRecord::Migration
def up
change_column_default :assignments, :vcs_submit, :false
end

def down
change_column_default :assignments, :vcs_submit, :nil
end
end
@@ -0,0 +1,10 @@
class AddDefaultToDisplayGraderNames < ActiveRecord::Migration
def up
change_column_default :assignments, :display_grader_names_to_students,
:false
end

def down
change_column_default :assignments, :display_grader_names_to_students, :nil
end
end
@@ -68,6 +68,7 @@
marking_scheme_type {'rubric'}
submission_rule {NoLateSubmissionRule.make}
allow_web_submits {true}
vcs_submit { false }
display_grader_names_to_students {false}
section_due_dates_type(false)
enable_test {true}
@@ -546,7 +546,7 @@ def teardown
:file_format => 'csv'
assert_response :redirect
assert_redirected_to(:controller => 'assignments', :action => 'index')
assert_equal flash[:success], I18n.t('assignment.create_success')
assert_equal flash[:success], [I18n.t('assignment.create_success')]
assert_equal flash[:error], nil
test1 = Assignment.find_by_short_identifier('ATest1')
assert_not_nil test1
@@ -598,7 +598,7 @@ def teardown

assert_response :redirect
assert_equal flash[:error],
I18n.t('csv.upload.non_text_file_with_csv_extension')
[I18n.t('csv.upload.non_text_file_with_csv_extension')]
end
end