From 3ee2dcb754315ec3f88035c73f52a4fe1c329bbf Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 16:17:41 -0500 Subject: [PATCH 01/12] add admin action to refresh autotest schema --- app/controllers/courses_controller.rb | 24 +++++++++++++++++++++ app/policies/course_policy.rb | 4 ++++ app/views/courses/_form.html.erb | 9 ++++++++ config/locales/views/automated_tests/en.yml | 4 ++++ config/routes.rb | 1 + 5 files changed, 42 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 08425a73fc..00156b6a9b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -3,6 +3,8 @@ class CoursesController < ApplicationController before_action { authorize! } + include AutomatedTestsHelper::AutotestApi + respond_to :html layout 'assignment_content' @@ -198,6 +200,28 @@ def lti_deployments render json: @current_course.lti_deployments.to_json(include: :lti_client) end + def refresh_autotest_schema + unless allowed_to?(:edit?, with: Admin::CoursePolicy) + return + end + autotest_setting = @current_course.autotest_setting + if autotest_setting.nil? + flash_message(:error, I18n.t('automated_tests.no_autotest_settings')) + redirect_back(fallback_location: edit_course_path(@current_course)) + return + end + + begin + schema_json = get_schema(autotest_setting) + autotest_setting.update!(schema: schema_json) + flash_message(:success, I18n.t('automated_tests.refresh_autotest_schema.success')) + rescue StandardError => e + flash_message(:error, e.message) + end + + redirect_back(fallback_location: edit_course_path(@current_course)) + end + private def log_role_switch(found_user) diff --git a/app/policies/course_policy.rb b/app/policies/course_policy.rb index 2bbb2202db..1ef86dbd01 100644 --- a/app/policies/course_policy.rb +++ b/app/policies/course_policy.rb @@ -42,4 +42,8 @@ def upload_assignments? def manage_lti_deployments? user.admin_user? || Instructor.exists?(user: user, course: record) end + + def refresh_autotest_schema? + edit? + end end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index b166473b59..17eec04fb3 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -48,6 +48,15 @@ placeholder: t('time.format_string.placeholder'), readonly: !allowed_to?(:edit?, with: Admin::CoursePolicy) %> + <% if allowed_to?(:edit?, with: Admin::CoursePolicy) %> +

+ <%= link_to t('automated_tests.refresh_autotest_schema.bottom'), + refresh_autotest_schema_course_path(@current_course), + method: :post, + class: 'button', + data: { confirm: I18n.t('automated_tests.refresh_autotest_schema.confirm') } %> +

+ <% end %>

