Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Added tests to improve coverage for `AnnotationCategory`'s `self.to_json` method
- Added tests to the Criteria Controller class to achieve full test coverage
- Refactored Criterion subclasses to remove redundant code
- Fixed Rack deprecation warnings by updating HTTP status code symbols (#7675)

## [v2.8.1]

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update

def test_autotest_connection
settings = current_course.autotest_setting
return head :unprocessable_entity unless settings&.url
return head :unprocessable_content unless settings&.url
begin
get_schema(current_course.autotest_setting)
flash_now(:success, I18n.t('automated_tests.manage_connection.test_success', url: settings.url))
Expand All @@ -50,7 +50,7 @@ def test_autotest_connection

def reset_autotest_connection
settings = current_course.autotest_setting
return head :unprocessable_entity unless settings&.url
return head :unprocessable_content unless settings&.url
@current_job = AutotestResetUrlJob.perform_later(current_course,
settings.url,
request.protocol + request.host_with_port,
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create
if has_missing_params?([:short_identifier, :due_date, :description])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand Down Expand Up @@ -205,15 +205,15 @@ def update_test_specs
begin
content = JSON.parse params[:specs]
rescue JSON::ParserError => e
render 'shared/http_status', locals: { code: '422', message: e.message }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.message }, status: :unprocessable_content
return
end
end
if content.nil?
render 'shared/http_status',
locals: { code: '422',
message: HttpStatusHelper::ERROR_CODE['message']['422'] },
status: :unprocessable_entity
status: :unprocessable_content
else
AutotestSpecsJob.perform_now(request.protocol + request.host_with_port, assignment, content)
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def show
def create
Course.create!(params.permit(:name, :is_hidden, :display_name))
rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
rescue StandardError
render 'shared/http_status', locals: { code: '500', message:
HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
Expand All @@ -39,7 +39,7 @@ def create
def update
current_course.update!(params.permit(:name, :is_hidden, :display_name))
rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
rescue StandardError
render 'shared/http_status', locals: { code: '500', message:
HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
Expand All @@ -51,7 +51,7 @@ def update
def update_autotest_url
AutotestResetUrlJob.perform_now(current_course, params[:url], request.protocol + request.host_with_port)
rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
rescue StandardError
render 'shared/http_status', locals: { code: '500', message:
HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_autotest_connection
end
else
render 'shared/http_status', locals: { code: '422', message:
I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_entity
I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
end
end

Expand All @@ -100,7 +100,7 @@ def reset_autotest_connection
end
else
render 'shared/http_status', locals: { code: '422', message:
I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_entity
I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/feedback_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create
if has_missing_params?([:filename, :mime_type, :file_content])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand Down Expand Up @@ -85,7 +85,7 @@ def create
message: I18n.t('oversize_feedback_file',
file_size: ActiveSupport::NumberHelper.number_to_human_size(size_diff),
max_file_size: submission.course.max_file_size / 1_000_000) },
status: :payload_too_large
status: :content_too_large
return
end
if submission.feedback_files.create(filename: params[:filename],
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/api/grade_entry_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create
if has_missing_params?([:short_identifier])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand All @@ -60,7 +60,7 @@ def create
new_form = GradeEntryForm.new(create_params)
unless new_form.save
render 'shared/http_status', locals: { code: '422', message:
new_form.errors.full_messages.first }, status: :unprocessable_entity
new_form.errors.full_messages.first }, status: :unprocessable_content
raise ActiveRecord::Rollback
end

Expand All @@ -69,7 +69,7 @@ def create
grade_item = new_form.grade_entry_items.build(**column_params, position: i + 1)
unless grade_item.save
render 'shared/http_status', locals: { code: '422', message:
grade_item.errors.full_messages.first }, status: :unprocessable_entity
grade_item.errors.full_messages.first }, status: :unprocessable_content
raise ActiveRecord::Rollback
end
end
Expand Down Expand Up @@ -137,7 +137,7 @@ def update_grades
if has_missing_params?([:user_name, :grade_entry_items])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand All @@ -151,7 +151,7 @@ def update_grades
if grade_entry_student.nil?
# There is no student with that user_name
render 'shared/http_status', locals: { code: '422', message:
'There is no student with that user_name' }, status: :unprocessable_entity
'There is no student with that user_name' }, status: :unprocessable_content
return
end

Expand All @@ -162,7 +162,7 @@ def update_grades
if grade_entry_item.nil?
# There is no such grade entry item
render 'shared/http_status', locals: { code: '422', message:
"There is no grade entry item named #{item}" }, status: :unprocessable_entity
"There is no grade entry item named #{item}" }, status: :unprocessable_content
raise ActiveRecord::Rollback
end
grade = grade_entry_student.grades.find_or_create_by(grade_entry_item_id: grade_entry_item.id)
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/api/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create
end
rescue StandardError => e
render 'shared/http_status', locals: { code: '422', message:
e.message }, status: :unprocessable_entity
e.message }, status: :unprocessable_content
end
end

Expand Down Expand Up @@ -68,7 +68,7 @@ def add_members
if self.grouping.nil?
# The group doesn't have a grouping associated with that assignment
render 'shared/http_status', locals: { code: '422', message:
'The group is not involved with that assignment' }, status: :unprocessable_entity
'The group is not involved with that assignment' }, status: :unprocessable_content
return
end

