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

codebar / planner / 6013922372

29 Aug 2023 02:50PM UTC coverage: 95.45% (-0.2%) from 95.602%
6013922372

push

github

web-flow
Merge pull request #1914 from codebar/fix-broken-link-on-admin-member-page

Fix broken link url on admin member page

3147 of 3297 relevant lines covered (95.45%)

36.65 hits per line

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

84.09
/app/controllers/application_controller.rb
1
class ApplicationController < ActionController::Base
1✔
2
  protect_from_forgery with: :exception
1✔
3

4
  include Pundit::Authorization
1✔
5

6
  rescue_from Exception do |ex|
1✔
7
    Rollbar.error(ex)
×
8
    Rails.logger.fatal(ex)
×
9
    respond_to do |format|
×
10
      format.html { render 'errors/error', layout: false, status: :internal_server_error }
×
11
      format.all  { head :internal_server_error }
×
12
    end
13
  end
14

15
  rescue_from ActionController::RoutingError, with: :render_not_found
1✔
16
  rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
1✔
17

18
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
1✔
19
  rescue_from Pundit::AuthorizationNotPerformedError, with: :user_not_authorized
1✔
20

21
  helper_method :logged_in?
1✔
22
  helper_method :current_user
1✔
23
  helper_method :current_service
1✔
24

25
  before_action :set_locale
1✔
26
  before_action :accept_terms, if: :logged_in?
1✔
27

28
  def render_not_found
1✔
29
    respond_to do |format|
3✔
30
      format.html { render template: 'errors/not_found', layout: false, status: :not_found }
6✔
31
      format.all  { head :not_found }
3✔
32
    end
33
  end
34

35
  protected
1✔
36

37
  def current_user
1✔
38
    if session.key?(:member_id)
864✔
39
      @current_member ||= Member.find(session[:member_id])
376✔
40
    end
41
  rescue ActiveRecord::RecordNotFound
42
    session[:member_id] = nil
×
43
  end
44

45
  def current_service
1✔
46
    if session.key?(:service_id)
×
47
      @current_service ||= Service.find_by(member_id: session[:member_id],
×
48
                                           id: session[:service_id])
49
    end
50
  rescue ActiveRecord::RecordNotFound
51
    session[:service_id] = nil
×
52
  end
53

54
  def current_user?
1✔
55
    !!current_user
1,688✔
56
  end
57

58
  def logged_in?
1✔
59
    current_user?
1,688✔
60
  end
61

62
  def accept_terms
1✔
63
    store_path
499✔
64
    redirect_to terms_and_conditions_path if current_user.accepted_toc_at.blank?
499✔
65
  end
66

67
  def authenticate_member!
1✔
68
    if current_user
29✔
69
      finish_registration
28✔
70
    else
71
      redirect_to redirect_path
1✔
72
    end
73
  end
74

75
  def store_path
1✔
76
    session[:previous_request_url] = request.url
499✔
77
  end
78

79
  def previous_path
1✔
80
    session[:previous_request_url]
7✔
81
  end
82

83
  def finish_registration
1✔
84
    if current_user.requires_additional_details?
36✔
85
      redirect_to edit_member_details_path unless providing_additional_details?
×
86
    end
87
  end
88

89
  def providing_additional_details?
1✔
90
    [edit_member_path, edit_member_details_path].include? request.path
×
91
  end
92

93
  def logout!
1✔
94
    @current_member = nil
×
95
    reset_session
×
96
  end
97

98
  helper_method :redirect_path
1✔
99
  def redirect_path
1✔
100
    '/auth/github'
8✔
101
  end
102

103
  def authenticate_admin!
1✔
104
    redirect_to root_path, notice: "You can't be here" unless logged_in? && current_user.has_role?(:admin)
4✔
105
  end
106

107
  def authenticate_admin_or_organiser!
1✔
108
    redirect_to root_path, notice: "You can't be here" unless manager?
220✔
109
  end
110

111
  def manager?
1✔
112
    logged_in? && (current_user.is_admin? || current_user.has_role?(:organiser, :any))
220✔
113
  end
114

115
  helper_method :manager?
1✔
116

117
  def is_logged_in?
1✔
118
    unless logged_in?
63✔
119
      flash[:notice] = t('notifications.not_logged_in')
1✔
120
      redirect_to root_path
1✔
121
    end
122
  end
123

124
  def has_access?
1✔
125
    is_logged_in?
53✔
126
  end
127

128
  private
1✔
129

130
  def set_locale
1✔
131
    store_locale_to_cookie(params[:locale]) if locale
721✔
132
    I18n.locale = cookies[:locale] || I18n.default_locale
721✔
133
  end
134

135
  def user_not_authorized
1✔
136
    redirect_to(user_path, notice: 'You are not authorized to perform this action.')
1✔
137
  end
138

139
  def user_path
1✔
140
    request.referrer || root_path
1✔
141
  end
142

143
  def chapters
1✔
144
    @chapters ||= Chapter.all
×
145
  end
146

147
  def redirect_back(fallback_location:, **args)
1✔
148
    if referer = request.headers['Referer']
82✔
149
      redirect_to referer, **args
64✔
150
    else
151
      redirect_to fallback_location, **args
18✔
152
    end
153
  end
154

155
  def store_locale_to_cookie(locale)
1✔
156
    cookies[:locale] = { value: locale,
1✔
157
                         expires: Time.zone.now + 36_000 }
158
  end
159

160
  def locale
1✔
161
    params[:locale] if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
721✔
162
  end
163
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

© 2025 Coveralls, Inc