<%= f.submit t(:save), data: { disable_with: t('working') } %> diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index d7d7bb22c2..e4951c344a 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -44,6 +44,10 @@ en: no_instructor_runnable_tests: No tests are available for instructors to run. no_results: No test results to display no_student_runnable_tests: No tests are available for students to run. + refresh_autotest_schema: + bottom: Refresh autotest schema + confirm: Do you want to refresh autotest schema now? + success: Autotest schema refreshed. requirements_file: Package requirements file requirements_file_tooltip: Upload a requirements file along with the test files results: diff --git a/config/routes.rb b/config/routes.rb index 0eb04540ae..dfca3dbc28 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,6 +124,7 @@ post 'sync_roster' get 'lti_deployments' get 'lti_settings' + post 'refresh_autotest_schema' end resources :instructors, only: [:index, :new, :create, :edit, :update, :destroy] From ad2fa9040d28a17e0556163640158756723dc977 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:21:26 -0500 Subject: [PATCH 02/12] enable refresh autotest schema --- app/controllers/admin/courses_controller.rb | 17 ++++++++ app/controllers/courses_controller.rb | 24 ------------ app/policies/course_policy.rb | 4 -- app/views/courses/_form.html.erb | 4 +- config/locales/views/automated_tests/en.yml | 3 +- config/routes.rb | 2 +- .../admin/courses_controller_spec.rb | 39 +++++++++++++++++++ 7 files changed, 61 insertions(+), 32 deletions(-) diff --git a/app/controllers/admin/courses_controller.rb b/app/controllers/admin/courses_controller.rb index 4ded4cb437..7b5d0d8f9a 100644 --- a/app/controllers/admin/courses_controller.rb +++ b/app/controllers/admin/courses_controller.rb @@ -60,6 +60,23 @@ def reset_autotest_connection respond_with current_course, location: -> { edit_admin_course_path(current_course) } end + def refresh_autotest_schema + settings = current_course.autotest_setting + if settings.nil? + flash_message(:error, I18n.t('automated_tests.no_autotest_settings')) + return respond_with current_course, location: -> { edit_admin_course_path(current_course) } + end + + begin + schema_json = get_schema(settings) + settings.update!(schema: schema_json) + flash_message(:success, I18n.t('automated_tests.refresh_autotest_schema.success')) + rescue StandardError => e + flash_message(:error, I18n.t('automated_tests.refresh_autotest_schema.failure', error: e.message)) + end + respond_with current_course, location: -> { edit_admin_course_path(current_course) } + end + def destroy_lti_deployment deployment = LtiDeployment.find(params[:lti_deployment_id]) deployment.destroy! diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 00156b6a9b..08425a73fc 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -3,8 +3,6 @@ class CoursesController < ApplicationController before_action { authorize! } - include AutomatedTestsHelper::AutotestApi - respond_to :html layout 'assignment_content' @@ -200,28 +198,6 @@ def lti_deployments render json: @current_course.lti_deployments.to_json(include: :lti_client) end - def refresh_autotest_schema - unless allowed_to?(:edit?, with: Admin::CoursePolicy) - return - end - autotest_setting = @current_course.autotest_setting - if autotest_setting.nil? - flash_message(:error, I18n.t('automated_tests.no_autotest_settings')) - redirect_back(fallback_location: edit_course_path(@current_course)) - return - end - - begin - schema_json = get_schema(autotest_setting) - autotest_setting.update!(schema: schema_json) - flash_message(:success, I18n.t('automated_tests.refresh_autotest_schema.success')) - rescue StandardError => e - flash_message(:error, e.message) - end - - redirect_back(fallback_location: edit_course_path(@current_course)) - end - private def log_role_switch(found_user) diff --git a/app/policies/course_policy.rb b/app/policies/course_policy.rb index 1ef86dbd01..2bbb2202db 100644 --- a/app/policies/course_policy.rb +++ b/app/policies/course_policy.rb @@ -42,8 +42,4 @@ def upload_assignments? def manage_lti_deployments? user.admin_user? || Instructor.exists?(user: user, course: record) end - - def refresh_autotest_schema? - edit? - end end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index 17eec04fb3..e66328f85f 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -48,10 +48,10 @@ placeholder: t('time.format_string.placeholder'), readonly: !allowed_to?(:edit?, with: Admin::CoursePolicy) %> - <% if allowed_to?(:edit?, with: Admin::CoursePolicy) %> + <% if @current_course.persisted? && allowed_to?(:edit?, with: Admin::CoursePolicy) %>