Expand Down Expand Up @@ -281,7 +281,7 @@ def update_marking_state
if has_missing_params?([:marking_state])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
result = self.grouping&.current_submission_used&.get_latest_result
Expand Down Expand Up @@ -336,7 +336,7 @@ def extension
else
# cannot delete a non existent extension; render failure
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
end
when 'POST'
if grouping.extension.nil?
Expand All @@ -349,7 +349,7 @@ def extension
else
# cannot create extension as it already exists; render failure
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
end
when 'PATCH'
if grouping.extension.present?
Expand All @@ -362,11 +362,11 @@ def extension
else
# cannot update extension as it does not exists; render failure
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
end
end
rescue ActiveRecord::RecordInvalid => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
end

def collect_submission
Expand All @@ -375,7 +375,7 @@ def collect_submission
released = @grouping.current_submission_used.results.exists?(released_to_students: true)
if released
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/main_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_collection(collection)
filter_params = params[:filter] ? params[:filter].permit(self.class::DEFAULT_FIELDS) : {}
if params[:filter].present? && filter_params.empty?
render 'shared/http_status', locals: { code: '422', message:
'Invalid or malformed parameter values' }, status: :unprocessable_entity
'Invalid or malformed parameter values' }, status: :unprocessable_content
false
elsif filter_params.empty?
collection.order('id')
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def create_role
HttpStatusHelper::ERROR_CODE['message']['201'] }, status: :created
end
rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotFound => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
rescue StandardError
render 'shared/http_status', locals: { code: '500', message:
HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
Expand All @@ -151,7 +151,7 @@ def update_role(role)
render 'shared/http_status', locals: { code: '200', message:
HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotFound => e
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_entity
render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
rescue StandardError
render 'shared/http_status', locals: { code: '500', message:
HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
Expand All @@ -161,7 +161,7 @@ def find_role_by_username
if has_missing_params?([:user_name])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand All @@ -181,7 +181,7 @@ def filtered_roles
if filter_params.empty?
render 'shared/http_status',
locals: { code: '422', message: 'Invalid or malformed parameter values' },
status: :unprocessable_entity
status: :unprocessable_content
return false
else
return collection.where(**filter_params)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create
locals: { code: '201', message: HttpStatusHelper::ERROR_CODE['message']['201'] }, status: :created
else
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
end
end

Expand Down
16 changes: 8 additions & 8 deletions app/controllers/api/starter_file_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_file
if has_missing_params?([:filename, :file_content])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand All @@ -73,7 +73,7 @@ def create_file
file_path = FileHelper.checked_join(starter_file_group.path, params[:filename])
if file_path.nil?
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
else
File.write(file_path, content, mode: 'wb')
update_entries_and_warn(starter_file_group)
Expand All @@ -91,14 +91,14 @@ def create_folder
if has_missing_params?([:folder_path])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

folder_path = FileHelper.checked_join(starter_file_group.path, params[:folder_path])
if folder_path.nil?
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
else
FileUtils.mkdir_p(folder_path)
update_entries_and_warn(starter_file_group)
Expand All @@ -116,13 +116,13 @@ def remove_file
if has_missing_params?([:filename])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
file_path = FileHelper.checked_join(starter_file_group.path, params[:filename])
if file_path.nil?
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
else
File.delete(file_path)
update_entries_and_warn(starter_file_group)
Expand All @@ -140,14 +140,14 @@ def remove_folder
if has_missing_params?([:folder_path])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

folder_path = FileHelper.checked_join(starter_file_group.path, params[:folder_path])
if folder_path.nil?
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
else
FileUtils.rm_rf(folder_path)
update_entries_and_warn(starter_file_group)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/submission_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def index
file = revision.files_at_path(File.join(assignment.repository_folder, path))[file_name]
if file.nil?
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
file_contents = repo.download_as_string(file)
Expand Down Expand Up @@ -88,7 +88,7 @@ def create_folders
if has_missing_params?([:folder_path])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
success, messages = grouping.access_repo do |repo|
Expand All @@ -115,7 +115,7 @@ def remove_file
if has_missing_params?([:filename])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end

Expand Down Expand Up @@ -143,7 +143,7 @@ def remove_folder
if has_missing_params?([:folder_path])
# incomplete/invalid HTTP params
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_entity
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
success, messages = grouping.access_repo do |repo|
Expand Down
Loading