Skip to content
Closed
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
24 changes: 24 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class CoursesController < ApplicationController
before_action { authorize! }

include AutomatedTestsHelper::AutotestApi

respond_to :html
layout 'assignment_content'

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/policies/course_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions app/views/courses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
placeholder: t('time.format_string.placeholder'),
readonly: !allowed_to?(:edit?, with: Admin::CoursePolicy) %>
</div>
<% if allowed_to?(:edit?, with: Admin::CoursePolicy) %>
<p>
<%= 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') } %>
</p>
<% end %>
<p>
<%= f.submit t(:save),
data: { disable_with: t('working') } %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/views/automated_tests/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down