<%= link_to t('automated_tests.refresh_autotest_schema.bottom'), - refresh_autotest_schema_course_path(@current_course), + refresh_autotest_schema_admin_course_path(@current_course), method: :post, class: 'button', data: { confirm: I18n.t('automated_tests.refresh_autotest_schema.confirm') } %> diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index e4951c344a..a27d00ef82 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -47,7 +47,8 @@ en: refresh_autotest_schema: bottom: Refresh autotest schema confirm: Do you want to refresh autotest schema now? - success: Autotest schema refreshed. + success: Refresh autotest schema was successful. + failure: "Refresh autotest schema failed with the following error: %{error}." requirements_file: Package requirements file requirements_file_tooltip: Upload a requirements file along with the test files results: diff --git a/config/routes.rb b/config/routes.rb index dfca3dbc28..8e1679a0f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,6 +104,7 @@ member do get 'test_autotest_connection' put 'reset_autotest_connection' + post 'refresh_autotest_schema' delete 'destroy_lti_deployment' end end @@ -124,7 +125,6 @@ post 'sync_roster' get 'lti_deployments' get 'lti_settings' - post 'refresh_autotest_schema' end resources :instructors, only: [:index, :new, :create, :edit, :update, :destroy] diff --git a/spec/controllers/admin/courses_controller_spec.rb b/spec/controllers/admin/courses_controller_spec.rb index 8945d4ab2b..e2afc4eb80 100644 --- a/spec/controllers/admin/courses_controller_spec.rb +++ b/spec/controllers/admin/courses_controller_spec.rb @@ -69,6 +69,13 @@ expect(response).to have_http_status(:forbidden) end end + + describe '#refresh_autotest_schema' do + it 'responds with 403' do + post_as user, :refresh_autotest_schema, params: { id: course.id } + expect(response).to have_http_status(:forbidden) + end + end end context 'Instructor' do @@ -354,6 +361,38 @@ end end + describe '#refresh_autotest_schema' do + subject { post_as admin, :refresh_autotest_schema, params: { id: course.id } } + + context 'there is no autotest_setting set' do + it 'should flash an error message' do + subject + expect(response).to have_http_status(:found) + expect(flash[:error]).not_to be_empty + end + end + + context 'there is an autotest_setting' do + include_context 'course with an autotest setting' + it 'should update the schema' do + schema_json = { 'schema' => 'data' }.to_json + allow(controller).to receive(:get_schema).and_return(schema_json) + subject + expect(autotest_setting.reload.schema).to eq(schema_json) + expect(flash[:success]).not_to be_empty + end + + context 'when the refresh request fails' do + before { allow(controller).to receive(:get_schema).and_raise(StandardError) } + + it 'should flash an error message' do + subject + expect(flash[:error]).not_to be_empty + end + end + end + end + describe '#reset_autotest_connection' do subject { put_as admin, :reset_autotest_connection, params: { id: course.id } } From 58294d7a38855d17d17c7da4fa0999d33e6a7f48 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:28:49 -0500 Subject: [PATCH 03/12] update changelog file --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 8caf63ea89..7998cc3f11 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ - Split courses into Current and Past sections for all users (#7801) - Batch the calculation of TA grading statistics on assignments index page (#7787) - Improve git repo access time, by reducing db queries (#7791) +- Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes - Prevent "No rows found" message from displaying in tables when data is loading (#7790) From 12d7e7b94556de8378cb494039be3b9d0c0c6e67 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:41:37 -0500 Subject: [PATCH 04/12] Revert "update changelog file" This reverts commit 58294d7a38855d17d17c7da4fa0999d33e6a7f48. --- Changelog.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index a34dad8db0..5a866f5708 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,7 +16,6 @@ - Split courses into Current and Past sections for all users (#7801) - Batch the calculation of TA grading statistics on assignments index page (#7787) - Improve git repo access time, by reducing db queries (#7791) -- Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes - Prevent "No rows found" message from displaying in tables when data is loading (#7790) From 6741843f32dfd220b384ff21c68523c032f7fe10 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:43:15 -0500 Subject: [PATCH 05/12] update changelog again --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 5a866f5708..a34dad8db0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ - Split courses into Current and Past sections for all users (#7801) - Batch the calculation of TA grading statistics on assignments index page (#7787) - Improve git repo access time, by reducing db queries (#7791) +- Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes - Prevent "No rows found" message from displaying in tables when data is loading (#7790) From b5b9fbce6cd3a65eb573f69f311fa82749161984 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:47:00 -0500 Subject: [PATCH 06/12] Revert "update changelog file" This reverts commit 58294d7a38855d17d17c7da4fa0999d33e6a7f48. --- Changelog.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index a34dad8db0..5a866f5708 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,7 +16,6 @@ - Split courses into Current and Past sections for all users (#7801) - Batch the calculation of TA grading statistics on assignments index page (#7787) - Improve git repo access time, by reducing db queries (#7791) -- Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes - Prevent "No rows found" message from displaying in tables when data is loading (#7790) From 2bd0b81bcde49ab513dc0e52aeb8d9828ddf306f Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:50:20 -0500 Subject: [PATCH 07/12] update changelog again --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 5a866f5708..a34dad8db0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ - Split courses into Current and Past sections for all users (#7801) - Batch the calculation of TA grading statistics on assignments index page (#7787) - Improve git repo access time, by reducing db queries (#7791) +- Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes - Prevent "No rows found" message from displaying in tables when data is loading (#7790) From 348c46262504504d75ef4cff7ca5219ca055f60a Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Thu, 12 Feb 2026 23:51:21 -0500 Subject: [PATCH 08/12] delete changes unrelated to this pr --- Changelog.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index a34dad8db0..73136cb9ae 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,8 +14,6 @@ - Update autotest settings form UI (#7777) - Store start and end date for courses (#7783) - Split courses into Current and Past sections for all users (#7801) -- Batch the calculation of TA grading statistics on assignments index page (#7787) -- Improve git repo access time, by reducing db queries (#7791) - Add an administrator action on the course settings page to refresh autotest schema (#7828) ### 🐛 Bug fixes From a86a62b2424e66c14d39e3162d6fa6ba30827d89 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Fri, 13 Feb 2026 12:57:55 -0500 Subject: [PATCH 09/12] reorder the i18n key in alphabetical order --- config/locales/views/automated_tests/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index a27d00ef82..e96cb73088 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -47,8 +47,8 @@ en: refresh_autotest_schema: bottom: Refresh autotest schema confirm: Do you want to refresh autotest schema now? - success: Refresh autotest schema was successful. failure: "Refresh autotest schema failed with the following error: %{error}." + success: Refresh autotest schema was successful. requirements_file: Package requirements file requirements_file_tooltip: Upload a requirements file along with the test files results: From a08d7b28a2bcd7446e0717631bb9cba9486d8696 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Sat, 14 Feb 2026 11:58:42 -0500 Subject: [PATCH 10/12] normalize i18n key --- config/locales/views/automated_tests/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index e96cb73088..f79d26143c 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -47,7 +47,7 @@ en: refresh_autotest_schema: bottom: Refresh autotest schema confirm: Do you want to refresh autotest schema now? - failure: "Refresh autotest schema failed with the following error: %{error}." + failure: 'Refresh autotest schema failed with the following error: %{error}.' success: Refresh autotest schema was successful. requirements_file: Package requirements file requirements_file_tooltip: Upload a requirements file along with the test files From fc2ebf203adcb249ea2475f1fa0cadb337213b3a Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Tue, 17 Feb 2026 22:26:27 -0500 Subject: [PATCH 11/12] move the button under 'Autotest Connection' section --- app/views/courses/_form.html.erb | 23 +++++++++++++-------- config/locales/views/automated_tests/en.yml | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index e66328f85f..0ea7aa6654 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -48,15 +48,6 @@ placeholder: t('time.format_string.placeholder'), readonly: !allowed_to?(:edit?, with: Admin::CoursePolicy) %> - <% if @current_course.persisted? && allowed_to?(:edit?, with: Admin::CoursePolicy) %> -

- <%= link_to t('automated_tests.refresh_autotest_schema.bottom'), - refresh_autotest_schema_admin_course_path(@current_course), - method: :post, - class: 'button', - data: { confirm: I18n.t('automated_tests.refresh_autotest_schema.confirm') } %> -

- <% end %>

<%= f.submit t(:save), data: { disable_with: t('working') } %> @@ -65,6 +56,20 @@ <% if @current_course.persisted? && allowed_to?(:edit?, with: Admin::CoursePolicy) %>

<%= t('automated_tests.manage_connection.title') %> +
+ <%= link_to t('automated_tests.refresh_autotest_schema.bottom'), + refresh_autotest_schema_admin_course_path(@current_course), + method: :post, + class: 'button', + data: { confirm: I18n.t('automated_tests.manage_connection.refresh_schema_confirm') } %> +
+

+ <%= I18n.t('automated_tests.manage_connection.refresh_schema_tooltip', + url: @current_course.autotest_setting&.url) %> +

+
+
+
<%= link_to I18n.t('automated_tests.manage_connection.test'), test_autotest_connection_admin_course_path(@current_course), diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index f79d26143c..47ba10f53c 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -27,6 +27,8 @@ en: Please try saving the settings again from the Automated Testing page. manage_connection: refresh: Refresh Settings + refresh_schema_confirm: Do you want to refresh autotest schema now? + refresh_schema_tooltip: Fetch the latest autotest schema from %{url}. refresh_tooltip: Resend all test settings to the automated tester at %{url}. This should be used when the automated tester has been reset. test: Test Connection test_failure: 'Connection to %{url} failed with the following error: %{error}' @@ -46,7 +48,6 @@ en: no_student_runnable_tests: No tests are available for students to run. refresh_autotest_schema: bottom: Refresh autotest schema - confirm: Do you want to refresh autotest schema now? failure: 'Refresh autotest schema failed with the following error: %{error}.' success: Refresh autotest schema was successful. requirements_file: Package requirements file From 045b73294d448b37c87ded5a37bbf27b618b09e0 Mon Sep 17 00:00:00 2001 From: freyazjiner Date: Tue, 17 Feb 2026 22:31:29 -0500 Subject: [PATCH 12/12] move the i18n key to under manage_connection --- app/controllers/admin/courses_controller.rb | 4 ++-- app/views/courses/_form.html.erb | 2 +- config/locales/views/automated_tests/en.yml | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/courses_controller.rb b/app/controllers/admin/courses_controller.rb index 7b5d0d8f9a..c03101f2dd 100644 --- a/app/controllers/admin/courses_controller.rb +++ b/app/controllers/admin/courses_controller.rb @@ -70,9 +70,9 @@ def refresh_autotest_schema begin schema_json = get_schema(settings) settings.update!(schema: schema_json) - flash_message(:success, I18n.t('automated_tests.refresh_autotest_schema.success')) + flash_message(:success, I18n.t('automated_tests.manage_connection.refresh_schema_success')) rescue StandardError => e - flash_message(:error, I18n.t('automated_tests.refresh_autotest_schema.failure', error: e.message)) + flash_message(:error, I18n.t('automated_tests.manage_connection.refresh_schema_failure', error: e.message)) end respond_with current_course, location: -> { edit_admin_course_path(current_course) } end diff --git a/app/views/courses/_form.html.erb b/app/views/courses/_form.html.erb index 0ea7aa6654..8f3e37fec7 100644 --- a/app/views/courses/_form.html.erb +++ b/app/views/courses/_form.html.erb @@ -57,7 +57,7 @@
<%= t('automated_tests.manage_connection.title') %>
- <%= link_to t('automated_tests.refresh_autotest_schema.bottom'), + <%= link_to t('automated_tests.manage_connection.refresh_schema_bottom'), refresh_autotest_schema_admin_course_path(@current_course), method: :post, class: 'button', diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index 47ba10f53c..4c58549425 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -27,7 +27,10 @@ en: Please try saving the settings again from the Automated Testing page. manage_connection: refresh: Refresh Settings + refresh_schema_bottom: Refresh autotest schema refresh_schema_confirm: Do you want to refresh autotest schema now? + refresh_schema_failure: 'Refresh autotest schema failed with the following error: %{error}.' + refresh_schema_success: Refresh autotest schema was successful. refresh_schema_tooltip: Fetch the latest autotest schema from %{url}. refresh_tooltip: Resend all test settings to the automated tester at %{url}. This should be used when the automated tester has been reset. test: Test Connection @@ -46,10 +49,6 @@ en: no_instructor_runnable_tests: No tests are available for instructors to run. no_results: No test results to display no_student_runnable_tests: No tests are available for students to run. - refresh_autotest_schema: - bottom: Refresh autotest schema - failure: 'Refresh autotest schema failed with the following error: %{error}.' - success: Refresh autotest schema was successful. requirements_file: Package requirements file requirements_file_tooltip: Upload a requirements file along with the test files results: