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

expertiza / expertiza / #18872

17 Feb 2025 02:43PM UTC coverage: 12.388% (-3.1%) from 15.45%
#18872

push

web-flow
sending email to mentor (#2915)

Co-authored-by: root <root@vclvm178-118.vcl.ncsu.edu>

0 of 11 new or added lines in 1 file covered. (0.0%)

973 existing lines in 36 files now uncovered.

1951 of 15749 relevant lines covered (12.39%)

0.25 hits per line

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

0.0
/app/controllers/application_controller.rb
UNCOV
1
class ApplicationController < ActionController::Base
×
UNCOV
2
  include AccessHelper
×
UNCOV
3
  helper_method :current_user
×
4

5
  # You want to get exceptions in development, but not in production.
UNCOV
6
  unless Rails.application.config.consider_all_requests_local
×
7
    rescue_from ActionView::MissingTemplate do |_exception|
×
8
      redirect_to root_path
×
UNCOV
9
    end
×
UNCOV
10
  end
×
11

12
  # forcing SSL only in the production mode
UNCOV
13
  force_ssl if Rails.env.production?
×
14

UNCOV
15
  helper_method :current_user, :current_user_role?
×
UNCOV
16
  protect_from_forgery with: :exception
×
UNCOV
17
  before_action :set_time_zone
×
UNCOV
18
  before_action :authorize
×
UNCOV
19
  before_action :filter_utf8
×
UNCOV
20
  before_action :set_locale
×
21

UNCOV
22
  def set_locale
×
23
    I18n.locale = user_locale
×
UNCOV
24
  end
×
25

UNCOV
26
  def user_locale
×
27
    # Checks whether the user is logged in, else the default locale is used
28
    if logged_in?
×
29
      # If the current user has set his preferred language, the locale is set according to their preference
30
      if !current_user.locale.nil?
×
31
        if current_user.locale != 'no_pref'
×
32
          return current_user.locale
×
33
          # If the user doesn't have any preference, the locale is taken from the course locale, if the current page is a course specific page or else default locale is used
34
        elsif current_user_role? && current_user_role.student? && respond_to?(:controller_locale)
×
35
          return controller_locale
×
UNCOV
36
        end
×
UNCOV
37
      else
×
38
        return I18n.default_locale
×
UNCOV
39
      end
×
UNCOV
40
    end
×
41
    I18n.default_locale
×
UNCOV
42
  end
×
43

UNCOV
44
  def locale_for_student
×
45
    # Gets participant using student from params
46
    participant_id = params[:id] || params[:student_id]
×
47
    if !participant_id.nil?
×
48
      participant = AssignmentParticipant.find_by(id: participant_id)
×
49
      # If id or student_id not correct, revert to locale based on courses.
50
      return locale_from_user_courses if participant.nil?
×
51

52
      # Find assignment from participant and find locale from the assignment
53
      assignment = participant.assignment
×
54
      return assignment.course.locale unless assignment.course.nil? || assignment.course.locale.nil?
×
UNCOV
55
    else
×
56
      return locale_from_user_courses
×
UNCOV
57
    end
×
58
    I18n.default_locale
×
UNCOV
59
  end
×
60

UNCOV
61
  def locale_from_user_courses
×
62
    # If the page is a course or assignment page with no specific student id, every course of that student is checked and if
63
    # the language for all these course are same, the page is displayed in that language
64
    course_participants = CourseParticipant.where(user_id: current_user.id)
×
65
    course_participants_locales = course_participants.map { |cp| cp.course.locale }
×
66
    # If no tasks, then possible to have no courses assigned.
67
    if course_participants_locales.uniq.length == 1 # && !@tasks.empty?
×
68
      course = course_participants.first.course
×
69
      return course.locale if course.locale?
×
UNCOV
70
    end
×
71
    I18n.default_locale
×
UNCOV
72
  end
×
73

UNCOV
74
  def filter_utf8
×
75
    remove_non_utf8(params)
×
UNCOV
76
  end
×
77

UNCOV
78
  def self.verify(_args); end
×
79

UNCOV
80
  def current_user_role?
×
81
    current_user.role.name
×
UNCOV
82
  end
×
83

UNCOV
84
  def current_role_name
×
85
    current_role.try :name
×
UNCOV
86
  end
×
87

UNCOV
88
  def current_role
×
89
    current_user.try :role
×
UNCOV
90
  end
×
91

UNCOV
92
  helper_method :current_user_role?
×
93

UNCOV
94
  def user_for_paper_trail
×
95
    session[:user].try :id if session[:user]
×
UNCOV
96
  end
×
97

UNCOV
98
  def undo_link(message)
×
99
    version = Version.where('whodunnit = ?', session[:user].id).last
×
100
    return unless version.try(:created_at) && Time.now.in_time_zone - version.created_at < 5.0
×
101

102
    link_name = params[:redo] == 'true' ? 'redo' : 'undo'
×
103
    message + "<a href = #{url_for(controller: :versions, action: :revert, id: version.id, redo: !params[:redo])}>#{link_name}</a>"
×
UNCOV
104
  end
×
105

UNCOV
106
  def are_needed_authorizations_present?(id, *authorizations)
×
107
    participant = Participant.find_by(id: id)
×
108
    return false if participant.nil?
×
109

110
    authorization = participant.authorization
×
111
    !authorizations.include?(authorization)
×
UNCOV
112
  end
×
113

UNCOV
114
  private
×
115

UNCOV
116
  def current_user
×
117
    @current_user ||= session[:user]
×
UNCOV
118
  end
×
119

UNCOV
120
  helper_method :current_user
×
121

UNCOV
122
  def current_user_role
×
123
    current_user.role
×
UNCOV
124
  end
×
125

126
  # rubocop:disable Lint/DuplicateMethods
UNCOV
127
  alias current_user_role? current_user_role
×
128
  # rubocop:enable Lint/DuplicateMethods
129

UNCOV
130
  def logged_in?
×
131
    # Recommendation: rename to ever_logged_in? because that's how this actually works
132
    current_user
×
UNCOV
133
  end
×
134

UNCOV
135
  def set_time_zone
×
136
    Time.zone = current_user.timezonepref if current_user
×
UNCOV
137
  end
×
138

UNCOV
139
  def require_user
×
140
    invalid_login_status('in') unless current_user
×
UNCOV
141
  end
×
142

UNCOV
143
  def require_no_user
×
144
    invalid_login_status('out') if current_user
×
UNCOV
145
  end
×
146

UNCOV
147
  def invalid_login_status(status)
×
148
    flash[:notice] = "You must be logged #{status} to access this page!"
×
149
    redirect_back fallback_location: root_path
×
UNCOV
150
  end
×
151

UNCOV
152
  def available?(user, owner_id)
×
UNCOV
153
    user.id == owner_id ||
×
154
      user.admin? ||
×
UNCOV
155
      user.super_admin?
×
UNCOV
156
  end
×
157

UNCOV
158
  def record_not_found
×
159
    redirect_to controller: :tree_display, action: :list
×
UNCOV
160
  end
×
161

UNCOV
162
  def remove_non_utf8(hash)
×
163
    # remove non-utf8 chars from hash
164
    hash.each_pair do |_key, value|
×
165
      if value.is_a?(Hash)
×
166
        remove_non_utf8(value)
×
167
      elsif value.is_a?(String)
×
168
        encode_opts = {
×
UNCOV
169
          invalid: :replace,
×
UNCOV
170
          undef: :replace,
×
UNCOV
171
          replace: ''
×
UNCOV
172
        }
×
173
        value.encode!(Encoding.find('UTF-8'), encode_opts)
×
UNCOV
174
      end
×
UNCOV
175
    end
×
UNCOV
176
  end
×
177

UNCOV
178
  protected
×
179

180
  # Use this method to validate the current user in order to avoid allowing users
181
  # to see unauthorized data.
182
  # Ex: return unless current_user_id?(params[:user_id])
UNCOV
183
  def current_user_id?(user_id)
×
184
    current_user.try(:id) == user_id
×
UNCOV
185
  end
×
186

UNCOV
187
  def denied(reason = nil)
×
188
    if reason
×
189
      redirect_to "/denied?reason=#{reason}"
×
UNCOV
190
    else
×
191
      redirect_to '/denied'
×
UNCOV
192
    end
×
UNCOV
193
  end
×
UNCOV
194
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