• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MarkUsProject / Markus / 20243384039

11 Dec 2025 06:21PM UTC coverage: 91.513%. First build
20243384039

Pull #7763

github

web-flow
Merge 9f55e660a into 0d3f24005
Pull Request #7763: Release 2.9.0

914 of 1805 branches covered (50.64%)

Branch coverage included in aggregate %.

1584 of 1666 new or added lines in 108 files covered. (95.08%)

43650 of 46892 relevant lines covered (93.09%)

121.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.85
/app/controllers/api/courses_controller.rb
1
module Api
1✔
2
  # API controller for Courses
3
  class CoursesController < MainApiController
1✔
4
    include AutomatedTestsHelper::AutotestApi
1✔
5

6
    DEFAULT_FIELDS = [:id, :name, :is_hidden, :display_name].freeze
1✔
7

8
    def index
1✔
9
      if current_user.admin_user?
64✔
10
        courses = get_collection(Course)
16✔
11
      else
12
        courses = get_collection(current_user.visible_courses)
48✔
13
      end
14
      respond_to do |format|
64✔
15
        format.xml { render xml: courses.to_xml(only: DEFAULT_FIELDS, root: 'courses', skip_types: 'true') }
96✔
16
        format.json { render json: courses.to_json(only: DEFAULT_FIELDS) }
96✔
17
      end
18
    end
19

20
    def show
1✔
21
      course = current_course
×
22
      respond_to do |format|
×
23
        format.xml { render xml: course.to_xml(only: DEFAULT_FIELDS, root: 'course', skip_types: 'true') }
×
24
        format.json { render json: course.to_json(only: DEFAULT_FIELDS) }
×
25
      end
26
    end
27

28
    def create
1✔
29
      Course.create!(params.permit(:name, :is_hidden, :display_name))
2✔
30
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
NEW
31
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
32
    rescue StandardError
33
      render 'shared/http_status', locals: { code: '500', message:
×
34
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
35
    else
36
      render 'shared/http_status', locals: { code: '200', message:
2✔
37
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
38
    end
39

40
    def update
1✔
41
      current_course.update!(params.permit(:name, :is_hidden, :display_name))
1✔
42
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
NEW
43
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
44
    rescue StandardError
45
      render 'shared/http_status', locals: { code: '500', message:
×
46
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
47
    else
48
      render 'shared/http_status', locals: { code: '200', message:
1✔
49
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
50
    end
51

52
    def update_autotest_url
1✔
53
      AutotestResetUrlJob.perform_now(current_course, params[:url], request.protocol + request.host_with_port)
1✔
54
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
NEW
55
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
56
    rescue StandardError
57
      render 'shared/http_status', locals: { code: '500', message:
×
58
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
59
    else
60
      render 'shared/http_status', locals: { code: '200', message:
1✔
61
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
62
    end
63

64
    def test_autotest_connection
1✔
65
      settings = current_course.autotest_setting
5✔
66
      if settings&.url
5✔
67
        begin
68
          get_schema(current_course.autotest_setting)
4✔
69
          render 'shared/http_status', locals: { code: '200', message:
2✔
70
            I18n.t('automated_tests.manage_connection.test_success', url: settings.url) }, status: :ok
71
        rescue JSON::ParserError
72
          render 'shared/http_status',
1✔
73
                 locals: { code: '500',
74
                           message: I18n.t('automated_tests.manage_connection.test_schema_failure',
75
                                           url: settings.url) },
76
                 status: :internal_server_error
77
        rescue StandardError => e
78
          render 'shared/http_status',
1✔
79
                 locals: { code: '500',
80
                           message: I18n.t('automated_tests.manage_connection.test_failure',
81
                                           url: settings.url,
82
                                           error: e.to_s) },
83
                 status: :internal_server_error
84
        end
85
      else
86
        render 'shared/http_status', locals: { code: '422', message:
1✔
87
          I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
88
      end
89
    end
90

91
    def reset_autotest_connection
1✔
92
      settings = current_course.autotest_setting
4✔
93
      if settings&.url
4✔
94
        begin
95
          AutotestResetUrlJob.perform_now(current_course, settings.url,
3✔
96
                                          request.protocol + request.host_with_port, refresh: true)
97
          render 'shared/http_status', locals: { code: '200', message:
2✔
98
            HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
99
        rescue StandardError => e
100
          render 'shared/http_status', locals: { code: '500', message: e.to_s }, status: :internal_server_error
1✔
101
        end
102
      else
103
        render 'shared/http_status', locals: { code: '422', message:
1✔
104
          I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
105
      end
106
    end
107

108
    private
1✔
109

110
    def check_course
1✔
111
      super unless action_name == 'index'
×
112
    end
113

114
    protected
1✔
115

116
    def implicit_authorization_target
1✔
117
      Course
80✔
118
    end
119
  end
120
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc