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

pulibrary / tigerdata-app / b24cc2b6-b6b3-496b-9591-c180ce75a674

24 Sep 2025 03:08PM UTC coverage: 88.812% (-0.3%) from 89.139%
b24cc2b6-b6b3-496b-9591-c180ce75a674

Pull #1892

circleci

carolyncole
typo
Pull Request #1892: Handle mediaflux session errors in request controller

4 of 18 new or added lines in 1 file covered. (22.22%)

1 existing line in 1 file now uncovered.

2580 of 2905 relevant lines covered (88.81%)

322.82 hits per line

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

65.45
/app/controllers/requests_controller.rb
1
# frozen_string_literal: true
2
class RequestsController < ApplicationController
1✔
3
  before_action :set_breadcrumbs
1✔
4
  around_action :mediaflux_session_errors
1✔
5

6
  # GET /requests
7
  def index
1✔
8
    if current_user.eligible_sysadmin?
5✔
9
      add_breadcrumb("Project Requests - All")
2✔
10
      @draft_requests = Request.where(state: Request::DRAFT).map do |request|
2✔
11
        request.project_title = "no title set" if request.project_title.blank?
×
12
        request
×
13
      end
14
      @submitted_requests = Request.where(state: Request::SUBMITTED)
2✔
15
    else
16
      error_message = "You do not have access to this page."
3✔
17
      flash[:notice] = error_message
3✔
18
      redirect_to dashboard_path
3✔
19
    end
20
  end
21

22
  def show
1✔
23
    if current_user.developer || current_user.sysadmin || current_user.trainer
15✔
24
      @request_model = Request.find(params[:id])
11✔
25
      add_breadcrumb("Requests", requests_path)
11✔
26
      add_breadcrumb(@request_model.project_title, request_path(@request_model))
11✔
27
      render :show
11✔
28
    else
29
      error_message = "You do not have access to this page."
4✔
30
      flash[:notice] = error_message
4✔
31
      redirect_to dashboard_path
4✔
32
    end
33
  end
34

35
  # rubocop:disable Metrics/MethodLength
36
  # rubocop:disable Metrics/AbcSize
37
  def approve
1✔
38
    if current_user.developer || current_user.sysadmin || current_user.trainer
5✔
39
      @request_model = Request.find(params[:id])
5✔
40
      if @request_model.valid_to_submit?
5✔
41
        project = @request_model.approve(current_user)
4✔
42
        @request_model.destroy
4✔
43
        stub_message = "The request has been approved and this project was created in the TigerData web portal.  The request has been processed and deleted."
4✔
44
        TigerdataMailer.with(project_id: project.id, approver: current_user).project_creation.deliver_later
4✔
45
        redirect_to project_path(project.id), notice: stub_message
4✔
46
      else
47
        redirect_to new_project_review_and_submit_path(@request_model)
1✔
48
      end
49
    else
50
      error_message = "You do not have access to this page."
×
51
      flash[:notice] = error_message
×
52
      redirect_to dashboard_path
×
53
    end
54
  end
55

56
  private
1✔
57

58
    def set_breadcrumbs
1✔
59
      add_breadcrumb("Dashboard", dashboard_path)
25✔
60
    end
61

62
    def mediaflux_session_errors
1✔
63
      yield # Yield to the action, show & approve
25✔
64
    rescue ActionView::Template::Error, Mediaflux::SessionExpired, ProjectCreate::ProjectCreateError => e # Catches all SessionExpired errors from Mediaflux calls
NEW
65
      raise unless e.is_a?(Mediaflux::SessionExpired) || e.cause.is_a?(Mediaflux::SessionExpired) || e.is_a?(ProjectCreate::ProjectCreateError) || e.cause.is_a?(ProjectCreate::ProjectCreateError)
×
NEW
66
      if session[:active_web_user]
×
NEW
67
        redirect_to mediaflux_passthru_path(path: request.path)
×
NEW
68
      elsif session_error_handler
×
NEW
69
        retry
×
70
      else
71
        # If a ProjectCreateError is not caused by a session expiry we want to log it and notify Honeybadger
NEW
72
        Rails.logger.error "Error approving request #{params[:id]}. Details: #{e.message}"
×
NEW
73
        Honeybadger.notify "Error approving request #{params[:id]}. Details: #{e.message}"
×
NEW
74
        flash[:notice] = "Error approving request #{params[:id]}"
×
NEW
75
        redirect_to request_path(@request_model)
×
76
      end
77
    end
78

79
    # rubocop:enable Metrics/AbcSize
80
    # rubocop:enable Metrics/MethodLength
81

82
    def session_error_handler
1✔
NEW
83
      @retry_count ||= 0
×
NEW
84
      @retry_count += 1
×
85

NEW
86
      current_user.clear_mediaflux_session(session)
×
NEW
87
      current_user.mediaflux_from_session(session)
×
NEW
88
      @retry_count < 3 # If the session is expired we should not have to retry more than once, but let's have a little wiggle room
×
89
    end
90
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