Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Diff from RB for issue 705
diff --git a/test/functional/api/users_controller_test.rb b/test/functional/api/users_controller_test.rb
--- a/test/functional/api/users_controller_test.rb
+++ b/test/functional/api/users_controller_test.rb
@@ -26,7 +26,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "/show" do
setup do
- get "show", :id => 1
+ get "show", :id => "garbage"
end
should "fail to authenticate the GET request" do
@@ -46,7 +46,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "/update" do
setup do
- put 'update', :id => 1
+ put 'update', :id => "garbage"
end
should "fail to authenticate the GET request" do
@@ -56,7 +56,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "/destroy" do
setup do
- delete "destroy", :id => 1
+ delete "destroy", :id => "garbage"
end
should "fail to authenticate the GET request" do
@@ -85,7 +85,7 @@ class Api::UsersControllerTest < ActionController::TestCase
# Create dummy user to display
@user = Student.make
# fire off request, after setup has been called again, reseting API key.
- get "show", :id => 1, :user_name => @user.user_name
+ get "show", :id => @user.user_name
assert_response :success
assert @response.body.include?(@user.user_name)
assert @response.body.include?(@user.type)
@@ -144,7 +144,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "testing the show function with a user that does not exist" do
setup do
- get "show", :id => 1, :user_name => "garbage fake user "
+ get "show", :id => "garbage fake user "
end
should "fail to find the user, 'garbage fake name'" do
@@ -159,8 +159,7 @@ class Api::UsersControllerTest < ActionController::TestCase
@attr = {:user_name => "ApiTestUser", :last_name => "Tester",
:first_name => "Api", :user_type =>"admin" }
# fire off request
- post "create", :id => 1, :user_name => "ApiTestUser", :last_name => "Tester",
- :first_name => "Api", :user_type =>"admin"
+ post "create", @attr
end
should "create the new user specified" do
@@ -207,25 +206,23 @@ class Api::UsersControllerTest < ActionController::TestCase
:last_name => "TesterChanged",
:first_name => "UpdatedApi"}
put "update",
- :id => 1,
- :user_name => @user.user_name,
+ :id => @user.user_name,
:last_name => "TesterChanged",
:first_name => "UpdatedApi"
end
should "and a new, non-existing user name" do
- @new_attr[:new_user_name] = "apitestuser2"
+ @new_attr[:user_name] = "apitestuser2"
put "update",
- :id => 1,
- :user_name => @user.user_name,
- :new_user_name => 'apitestuser2',
+ :id => @user.user_name,
+ :user_name => 'apitestuser2',
:last_name => "TesterChanged",
:first_name => "UpdatedApi"
# Try to find old user_name
assert User.find_by_user_name(@user.user_name).nil?
# Find user by new user_name
- @updated_user2 = User.find_by_user_name(@new_attr[:new_user_name])
+ @updated_user2 = User.find_by_user_name(@new_attr[:user_name])
assert !@updated_user2.nil?
assert_equal(@updated_user2.last_name, @new_attr[:last_name])
assert_equal(@updated_user2.first_name, @new_attr[:first_name])
@@ -241,7 +238,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "testing the update function with a user_name that does not exist" do
setup do
- put "update", :id => 1, :user_name => "garbage", :last_name => "garbage",
+ put "update", :id => "garbage", :last_name => "garbage",
:first_name => "garbage"
end
@@ -256,10 +253,10 @@ class Api::UsersControllerTest < ActionController::TestCase
@user_to_update = Student.make
@existing_user = Student.make
# fire off request
- put "update", :id => 1, :user_name => @user_to_update.user_name,
+ put "update", :id => @user_to_update.user_name,
:last_name => "garbage",
:first_name => "garbage",
- :new_user_name => @existing_user.user_name
+ :user_name => @existing_user.user_name
end
should "find the new user_name as existing and cause conflict" do
@@ -269,7 +266,7 @@ class Api::UsersControllerTest < ActionController::TestCase
context "testing the destory function is disabled" do
setup do
- delete "destroy", :id => 1
+ delete "destroy", :id => "garbage"
end
should "pretend the function doesn't exist" do
diff --git a/test/functional/api/test_results_controller_test.rb b/test/functional/api/test_results_controller_test.rb
--- a/test/functional/api/test_results_controller_test.rb
+++ b/test/functional/api/test_results_controller_test.rb
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
require 'shoulda'
require 'base64'
-# Tests the test results handlers (create, destroy, update, show)
+# Tests the test results handlers (create, destroy, update, index)
class Api::TestResultsControllerTest < ActionController::TestCase
fixtures :all
@@ -22,7 +22,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
a_short_identifier = assignment.short_identifier
filename = @test_result.filename
# fire off request
- @res = get("show", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = get("index", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => filename})
end
@@ -35,7 +35,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
context "getting a text response" do
setup do
@request.env['HTTP_ACCEPT'] = 'text/plain'
- get "show", :id => "garbage"
+ get "index", :group_id => "garbage", :assignment_id => "garbage"
end
should "be successful" do
@@ -47,7 +47,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
context "getting a json response" do
setup do
@request.env['HTTP_ACCEPT'] = 'application/json'
- get "show", :id => "garbage"
+ get "index", :group_id => "garbage", :assignment_id => "garbage"
end
should "be successful" do
@@ -59,7 +59,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
context "getting an xml response" do
setup do
@request.env['HTTP_ACCEPT'] = 'application/xml'
- get "show", :id => "garbage"
+ get "index", :group_id => "garbage", :assignment_id => "garbage"
end
should "be successful" do
@@ -71,7 +71,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
context "getting an rss response" do
setup do
@request.env['HTTP_ACCEPT'] = 'application/rss'
- get "show", :id => "garbage"
+ get "index", :group_id => "garbage", :assignment_id => "garbage"
end
should "not be successful" do
@@ -101,7 +101,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
test_results = @submission.test_results # returns Array
@test_results_count_pre_post = test_results.length
# fire off request
- @res = post("create", {:group_name => group_name, :assignment => a_short_identifier,
+ @res = post("create", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => @filename, :file_content => @file_content})
end
@@ -140,7 +140,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
test_results = @submission.test_results # returns Array
@test_results_count_pre_post = test_results.length
@to_be_deleted_test_result = "example.rb"
- @res = delete("destroy", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = delete("destroy", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => @to_be_deleted_test_result})
end
@@ -176,7 +176,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
group_name = group.group_name
a_short_identifier = assignment.short_identifier
grouping = group.grouping_for_assignment(assignment.id)
- @res = put("update", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = put("update", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => @filename, :file_content => @file_content})
end
@@ -198,8 +198,13 @@ class Api::TestResultsControllerTest < ActionController::TestCase
auth_http_header = "MarkUsAuth #{base_encoded_md5}"
@request.env['HTTP_AUTHORIZATION'] = auth_http_header
@request.env['HTTP_ACCEPT'] = 'text/plain'
+ # get parameters from fixtures
+ group = groups(:group_test_result1)
+ assignment = assignments(:assignment_test_result1)
+ group_name = group.group_name
+ a_short_identifier = assignment.short_identifier
# parameters
- @res = get("show", {:id => 1, :filename => "some_filename"})
+ @res = get("index", {:group_id => group_name, :assignment_id => a_short_identifier})
end
should assign_to :current_user
@@ -217,7 +222,12 @@ class Api::TestResultsControllerTest < ActionController::TestCase
auth_http_header = "MarkUsAuth #{base_encoded_md5}"
@request.env['HTTP_ACCEPT'] = 'text/plain'
@request.env['HTTP_AUTHORIZATION'] = auth_http_header
- @res = post("create", {:filename => "some_filename"})
+ # get parameters from fixtures
+ group = groups(:group_test_result1)
+ assignment = assignments(:assignment_test_result1)
+ group_name = group.group_name
+ a_short_identifier = assignment.short_identifier
+ @res = post("create", {:group_id => group_name, :assignment_id => a_short_identifier, :filename => "some_filename"})
end
should assign_to :current_user
@@ -235,7 +245,12 @@ class Api::TestResultsControllerTest < ActionController::TestCase
auth_http_header = "MarkUsAuth #{base_encoded_md5}"
@request.env['HTTP_AUTHORIZATION'] = auth_http_header
@request.env['HTTP_ACCEPT'] = 'text/plain'
- @res = put("update", {:id => 1, :filename => "some_filename"})
+ # get parameters from fixtures
+ group = groups(:group_test_result1)
+ assignment = assignments(:assignment_test_result1)
+ group_name = group.group_name
+ a_short_identifier = assignment.short_identifier
+ @res = put("update", {:group_id => group_name, :assignment_id => a_short_identifier, :filename => "some_filename"})
end
should assign_to :current_user
@@ -253,7 +268,12 @@ class Api::TestResultsControllerTest < ActionController::TestCase
auth_http_header = "MarkUsAuth #{base_encoded_md5}"
@request.env['HTTP_AUTHORIZATION'] = auth_http_header
@request.env['HTTP_ACCEPT'] = 'text/plain'
- @res = delete("destroy", {:id => 1, :filename => "somefilename"})
+ # get parameters from fixtures
+ group = groups(:group_test_result1)
+ assignment = assignments(:assignment_test_result1)
+ group_name = group.group_name
+ a_short_identifier = assignment.short_identifier
+ @res = delete("destroy", {:group_id => group_name, :assignment_id => a_short_identifier})
end
should assign_to :current_user
@@ -276,7 +296,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
assignment = assignments(:assignment_test_result1)
group_name = group.group_name
a_short_identifier = assignment.short_identifier
- @res = delete("destroy", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = delete("destroy", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => "does_not_exist"})
end
@@ -300,7 +320,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
assignment = assignments(:assignment_test_result1)
group_name = group.group_name
a_short_identifier = assignment.short_identifier
- @res = get("show", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = get("index", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => "does_not_exist"})
end
@@ -324,7 +344,7 @@ class Api::TestResultsControllerTest < ActionController::TestCase
assignment = assignments(:assignment_test_result1)
group_name = group.group_name
a_short_identifier = assignment.short_identifier
- @res = put("update", {:id => 1, :group_name => group_name, :assignment => a_short_identifier,
+ @res = put("update", {:group_id => group_name, :assignment_id => a_short_identifier,
:filename => "does_not_exist", :file_content => "irrelevant"})
end
diff --git a/public/stylesheets/grader.css b/public/stylesheets/grader.css
--- a/public/stylesheets/grader.css
+++ b/public/stylesheets/grader.css
@@ -176,7 +176,7 @@ li.annotation_category {
width: 4px;
margin: 0 2px 10px 2px;
height: 722px;
- background-color: DDDDDD;
+ background-color: #DDDDDD;
cursor: col-resize;
}
@@ -306,7 +306,6 @@ li.annotation_category {
width:13px;
background-image:url("/stylesheets/window_close.gif");
cursor:pointer;
- cursor:hand;
}
/* Annotation summary list styles */
diff --git a/test/functional/api/assignments_api_controller_test.rb b/test/functional/api/assignments_api_controller_test.rb
--- /dev/null
+++ b/test/functional/api/assignments_api_controller_test.rb
@@ -0,0 +1,289 @@
+require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'blueprints', 'blueprints')
+require File.join(File.dirname(__FILE__), '..', '..', 'blueprints', 'helper')
+require 'shoulda'
+require 'base64'
+
+class Api::AssignmentsApiControllerTest < ActionController::TestCase
+
+ # Testing Unauthenticated requests
+ context "An unauthenticated request to api/assignments" do
+ setup do
+ # Set garbage HTTP header
+ @request.env['HTTP_AUTHORIZATION'] = "garbage http_header"
+ @request.env['HTTP_ACCEPT'] = 'text/plain'
+ end
+
+ context "/index" do
+ setup do
+ get "index"
+ end
+
+ should "fail to authenticate the GET request" do
+ assert_response 403
+ end
+ end
+
+ context "/show" do
+ setup do
+ get "show", :id => "garbage"
+ end
+
+ should "fail to authenticate the GET request" do
+ assert_response 403
+ end
+ end
+
+ context "/create" do
+ setup do
+ @res_create = post("create")
+ end
+
+ should "fail to authenticate the GET request" do
+ assert_response 403
+ end
+ end
+
+ context "/update" do
+ setup do
+ put 'update', :id => "garbage"
+ end
+
+ should "fail to authenticate the GET request" do
+ assert_response 403
+ end
+ end
+
+ context "/destroy" do
+ setup do
+ delete "destroy", :id => "garbage"
+ end
+
+ should "fail to authenticate the GET request" do
+ assert_response 403
+ end
+ end
+ end
+
+ # Testing authenticated requests
+ context "An authenticated request to api/assignments" do
+ setup do
+ # Fixtures have manipulated the DB, clear them off.
+ clear_fixtures
+
+ # Creates admin from blueprints.
+ @admin = Admin.make
+ @admin.reset_api_key
+ base_encoded_md5 = @admin.api_key.strip
+ auth_http_header = "MarkUsAuth #{base_encoded_md5}"
+ @request.env['HTTP_AUTHORIZATION'] = auth_http_header
+ @request.env['HTTP_ACCEPT'] = 'text/plain'
+ end
+
+ # Testing GET
+ should "testing the show function with an assignment that exists" do
+ # Create dummy assignment to display
+ @assignment = Assignment.make
+ # fire off request, after setup has been called again, reseting API key.
+ get "show", :id => @assignment.short_identifier
+ assert_response :success
+ assert @response.body.include?(@assignment.short_identifier)
+ assert @response.body.include?(@assignment.due_date.to_s)
+ assert @response.body.include?(@assignment.marking_scheme_type)
+ assert @response.body.include?(@assignment.allow_web_submits.to_s)
+ assert @response.body.include?(@assignment.display_grader_names_to_students.to_s)
+ assert @response.body.include?(@assignment.enable_test.to_s)
+ assert @response.body.include?(@assignment.assign_graders_to_criteria.to_s)
+ assert @response.body.include?(@assignment.submission_rule.type)
+ end
+
+ context "testing the show function with an assignment that does not exist" do
+ setup do
+ get "show", :id => "garbage fake assignment"
+ end
+
+ should "fail to find the assignment, 'garbage fake name'" do
+ assert_response 404
+ end
+ end
+
+ # Testing POST
+ context "testing the create function with valid but minimal attributes" do
+ setup do
+ # Create paramters for request
+ @attr = { :short_identifier => "ApiTestAssignment", :due_date => "2012-03-26 18:04:39" }
+ # fire off request
+ post "create", @attr
+ end
+
+ should "create the new assignment specified" do
+ assert_response :success
+ @new_assignment = Assignment.find_by_short_identifier(@attr[:short_identifier])
+ assert !@new_assignment.nil?
+ assert_equal(@new_assignment.short_identifier, @attr[:short_identifier])
+ assert_equal(@new_assignment.due_date, Time.zone.parse(@attr[:due_date]))
+ assert_equal(@new_assignment.repository_folder, @attr[:short_identifier])
+ end
+ end
+
+ context "testing the create function with all attributes" do
+ setup do
+ # Create paramters for request
+ @attr = { :short_identifier => "ApiTestAssignment", :due_date => "2012-03-26 18:04:39",
+ :repository_folder => "TestFolder", :group_min => 2, :group_max => 3,
+ :tokens_per_day => 13, :submission_rule_type => "PenaltyDecayPeriod",
+ :marking_scheme_type => "flexible", :allow_web_submits => false,
+ :display_grader_names_to_students => true, :enable_test => true,
+ :assign_graders_to_criteria => true, :description => "Test Description",
+ :message => "Test Message", :allow_remarks => false, :remark_due_date => "2012-03-26 18:04:39",
+ :remark_message => "Test Remark Message", :student_form_groups => true,
+ :group_name_autogenerated => false, :submission_rule_deduction => 10,
+ :submission_rule_hours => 11, :submission_rule_interval => 12}
+ # fire off request
+ post "create", @attr
+ end
+
+ should "create the new assignment specified" do
+ assert_response :success
+ @new_assignment = Assignment.find_by_short_identifier(@attr[:short_identifier])
+ assert !@new_assignment.nil?
+ assert_equal(@new_assignment.short_identifier, @attr[:short_identifier])
+ assert_equal(@new_assignment.due_date, Time.zone.parse(@attr[:due_date]))
+ assert_equal(@new_assignment.repository_folder, @attr[:repository_folder])
+ assert_equal(@new_assignment.group_min, @attr[:group_min])
+ assert_equal(@new_assignment.group_max, @attr[:group_max])
+ assert_equal(@new_assignment.tokens_per_day, @attr[:tokens_per_day])
+ assert_equal(@new_assignment.submission_rule.type, PenaltyDecayPeriodSubmissionRule.to_s)
+ assert_equal(@new_assignment.marking_scheme_type, @attr[:marking_scheme_type])
+ assert_equal(@new_assignment.allow_web_submits, @attr[:allow_web_submits])
+ assert_equal(@new_assignment.display_grader_names_to_students, @attr[:display_grader_names_to_students])
+ assert_equal(@new_assignment.enable_test, @attr[:enable_test])
+ assert_equal(@new_assignment.assign_graders_to_criteria, @attr[:assign_graders_to_criteria])
+ assert_equal(@new_assignment.description, @attr[:description])
+ assert_equal(@new_assignment.message, @attr[:message])
+ assert_equal(@new_assignment.allow_remarks, @attr[:allow_remarks])
+ assert_equal(@new_assignment.remark_message, @attr[:remark_message])
+ assert_equal(@new_assignment.student_form_groups, @attr[:student_form_groups])
+ assert_equal(@new_assignment.remark_due_date, Time.zone.parse(@attr[:remark_due_date]))
+ assert_equal(@new_assignment.group_name_autogenerated, @attr[:group_name_autogenerated])
+ assert_equal(@new_assignment.submission_rule.periods.first.deduction, @attr[:submission_rule_deduction])
+ assert_equal(@new_assignment.submission_rule.periods.first.hours, @attr[:submission_rule_hours])
+ assert_equal(@new_assignment.submission_rule.periods.first.interval, @attr[:submission_rule_interval])
+ end
+ end
+
+ context "testing the create function with an existing short_identifier to cause error" do
+ setup do
+ @assignment = Assignment.make
+ @attr = {:short_identifier => @assignment.short_identifier, :due_date => "2012-03-26 18:04:39"}
+ @res = post("create", @attr)
+ end
+
+ should "find an existing assignment and cause conflict" do
+ assert !Assignment.find_by_short_identifier(@attr[:short_identifier]).nil?
+ assert_response :conflict
+ end
+ end
+
+ context "testing the create function with due_date set to garbage" do
+ setup do
+ @attr = {:short_identifier => "ApiTestAssignment", :due_date => "garbage"}
+ @res = post("create", @attr)
+ end
+
+ should "not be saved properly" do
+ assert_response 500
+ end
+ end
+
+ context "testing the create function with submission_rule_type set to garbage" do
+ setup do
+ @attr = {:short_identifier => "ApiTestAssignment", :due_date => "2012-03-26 18:04:39",
+ :submission_rule_type => "garbage"}
+ @res = post("create", @attr)
+ end
+
+ should "give a 422 response" do
+ assert_response 422
+ end
+ end
+
+ # Testing PUT
+ context "testing the update function with a new due_date and short_identifier" do
+ setup do
+ @assignment = Assignment.make
+ @new_attr = {:short_identifier => "ApiTestAssignment", :due_date => "2012-03-26 18:04:39"}
+
+ put "update", :id => @assignment.short_identifier,
+ :due_date => @new_attr[:due_date], :short_identifier => @new_attr[:short_identifier]
+ end
+
+ should "update the short_idenfier and due_date" do
+ @updated_assignment = Assignment.find_by_short_identifier(@new_attr[:short_identifier])
+ assert !@updated_assignment.nil?
+ assert_equal(@updated_assignment.due_date, Time.zone.parse(@new_attr[:due_date]))
+ assert_equal(@updated_assignment.short_identifier, @new_attr[:short_identifier])
+ end
+ end
+
+ context "testing the update function with a new submission_rule_type" do
+ setup do
+ @assignment = Assignment.make
+ @new_attr = {:submission_rule_type => "PenaltyDecayPeriod", :submission_rule_hours => 10,
+ :submission_rule_interval => 11, :submission_rule_deduction => 12}
+
+ put "update", :id => @assignment.short_identifier,
+ :submission_rule_type => @new_attr[:submission_rule_type],
+ :submission_rule_hours => @new_attr[:submission_rule_hours],
+ :submission_rule_interval => @new_attr[:submission_rule_interval],
+ :submission_rule_deduction => @new_attr[:submission_rule_deduction]
+ end
+
+ should "update the short_idenfier and due_date" do
+ @updated_assignment = Assignment.find_by_short_identifier(@assignment.short_identifier)
+ assert !@updated_assignment.nil?
+ assert_equal(@updated_assignment.submission_rule.type, PenaltyDecayPeriodSubmissionRule.to_s)
+ assert_equal(@updated_assignment.submission_rule.periods.first.hours, @new_attr[:submission_rule_hours])
+ assert_equal(@updated_assignment.submission_rule.periods.first.interval, @new_attr[:submission_rule_interval])
+ assert_equal(@updated_assignment.submission_rule.periods.first.deduction, @new_attr[:submission_rule_deduction])
+ end
+ end
+
+ context "testing the update function with a short_identifier that does not exist" do
+ setup do
+ put "update", :id => "garbage",
+ :due_date => "garbage"
+ end
+
+ should "not be able to find the short_identifier to update" do
+ assert Assignment.find_by_short_identifier("garbage").nil?
+ assert_response 404
+ end
+ end
+
+ context "testing the update function with a short_identifier that already exists" do
+ setup do
+ @assignment_to_update = Assignment.make
+ @existing_assignment = Assignment.make
+ # fire off request
+ put "update", :id => @assignment_to_update.short_identifier,
+ :short_identifier => @existing_assignment.short_identifier,
+ :due_date => "2012-03-26 18:04:39"
+ end
+
+ should "find the new short_identifier as existing and cause conflict" do
+ assert_response 409
+ end
+ end
+
+ context "testing the destory function is disabled" do
+ setup do
+ delete "destroy", :id => "garbage"
+ end
+
+ should "pretend the function doesn't exist" do
+ assert_response :missing
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb
--- a/app/controllers/api/users_controller.rb
+++ b/app/controllers/api/users_controller.rb
@@ -1,10 +1,10 @@
module Api
#=== Description
- # Allows for adding, modifying and showing users into MarkUs.
+ # Allows for adding, modifying and showing users for MarkUs.
# Uses Rails' RESTful routes (check 'rake routes' for the configured routes)
class UsersController < MainApiController
- # Requires user_name, user_type, last_name, first_name, [section_name], [grace_credits]
+ # Accepts: user_name, user_type, last_name, first_name, [section_name], [grace_credits]
def create
if has_missing_params?(params)
# incomplete/invalid HTTP params
@@ -19,7 +19,7 @@ module Api
return
end
- # No user found so create new one
+ # No user found so create a new one
param_user_type = params[:user_type].downcase
if param_user_type == "student"
user_type = Student
@@ -38,43 +38,38 @@ module Api
new_user = user_type.new(attributes)
if !new_user.save
# Some error occurred
- render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] }, :status => 500
+ render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] +
+ ": " + new_user.errors.full_messages.join(", ") }, :status => 500
return
end
- # Otherwise everything went alright.
+ # Otherwise everything went well
render 'shared/http_status', :locals => { :code => "200", :message => HttpStatusHelper::ERROR_CODE["message"]["200"] }, :status => 200
end
- # Requires nothing, does nothing
+ # Accepts: nothing
def destroy
# Admins should not be deleting users at all so pretend this URL does not exist
render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
end
- # Requires user_name, [first_name], [last_name], [new_user_name], [section_name], [grace_credits]
+ # Accepts: [first_name], [last_name], [user_name], [section_name], [grace_credits]
def update
- if params[:user_name].blank?
- # incomplete/invalid HTTP params
- render 'shared/http_status', :locals => { :code => "422", :message => HttpStatusHelper::ERROR_CODE["message"]["422"] }, :status => 422
- return
- end
-
# If no user is found, render an error.
- user = User.find_by_user_name(params[:user_name])
+ user = User.find_by_user_name(params[:id])
if user.nil?
render 'shared/http_status', :locals => { :code => "404", :message => "User was not found" }, :status => 404
return
end
- updated_user_name = params[:user_name]
- if !params[:new_user_name].blank?
+ updated_user_name = params[:id]
+ if !params[:user_name].blank?
# Make sure new user_name does not exist
- if !User.find_by_user_name(params[:new_user_name]).nil?
- render 'shared/http_status', :locals => { :code => "409", :message => "User already exists" }, :status => 409
+ if !User.find_by_user_name(params[:user_name]).nil?
+ render 'shared/http_status', :locals => { :code => "409", :message => "A user already exists with the specified user_name" }, :status => 409
return
end
- updated_user_name = params[:new_user_name]
+ updated_user_name = params[:user_name]
end
attributes={:user_name => updated_user_name}
@@ -83,16 +78,16 @@ module Api
user.attributes = attributes
if !user.save
# Some error occurred
- render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] }, :status => 500
+ render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] +
+ ": " + user.errors.full_messages.join(", ") }, :status => 500
return
end
- # Otherwise everything went alright.
+ # Otherwise everything went well
render 'shared/http_status', :locals => { :code => "200", :message => HttpStatusHelper::ERROR_CODE["message"]["200"] }, :status => 200
- return
end
- # Requires nothing
+ # Accepts: nothing
def index
users = User.all
@@ -103,16 +98,16 @@ module Api
end
end
- # Requires user_name
+ # Accepts: id ( user name )
def show
- if params[:user_name].blank?
+ if params[:id].blank?
# incomplete/invalid HTTP params
render 'shared/http_status', :locals => { :code => "422", :message => "Missing user name" }, :status => 422
return
end
# check if there's a valid user.
- user = User.find_by_user_name(params[:user_name])
+ user = User.find_by_user_name(params[:id])
if user.nil?
# no such user
render 'shared/http_status', :locals => { :code => "404", :message => "User was not found" }, :status => 404
@@ -128,22 +123,22 @@ module Api
end
private
-
+
# Get the plain text representation for users
def get_plain_text_for_users(users)
data=""
-
+
users.each do |user|
data += t('user.user_name') + ": " + user.user_name + "\n" +
t('user.user_type') + ": " + user.type + "\n" +
t('user.first_name') + ": " + user.first_name + "\n" +
t('user.last_name') + ": " + user.last_name + "\n\n"
end
-
+
return data
end
-
- # Process the parameters passed
+
+ # Process the parameters passed during a POST/PUT request
def process_attributes(params, attributes)
# allow the user to provide the section name instead of an id which is meaningless
# thus we have to retrieve the id here
@@ -170,7 +165,7 @@ module Api
return attributes
end
- # Checks user_name, first_name, last_name, user_type.
+ # Checks id ( user's name ), first_name, last_name, user_type.
def has_missing_params?(params)
return params[:user_name].blank? || params[:user_type].blank? ||
params[:first_name].blank? || params[:last_name].blank?
diff --git a/config/routes.rb b/config/routes.rb
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,11 +6,23 @@ Markus::Application.routes.draw do
# Install the default routes as the lowest priority.
root :controller => "main", :action => "login"
- # API routes
+ # API routes
namespace :api, :defaults => { :format => 'text' } do
- resources :test_results, :except => [:new, :edit]
- resources :submission_downloads, :except => [:new, :edit]
- resources :users, :except => [:new, :edit]
+
+ resources :assignments, :controller => "assignments_api", :except => [:new, :edit] do
+ resources :groups, :controller => "groups_api", :except => [:new, :edit] do
+ resources :test_results, :except => [:new, :edit, :show] do
+ collection do
+ delete :destroy
+ put :update
+ end
+ end
+ resources :submission_downloads, :except => [:new, :edit, :show, :destroy, :create, :update]
+ end
+
+ end
+
+ resources :users, :except => [:new, :edit]
resources :main_api
end
diff --git a/app/controllers/api/groups_api_controller.rb b/app/controllers/api/groups_api_controller.rb
--- /dev/null
+++ b/app/controllers/api/groups_api_controller.rb
@@ -0,0 +1,30 @@
+module Api
+
+ #=== Description
+ # TODO: write a description
+ # Uses Rails' RESTful routes (check 'rake routes' for the configured routes)
+ class GroupsApiController < MainApiController
+ # TODO: WRITE ME!!!
+
+ def create
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ def destroy
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ def update
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ def index
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ def show
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ end # end GroupsApiController
+end
\ No newline at end of file
diff --git a/app/controllers/api/submission_downloads_controller.rb b/app/controllers/api/submission_downloads_controller.rb
--- a/app/controllers/api/submission_downloads_controller.rb
+++ b/app/controllers/api/submission_downloads_controller.rb
@@ -10,14 +10,14 @@ module Api
# Triggered by a HTTP GET request to /api/submission_downloads(.:format)
# Downloads a SubmissionFile, possibly with annotations.
# Requires the following parameters:
- # group_name: Name of the group that submitten the file
+ # group_id: Name of the group that submitted the file
# assignment: Assignment for which the file was submitted
- # Allows the following optional paramenters:
+ # Allows the following optional parameters:
# filename: Name of the file, if absent all files will be downloaded
# include_annotations: If 'true', will include annotations in the file(s)
#=== Returns
# The requested file, or a zip file containing all requested files
- def show
+ def index
if !has_required_http_params?(params)
# incomplete/invalid HTTP params
render 'shared/http_status', :locals => { :code => "422", :message => HttpStatusHelper::ERROR_CODE["message"]["422"] }, :status => 422
@@ -25,8 +25,8 @@ module Api
end
# check if there's a valid submission
- submission = Submission.get_submission_by_group_and_assignment(params[:group_name],
- params[:assignment])
+ submission = Submission.get_submission_by_group_and_assignment(params[:group_id],
+ params[:assignment_id])
if submission.nil?
# no such submission
@@ -80,7 +80,7 @@ module Api
#Send the zip file
if !single_file
- send_file "tmp/submissions.zip", :disposition => 'inline', :filename => "#{params[:assignment]}_#{params[:group_name]}.zip"
+ send_file "tmp/submissions.zip", :disposition => 'inline', :filename => "#{params[:assignment_id]}_#{params[:group_id]}.zip"
end
end
@@ -91,8 +91,8 @@ module Api
# Note: The blank? method is a Rails extension.
# Specific keys have to be present, and their values
# must not be blank.
- if !param_hash[:assignment].blank? &&
- !param_hash[:group_name].blank?
+ if !param_hash[:assignment_id].blank? &&
+ !param_hash[:group_id].blank?
return true
else
return false
diff --git a/app/controllers/api/test_results_controller.rb b/app/controllers/api/test_results_controller.rb
--- a/app/controllers/api/test_results_controller.rb
+++ b/app/controllers/api/test_results_controller.rb
@@ -8,8 +8,8 @@ module Api
#=== Description
# Triggered by a HTTP POST request to /api/test_results(.:format).
# Creates a new TestResult instance. Requires the following parameters:
- # group_name: Name of the group to which the test result should be associated to
- # assignment: Short identifier of the assignment
+ # group_id: Name of the group to which the test result should be associated to
+ # assignment_id: Short identifier of the assignment
# filename: Filename of the test result
# file_content: Content of the test results
#=== Returns
@@ -21,8 +21,8 @@ module Api
return
end
# check if there's a valid submission
- submission = Submission.get_submission_by_group_and_assignment(params[:group_name],
- params[:assignment])
+ submission = Submission.get_submission_by_group_and_assignment(params[:group_id],
+ params[:assignment_id])
if submission.nil?
# no such submission
render 'shared/http_status', :locals => { :code => "404", :message => "Submission was not found" }, :status => 404
@@ -51,7 +51,8 @@ module Api
return
else
# Some other error occurred
- render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] }, :status => 500
+ render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] +
+ ": " + new_test_result.errors.full_messages.join(", ") }, :status => 500
return
end
end
@@ -60,8 +61,8 @@ module Api
#=== Description
# Triggered by a HTTP DELETE request to /api/test_results(.:format).
# Deletes a TestResult instance. Requires the following parameters:
- # group_name: Name of the group to which the test result should be associated to
- # assignment: Short identifier of the assignment
+ # group_id: Name of the group to which the test result should be associated to
+ # assignment_id: Short identifier of the assignment
# filename: Filename of the test result to be deleted
#=== Returns
# An XML response, indicating the success/failure for the request
@@ -72,8 +73,8 @@ module Api
return
end
# check if there's a valid submission
- submission = Submission.get_submission_by_group_and_assignment(params[:group_name],
- params[:assignment])
+ submission = Submission.get_submission_by_group_and_assignment(params[:group_id],
+ params[:assignment_id])
if submission.nil?
# no such submission
render 'shared/http_status', :locals => { :code => "404", :message => "Submission was not found" }, :status => 404
@@ -100,8 +101,8 @@ module Api
#=== Description
# Triggered by a HTTP PUT request to /api/test_results(.:format).
# Updates (overwrites) a TestResult instance. Requires the following parameters:
- # group_name: Name of the group to which the test result should be associated to
- # assignment: Short identifier of the assignment
+ # group_id: Name of the group to which the test result should be associated to
+ # assignment_id: Short identifier of the assignment
# filename: Filename of the test result, which content should be updated
# file_content: New content of the test result
#=== Returns
@@ -113,8 +114,8 @@ module Api
return
end
# check if there's a valid submission
- submission = Submission.get_submission_by_group_and_assignment(params[:group_name],
- params[:assignment])
+ submission = Submission.get_submission_by_group_and_assignment(params[:group_id],
+ params[:assignment_id])
if submission.nil?
# no such submission
render 'shared/http_status', :locals => { :code => "404", :message => "Submission was not found" }, :status => 404
@@ -141,20 +142,20 @@ module Api
#=== Description
# Triggered by a HTTP GET request to /api/test_results(.:format).
# Shows a TestResult instance. Requires the following parameters:
- # group_name: Name of the group to which the test result should be associated to
- # assignment: Short identifier of the assignment
+ # group_id: Name of the group to which the test result should be associated to
+ # assignment_id: Short identifier of the assignment
# filename: New filename of the test result
#=== Returns
# The content of the test result file in question
- def show
+ def index
if !has_required_http_params?(params)
# incomplete/invalid HTTP params
render 'shared/http_status', :locals => { :code => "422", :message => HttpStatusHelper::ERROR_CODE["message"]["422"] }, :status => 422
return
end
# check if there's a valid submission
- submission = Submission.get_submission_by_group_and_assignment(params[:group_name],
- params[:assignment])
+ submission = Submission.get_submission_by_group_and_assignment(params[:group_id],
+ params[:assignment_id])
if submission.nil?
# no such submission
render 'shared/http_status', :locals => { :code => "404", :message => "Submission was not found" }, :status => 404
@@ -181,9 +182,9 @@ module Api
# Specific keys have to be present, and their values
# must not be blank.
if !param_hash[:filename].blank? &&
- !param_hash[:assignment].blank? &&
- !param_hash[:group_name].blank?
- return true
+ !param_hash[:assignment_id].blank? &&
+ !param_hash[:group_id].blank?
+ return true
else
return false
end
diff --git a/app/controllers/api/assignments_api_controller.rb b/app/controllers/api/assignments_api_controller.rb
--- /dev/null
+++ b/app/controllers/api/assignments_api_controller.rb
@@ -0,0 +1,255 @@
+module Api
+ #=== Description
+ # Allows for adding, modifying and showing assignments for MarkUs.
+ # Uses Rails' RESTful routes (check 'rake routes' for the configured routes)
+ class AssignmentsApiController < MainApiController
+ # Accepts: short_identifier, due_date ( YYYY-MM-DD HH:MM ), [repository_folder] ( default: same as short_identifier ),
+ # [group_min] ( default: 1 ), [group_max] ( default: 1 ), [tokens_per_day] ( default: 0 ),
+ # [submission_rule_type] ( default: noLateSubmissionRule ), [marking_scheme_type] ( default: rubric ),
+ # [allow_web_submits] ( default: 1 ), [display_grader_names_to_students] ( default: 0 ),
+ # [enable_test] ( default: 0 ), [assign_graders_to_criteria] ( default: 0 )
+ # [description], [message], [allow_remarks] ( default: 1 ), [remark_due_date]
+ # [remark_message], [student_form_groups] ( default: 0 ),
+ # [group_name_autogenerated] ( default: 1 ), [submission_rule_deduction],
+ # [submission_rule_hours] ( REQUIRED if submission_rule_type is not noLateSubmissionRule ),
+ # [submission_rule_interval]
+ def create
+ if has_missing_params?(params)
+ # incomplete/invalid HTTP params
+ render 'shared/http_status', :locals => { :code => "422", :message => HttpStatusHelper::ERROR_CODE["message"]["422"] }, :status => 422
+ return
+ end
+
+ # check if there is an existing assignment
+ assignment = Assignment.find_by_short_identifier(params[:short_identifier])
+ if !assignment.nil?
+ render 'shared/http_status', :locals => { :code => "409", :message => "Assignment already exists" }, :status => 409
+ return
+ end
+
+ # no assignment found so create a new one
+ attributes = {:short_identifier => params[:short_identifier]}
+ attributes = process_attributes(params, attributes, true)
+
+ new_assignment = Assignment.new(attributes)
+ new_assignment.build_assignment_stat
+
+ @submission_rule = get_submission_rule(params)
+ # stop if we encountered an error while getting the submission_rule
+ if !@submission_rule
+ return
+ end
+ new_assignment.submission_rule = @submission_rule
+
+ if !new_assignment.save
+ # some error occurred
+ render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] +
+ ": " + new_assignment.errors.full_messages.join(", ")}, :status => 500
+ return
+ end
+
+ # otherwise everything went well
+ render 'shared/http_status', :locals => { :code => "200", :message => HttpStatusHelper::ERROR_CODE["message"]["200"] }, :status => 200
+ end
+
+ # Accepts: nothing
+ def destroy
+ # Admins should not be deleting assignments at all so pretend this URL does not exist
+ render 'shared/http_status', :locals => { :code => "404", :message => HttpStatusHelper::ERROR_CODE["message"]["404"] }, :status => 404
+ end
+
+ # Accepts: [short_identifier], [due_date] ( YYYY-MM-DD HH:MM ), [repository_folder] ( default: same as short_identifier ),
+ # [group_min] ( default: 1 ), [group_max] ( default: 1 ), [tokens_per_day] ( default: 0 ),
+ # [submission_rule_type] ( default: noLateSubmissionRule ), [marking_scheme_type] ( default: rubric ),
+ # [allow_web_submits] ( default: 1 ), [display_grader_names_to_students] ( default: 0 ),
+ # [enable_test] ( default: 0 ), [assign_graders_to_criteria] ( default: 0 )
+ # [description], [message], [allow_remarks] ( default: 1 ), [remark_due_date]
+ # [remark_message], [student_form_groups] ( default: 0 ),
+ # [group_name_autogenerated] ( default: 1 ), [submission_rule_deduction],
+ # [submission_rule_hours] ( REQUIRED if submission_rule_type is not noLateSubmissionRule ),
+ # [submission_rule_interval]
+ def update
+ # If no assignment is found, render an error.
+ assignment = Assignment.find_by_short_identifier(params[:id])
+ if assignment.nil?
+ render 'shared/http_status', :locals => { :code => "404", :message => "Assignment was not found" }, :status => 404
+ return
+ end
+
+ updated_short_identifier = params[:id]
+ if !params[:short_identifier].blank?
+ # Make sure new short_identifier does not exist
+ if !Assignment.find_by_short_identifier(params[:short_identifier]).nil?
+ render 'shared/http_status', :locals => { :code => "409", :message => "An assignment already exists with the specified short_identifier" }, :status => 409
+ return
+ end
+ updated_short_identifier = params[:short_identifier]
+ end
+
+ attributes = {:short_identifier => updated_short_identifier}
+ attributes = process_attributes(params, attributes, false)
+
+ # only update the submission_rule if we have to
+ if !params[:submission_rule_type].nil?
+ @submission_rule = get_submission_rule(params)
+ # stop if we encountered an error while getting the submission_rule
+ if !@submission_rule
+ return
+ end
+ end
+
+ assignment.attributes = attributes
+
+ # Only update the existing submission_rule if the new one exists, is valid
+ # and the assignment will save correctly with the current attributes
+ # This is to avoid deleting the submission_rule/periods for an existing
+ # assignment and then failing to create new ones
+ if assignment.valid? and !@submission_rule.nil? and @submission_rule.valid?
+ assignment.submission_rule.destroy
+ assignment.submission_rule = @submission_rule
+ end
+
+ if !assignment.save
+ # Some error occurred
+ render 'shared/http_status', :locals => { :code => "500", :message => HttpStatusHelper::ERROR_CODE["message"]["500"] +
+ ": " + assignment.errors.full_messages.join(", ") }, :status => 500
+ return
+ end
+
+ # Otherwise everything went well
+ render 'shared/http_status', :locals => { :code => "200", :message => HttpStatusHelper::ERROR_CODE["message"]["200"] }, :status => 200
+ end
+
+ # Accepts: nothing
+ def index
+ assignments = Assignment.all
+
+ respond_to do |format|
+ format.any{render :text => get_plain_text_for_assignments(assignments)}
+ format.json{render :json => assignments.to_json(:only => [ :short_identifier, :due_date,
+ :marking_scheme_type, :allow_web_submits, :display_grader_names_to_students, :type ], :include => :submission_rule)}
+ format.xml{render :xml => assignments.to_xml(:only => [ :short_identifier, :due_date,
+ :marking_scheme_type, :allow_web_submits, :display_grader_names_to_students, :type ], :include => :submission_rule)}
+ end
+ end
+
+ # Accepts: id ( short identifier )
+ def show
+ if params[:id].blank?
+ # incomplete/invalid HTTP params
+ render 'shared/http_status', :locals => { :code => "422", :message => "Missing short identifier name" }, :status => 422
+ return
+ end
+
+ # check if there's a valid assignment
+ assignment = Assignment.find_by_short_identifier(params[:id])
+ if assignment.nil?
+ # no such assignment
+ render 'shared/http_status', :locals => { :code => "404", :message => "Assignment was not found" }, :status => 404
+ return
+ end
+
+ # Everything went fine, send the response according to the user's format
+ respond_to do |format|
+ format.any{render :text => get_plain_text_for_assignments([assignment])}
+ format.json{render :json => assignment.to_json(:only => [ :short_identifier, :due_date,
+ :marking_scheme_type, :allow_web_submits, :display_grader_names_to_students,:enable_test,
+ :assign_graders_to_criteria, :type ], :include => :submission_rule)}
+ format.xml{render :xml => assignment.to_xml(:only => [ :short_identifier, :due_date,
+ :marking_scheme_type, :allow_web_submits, :display_grader_names_to_students,:enable_test,
+ :assign_graders_to_criteria, :type ], :include => :submission_rule)}
+ end
+ end
+
+ private
+
+ # get a submission_rule for an assignment based on params
+ def get_submission_rule(params)
+ # defaults to noLateSubmissionRule
+ if params[:submission_rule_type].nil? or params[:submission_rule_type] == "NoLate"
+ @submission_rule = NoLateSubmissionRule.new
+
+ elsif params[:submission_rule_type] == "GracePeriod"
+ @submission_rule = GracePeriodSubmissionRule.new
+ @submission_rule.periods.push( Period.new( :hours => params[:submission_rule_hours]))
+
+ elsif params[:submission_rule_type] == "PenaltyDecayPeriod"
+ @submission_rule = PenaltyDecayPeriodSubmissionRule.new
+ @submission_rule.periods.push( Period.new( :hours => params[:submission_rule_hours],
+ :deduction => params[:submission_rule_deduction], :interval => params[:submission_rule_interval]))
+
+ elsif params[:submission_rule_type] == "PenaltyPeriod"
+ @submission_rule = PenaltyPeriodSubmissionRule.new
+ @submission_rule.periods.push( Period.new( :hours => params[:submission_rule_hours], :deduction => params[:submission_rule_deduction]))
+
+ else
+ render 'shared/http_status', :locals => { :code => "422", :message => "Unrecognized submission_rule_type"}, :status => 422
+ @submission_rule = false
+ end
+
+ return @submission_rule
+ end
+
+ # Process the parameters passed during a POST/PUT request
+ def process_attributes(params, attributes, create)
+ attributes["due_date"] = params[:due_date] if !params[:due_date].nil?
+ attributes["group_max"] = params[:group_max] if !params[:group_max].nil?
+ attributes["tokens_per_day"] = params[:tokens_per_day] if !params[:tokens_per_day].nil?
+ attributes["description"] = params[:description] if !params[:description].nil?
+ attributes["message"] = params[:message] if !params[:message].nil?
+ attributes["allow_remarks"] = params[:allow_remarks] if !params[:allow_remarks].nil?
+ attributes["remark_due_date"] = params[:remark_due_date] if !params[:remark_due_date].nil?
+ attributes["remark_message"] = params[:remark_message] if !params[:remark_message].nil?
+ attributes["student_form_groups"] = params[:student_form_groups] if !params[:student_form_groups].nil?
+ attributes["group_name_autogenerated"] = params[:group_name_autogenerated] if !params[:group_name_autogenerated].nil?
+
+ # These attributes HAVE to be set when creating a new assignment for the model to save correctly, but
+ # have default values that are usually preset in the UI. They do need to be set when editing an existing
+ # assignment
+ if create
+ # these defaults should probably be consistent with the ones found in db/schema
+ attributes["allow_web_submits"] = params[:allow_web_submits].nil? ? 1 : params[:allow_web_submits]
+ attributes["display_grader_names_to_students"] = params[:display_grader_names_to_students].nil? ? 0 : params[:display_grader_names_to_students]
+ attributes["enable_test"] = params[:enable_test].nil? ? 0 : params[:enable_test]
+ attributes["assign_graders_to_criteria"] = params[:assign_graders_to_criteria].nil? ? 0 : params[:assign_graders_to_criteria]
+ attributes["repository_folder"] = params[:repository_folder].nil? ? attributes[:short_identifier] : params[:repository_folder]
+ attributes["group_min"] = params[:group_min].nil? ? 1 : params[:group_min]
+ attributes["marking_scheme_type"] = params[:marking_scheme_type].nil? ? "rubric" : params[:marking_scheme_type]
+ else
+ attributes["allow_web_submits"] = params[:allow_web_submits] if !params[:allow_web_submits].nil?
+ attributes["display_grader_names_to_students"] = params[:display_grader_names_to_students] if !params[:display_grader_names_to_students].nil?
+ attributes["enable_test"] = params[:enable_test] if !params[:enable_test].nil?
+ attributes["assign_graders_to_criteria"] = params[:assign_graders_to_criteria] if !params[:assign_graders_to_criteria].nil?
+ attributes["repository_folder"] = params[:repository_folder] if !params[:repository_folder].nil?
+ attributes["group_min"] = params[:group_min] if !params[:group_min].nil?
+ attributes["marking_scheme_type"] = params[:marking_scheme_type] if !params[:marking_scheme_type].nil?
+ end
+
+ return attributes
+ end
+
+ # Checks short_identifier, due_date
+ def has_missing_params?(params)
+ return params[:short_identifier].blank? || params[:due_date].blank?
+ end
+
+ # Get the plain text representation for users
+ def get_plain_text_for_assignments(assignments)
+ data=""
+
+ assignments.each do |assignment|
+ data += t('short_identifier') + ": " + assignment.short_identifier + "\n" +
+ t('due_date') + ": " + assignment.due_date.to_s + "\n" +
+ t('assignment.allow_web_submits') + ": " + assignment.allow_web_submits.to_s + "\n" +
+ t('assignment.display_grader_names_to_students') + ": " + assignment.display_grader_names_to_students.to_s + "\n" +
+ t('automated_tests.enable_test') + ": " + assignment.enable_test.to_s + "\n" +
+ t('graders.assign_to_criteria') + ": " + assignment.assign_graders_to_criteria.to_s + "\n" +
+ t('assignment.marking_scheme.title') + ": " + assignment.marking_scheme_type.to_s + "\n" +
+ t('assignment.submission_rules') + ": " + assignment.submission_rule.type + "\n\n"
+ end
+
+ return data
+ end
+
+ end # end AssignmentsApiController
+end
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment