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

MarkUsProject / Markus / 10928630900

18 Sep 2024 07:13PM UTC coverage: 51.86% (-39.7%) from 91.541%
10928630900

push

github

web-flow
Enable cron-based automatic syncing of LTI rosters (#7178)

574 of 1298 branches covered (44.22%)

Branch coverage included in aggregate %.

2 of 20 new or added lines in 4 files covered. (10.0%)

1886 existing lines in 60 files now uncovered.

3818 of 7171 relevant lines covered (53.24%)

76.37 hits per line

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

76.47
/app/controllers/application_controller.rb
1
# Filters added to this controller apply to all controllers in the application.
2
# Likewise, all the methods added will be available for all controllers.
3
class ApplicationController < ActionController::Base
1✔
4
  include SessionHandler
1✔
5
  include ApplicationHelper
1✔
6
  include UploadHelper
1✔
7
  include DownloadHelper
1✔
8

9
  authorize :role, through: :current_role
1✔
10
  authorize :real_user, through: :real_user
1✔
11
  authorize :real_role, through: :real_role
1✔
12
  verify_authorized
1✔
13
  rescue_from ActionPolicy::Unauthorized, with: :user_not_authorized
1✔
14

15
  # responder set up
16
  self.responder = ApplicationResponder
1✔
17
  respond_to :html
1✔
18

19
  protect_from_forgery with: :exception
1✔
20

21
  layout 'content'
1✔
22

23
  helper :all # include all helpers in the views, all the time
1✔
24

25
  # set user time zone based on their settings
26
  around_action :use_time_zone, if: :current_user
1✔
27
  # activate i18n for renaming constants in views
28
  before_action :set_locale, :get_file_encodings
1✔
29
  # check for active session on every page
30
  before_action :authenticate, :check_record,
1✔
31
                except: [:login, :page_not_found, :check_timeout, :login_remote_auth]
32
  before_action :check_course_switch
1✔
33
  # check for AJAX requests
34
  after_action :flash_to_headers
1✔
35

36
  # Define default URL options to include the locale if the user is not logged in
37
  def default_url_options(_options = {})
1✔
38
    if current_user
28✔
39
      {}
20✔
40
    else
41
      { locale: I18n.locale }
8✔
42
    end
43
  end
44

45
  def page_not_found
1✔
UNCOV
46
    if current_user
×
UNCOV
47
      current_role unless current_course.nil?
×
UNCOV
48
      render 'shared/error_page',
×
49
             locals: { code: '404', message: HttpStatusHelper::ERROR_CODE['message']['404'] },
50
             status: :not_found,
51
             layout: 'content'
52
    else
53
      redirect_to root_path
×
54
    end
55
  end
56

57
  protected
1✔
58

59
  def use_time_zone(&block)
1✔
60
    Time.use_zone(current_user.time_zone, &block)
3✔
61
  end
62

63
  # Set locale according to URL parameter. If unknown parameter is
64
  # requested, fall back to default locale.
65
  def set_locale
1✔
66
    if params[:locale].nil?
9✔
67
      if current_user && I18n.available_locales.include?(current_user.locale.to_sym)
6✔
68
        I18n.locale = current_user.locale
3✔
69
      else
70
        I18n.locale = I18n.default_locale
3✔
71
      end
72
    elsif I18n.available_locales.include? params[:locale].to_sym
3✔
73
      I18n.locale = params[:locale]
3✔
74
    else
75
      flash_now(:notice, I18n.t('locale_not_available', locale: params[:locale]))
×
76
    end
77
  end
78

79
  def get_file_encodings
1✔
80
    @encodings = [%w[Unicode UTF-8], %w[ISO-8859-1 ISO-8859-1]]
9✔
81
  end
82

83
  # add flash message to HTTP response headers
84
  def flash_to_headers
1✔
85
    [:error, :success, :warning, :notice].each do |key|
9✔
86
      unless flash[key].nil?
36✔
87
        if flash[key].is_a?(Array)
1✔
88
          str = flash[key].join(';')
1✔
89
        else
UNCOV
90
          str = flash[key]
×
91
        end
92
        response.headers["X-Message-#{key}"] = str
1✔
93
      end
94
    end
95
    if request.xhr?
9✔
UNCOV
96
      flash.discard
×
97
    end
98
  end
99

100
  # dynamically hide a flash message (for HTTP requests)
101
  def hide_flash(key)
1✔
UNCOV
102
    discard_header = response.headers['X-Message-Discard']
×
UNCOV
103
    if discard_header.nil?
×
UNCOV
104
      response.headers['X-Message-Discard'] = key.to_s
×
105
    else
106
      response.headers['X-Message-Discard'] = "#{key};#{discard_header}"
×
107
    end
108
  end
109

110
  def user_not_authorized
1✔
UNCOV
111
    if current_user
×
UNCOV
112
      render 'shared/error_page',
×
113
             locals: { code: '403', message: HttpStatusHelper::ERROR_CODE['message']['403'] },
114
             status: :forbidden,
115
             layout: 'content'
116
    else
117
      redirect_to root_path
×
118
    end
119
  end
120

121
  # Render 403 if the current user is switching roles and they try to view a route for a different course
122
  def check_course_switch
1✔
123
    if session[:role_switch_course_id] && current_course&.id != session[:role_switch_course_id]
3✔
UNCOV
124
      flash_message(:error, I18n.t('main.role_switch.forbidden_warning'))
×
UNCOV
125
      redirect_back(fallback_location: course_assignments_path(session[:role_switch_course_id]))
×
126
    end
127
  end
128

129
  def implicit_authorization_target
1✔
130
    controller_name.classify.constantize.find_or_initialize_by(identification_params)
10✔
131
  end
132

133
  def identification_params
1✔
134
    params.permit(:id)
10✔
135
  end
136
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