From 565250a38b018156e4e92fefcccb01a011872ebd Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Sun, 9 Jan 2022 16:26:36 +1100 Subject: [PATCH] fix: update model object to work with ruby 3.1 --- app/helpers/file_helper.rb | 2 +- app/models/overseer_assessment.rb | 6 +++--- app/models/task.rb | 12 ++++++------ app/models/task_definition.rb | 10 +++++----- app/models/unit.rb | 22 +++++++++++----------- config/secrets.yml | 14 +++++++++++--- lib/helpers/database_populator.rb | 8 ++++---- 7 files changed, 41 insertions(+), 33 deletions(-) diff --git a/app/helpers/file_helper.rb b/app/helpers/file_helper.rb index c4d904ef4..8267a611a 100644 --- a/app/helpers/file_helper.rb +++ b/app/helpers/file_helper.rb @@ -425,7 +425,7 @@ def write_entries_to_zip(entries, disk_root_path, zip_root_path, path, zip) # puts "subdir: #{subdir}" write_entries_to_zip(subdir, disk_root_path, zip_root_path, file_path, zip) else - # puts "Adding file: #{disk_file_path} -- #{File.exists? disk_file_path}" + # puts "Adding file: #{disk_file_path} -- #{File.exist? disk_file_path}" zip.get_output_stream(zip_file_path) do |f| f.puts(File.open(disk_file_path, 'rb').read) end diff --git a/app/models/overseer_assessment.rb b/app/models/overseer_assessment.rb index eb67beb30..3219ee033 100644 --- a/app/models/overseer_assessment.rb +++ b/app/models/overseer_assessment.rb @@ -51,7 +51,7 @@ def self.create_for(task) end def has_submission_files? - File.exists? submission_zip_file_name + File.exist? submission_zip_file_name end def submission_zip_file_name @@ -155,7 +155,7 @@ def send_to_overseer() return nil end - unless File.exists? submission_zip_file_name + unless File.exist? submission_zip_file_name puts "ERROR: Student submission history zip file doesn't exist #{submission_zip_file_name}. Unable to send - OverseerAssessment #{id}" return nil end @@ -166,7 +166,7 @@ def send_to_overseer() return nil end - unless File.exists? assessment_resources_path + unless File.exist? assessment_resources_path puts "ERROR: Unable to fine assessment resources - OverseerAssessment #{id}" return nil end diff --git a/app/models/task.rb b/app/models/task.rb index 38cf9d805..42a466feb 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -799,7 +799,7 @@ def has_new_files? end def has_done_file? - File.exists? zip_file_path_for_done_task + File.exist? zip_file_path_for_done_task end # @@ -1017,7 +1017,7 @@ def portfolio_evidence_path def portfolio_evidence_path=(value) # Strip the student work directory to store in database as relative path self.portfolio_evidence = value.present? ? value.sub(FileHelper.student_work_dir,'') : nil - end + end def final_pdf_path if group_task? @@ -1248,7 +1248,7 @@ def accept_submission(current_user, files, _student, ui, contributions, trigger, enqueued_dir = File.join(FileHelper.student_work_dir(:new, nil, true), id.to_s) # Move files into place, deleting existing files if present. - if not File.exists? enqueued_dir + if not File.exist? enqueued_dir logger.debug "Creating student work new dir #{enqueued_dir}" FileUtils.mkdir_p enqueued_dir end @@ -1259,7 +1259,7 @@ def accept_submission(current_user, files, _student, ui, contributions, trigger, # Delete the tmp dir logger.debug "Deleting student work dir: #{tmp_dir}" - FileUtils.rm_rf tmp_dir if File.exists? tmp_dir + FileUtils.rm_rf tmp_dir if File.exist? tmp_dir logger.info "Submission accepted! Status for task #{id} is now #{trigger}" end @@ -1270,10 +1270,10 @@ def delete_associated_files group_submission.destroy else zip_file = zip_file_path_for_done_task() - if zip_file && File.exists?(zip_file) + if zip_file && File.exist?(zip_file) FileUtils.rm zip_file end - if portfolio_evidence_path.present? && File.exists?(portfolio_evidence_path) + if portfolio_evidence_path.present? && File.exist?(portfolio_evidence_path) FileUtils.rm portfolio_evidence_path end diff --git a/app/models/task_definition.rb b/app/models/task_definition.rb index 08a1c1218..cb5e5584e 100644 --- a/app/models/task_definition.rb +++ b/app/models/task_definition.rb @@ -116,15 +116,15 @@ def remove_old_group_submissions def move_files_on_abbreviation_change old_abbr = saved_change_to_abbreviation[0] # 0 is original abbreviation - if File.exists? task_sheet_with_abbreviation(old_abbr) + if File.exist? task_sheet_with_abbreviation(old_abbr) FileUtils.mv(task_sheet_with_abbreviation(old_abbr), task_sheet()) end - if File.exists? task_resources_with_abbreviation(old_abbr) + if File.exist? task_resources_with_abbreviation(old_abbr) FileUtils.mv(task_resources_with_abbreviation(old_abbr), task_resources()) end - if File.exists? task_assessment_resources_with_abbreviation(old_abbr) + if File.exist? task_assessment_resources_with_abbreviation(old_abbr) FileUtils.mv(task_assessment_resources_with_abbreviation(old_abbr), task_assessment_resources()) end end @@ -340,8 +340,8 @@ def clear_related_plagiarism end end - def self.to_csv(task_definitions, options = {}) - CSV.generate(options) do |csv| + def self.to_csv(task_definitions) + CSV.generate() do |csv| csv << csv_columns task_definitions.each do |task_definition| csv << task_definition.to_csv_row diff --git a/app/models/unit.rb b/app/models/unit.rb index 4e742d435..d0de91794 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -717,7 +717,7 @@ def update_student_enrolments(changes, import_settings, result) last_name = last_name || first_name nickname = nickname || first_name - if !email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + if email !~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i errors << { row: row, message: "Invalid email address (#{email})" } next end @@ -1338,12 +1338,12 @@ def tutorial_stream_abbr tutorial_streams.map{|ts| ts.abbreviation } end - def task_completion_csv(options = {}) + def task_completion_csv task_def_by_grade = task_definitions_by_grade streams = tutorial_streams grp_sets = group_sets - CSV.generate(options) do |csv| + CSV.generate() do |csv| # Add header row csv << [ 'Student ID', @@ -1407,7 +1407,7 @@ def task_completion_csv(options = {}) "#{row['first_name']} #{row['last_name']}", GradeHelper.grade_for(row['target_grade']), row['email'], - row['portfolio_production_date'].present? && !row['compile_portfolio'] && File.exists?(FileHelper.student_portfolio_path(self, row['username'], true)), + row['portfolio_production_date'].present? && !row['compile_portfolio'] && File.exist?(FileHelper.student_portfolio_path(self, row['username'], true)), row['grade'] > 0 ? row['grade'] : nil, row['grade_rationale'] ] + [1].map do @@ -1437,7 +1437,7 @@ def get_portfolio_zip(current_user) filename = FileHelper.sanitized_filename("portfolios-#{code}-#{current_user.username}") result = "#{FileHelper.tmp_file(filename)}.zip" - return result if File.exists?(result) + return result if File.exist?(result) # Create a new zip Zip::File.open(result, Zip::File::CREATE) do |zip| active_projects.each do |project| @@ -1462,7 +1462,7 @@ def get_task_resources_zip # Get a temp file path result = FileHelper.tmp_file("task-resources-#{code}.zip") - return result if File.exists?(result) + return result if File.exist?(result) # Create a new zip Zip::File.open(result, Zip::File::CREATE) do |zip| @@ -1490,7 +1490,7 @@ def get_task_submissions_pdf_zip(current_user, td) tasks_with_files = td.related_tasks_with_files - return result if File.exists?(result) + return result if File.exist?(result) # Create a new zip Zip::File.open(result, Zip::File::CREATE) do |zip| @@ -1523,7 +1523,7 @@ def get_task_submissions_zip(current_user, td) tasks_with_files = td.related_tasks_with_files - return result if File.exists?(result) + return result if File.exist?(result) # Create a new zip Zip::File.open(result, Zip::File::CREATE) do |zip| @@ -2275,8 +2275,8 @@ def student_grades_csv end # Used to calculate the number of assessment each tutor has performed - def tutor_assessment_csv(options = {}) - CSV.generate(options) do |csv| + def tutor_assessment_csv + CSV.generate() do |csv| csv << [ 'Username', 'Tutor Name', @@ -2322,7 +2322,7 @@ def generate_batch_task_zip(user, tasks) output_zip = FileHelper.tmp_file("batch_ready_for_feedback_#{code}_#{user.username}.zip") - return result if File.exists?(output_zip) + return result if File.exist?(output_zip) # Create a new zip Zip::File.open(output_zip, Zip::File::CREATE) do |zip| diff --git a/config/secrets.yml b/config/secrets.yml index e59d46c66..71241f314 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,13 +1,21 @@ -development: &development +development: &development-settings secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %> secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %> secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %> secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %> secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %> test: - <<: *development + secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %> + secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %> + secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %> + secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %> + secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %> staging: - <<: *development + secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %> + secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %> + secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %> + secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %> + secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %> production: secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] %> secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] %> diff --git a/lib/helpers/database_populator.rb b/lib/helpers/database_populator.rb index 304630e4e..a7aa80b64 100644 --- a/lib/helpers/database_populator.rb +++ b/lib/helpers/database_populator.rb @@ -473,7 +473,7 @@ def self.assess_task(proj, task, tutor, status, complete_date) end pdf_path = task.final_pdf_path - if pdf_path && !File.exists?(pdf_path) + if pdf_path && !File.exist?(pdf_path) FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-student-submission.pdf'), pdf_path) end @@ -486,7 +486,7 @@ def self.generate_portfolio(project) FileUtils.mkdir_p(portfolio_tmp_dir) lsr_path = File.join(portfolio_tmp_dir, "000-document-LearningSummaryReport.pdf") - FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-learning-summary.pdf'), lsr_path) unless File.exists? lsr_path + FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-learning-summary.pdf'), lsr_path) unless File.exist? lsr_path project.compile_portfolio = true project.create_portfolio end @@ -508,7 +508,7 @@ def echo_line *args def generate_tasks_for_unit(unit, unit_details) echo "----> Generating #{unit_details[:num_tasks]} tasks" - if File.exists? Rails.root.join('test_files',"#{unit.code}-Tasks.csv") + if File.exist? Rails.root.join('test_files',"#{unit.code}-Tasks.csv") unit.import_tasks_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Tasks.csv")) unit.import_task_files_from_zip Rails.root.join('test_files',"#{unit.code}-Tasks.zip") return @@ -546,7 +546,7 @@ def generate_and_align_ilos_for_unit(unit, unit_details) # Create the ILOs echo "----> Adding #{unit_details[:ilos]} ILOs" - if File.exists? Rails.root.join('test_files',"#{unit.code}-Outcomes.csv") + if File.exist? Rails.root.join('test_files',"#{unit.code}-Outcomes.csv") unit.import_outcomes_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Outcomes.csv")) unit.import_task_alignment_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Alignment.csv")), nil return