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

pulibrary / tigerdata-app / c4e30aa7-22e1-4c10-94de-7c602f448bdc

15 Dec 2025 05:48PM UTC coverage: 91.163% (+0.01%) from 91.149%
c4e30aa7-22e1-4c10-94de-7c602f448bdc

Pull #2311

circleci

JaymeeH
Remove exit without saving functionality
Pull Request #2311: Remove exit without saving functionality

2971 of 3259 relevant lines covered (91.16%)

606.41 hits per line

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

94.81
/app/controllers/request_wizards_controller.rb
1
# frozen_string_literal: true
2
class RequestWizardsController < ApplicationController
5✔
3
  layout "wizard"
5✔
4
  before_action :set_breadcrumbs
5✔
5

6
  before_action :set_request_model, only: %i[save]
5✔
7
  before_action :set_or_init_request_model, only: %i[show]
5✔
8
  before_action :check_access
5✔
9

10
  attr_reader :request_model
5✔
11

12
  # GET /request_wizards/1
13
  def show
5✔
14
    # show the current wizard step form
15
    render_current
78✔
16
  end
17

18
  # PUT /request_wizards/1/save
19
  def save
5✔
20
    # save and render the requested step
21
    save_request
90✔
22
    notice_message = "Draft request saved automatically. To open or delete your draft, select the dropdown menu next to 'New Project Request'."
90✔
23
    if params["redirectUrl"] == "undefined" # clicking the tigerdata logo
90✔
24
      redirect_to dashboard_path
1✔
25
      flash[:notice] = notice_message
1✔
26
    elsif params["redirectUrl"] # clicking a breadcrumb link
89✔
27
      redirect_to params["redirectUrl"]
7✔
28
      flash[:notice] = notice_message
7✔
29
    else
30
      redirect_to_requested_step
82✔
31
    end
32
  end
33

34
  private
5✔
35

36
    def redirect_to_requested_step
5✔
37
      case params[:commit]
82✔
38
      when "Back"
39
        render_back
19✔
40
      when "Next", "Submit"
41
        render_next
32✔
42
      else
43
        redirect_to request_path(@request_model)
31✔
44
      end
45
    end
46

47
    def check_access
5✔
48
      return if user_eligible_to_modify_request?
201✔
49

50
      # request can not be modified by this user, redirect to dashboard
51
      error_message = "You do not have access to this page."
33✔
52
      flash[:notice] = error_message
33✔
53
      redirect_to dashboard_path
33✔
54
    end
55

56
    def render_current
5✔
57
      raise "Must be implemented"
×
58
    end
59

60
    def render_next
5✔
61
      raise "Must be implemented"
×
62
    end
63

64
    def render_back
5✔
65
      raise "Must be implemented"
×
66
    end
67

68
    # Use callbacks to share common setup or constraints between actions.
69
    def set_request_model
5✔
70
      # do nothing if we are bailing out without creating a request2
71
      return if params[:request_id] == "0" && params[:commit] == "Exit without Saving"
104✔
72

73
      @request_model = if params[:request_id] == "0"
104✔
74
                         # on the first page with a brand new request that has not been created
75
                         req = Request.create(requested_by: current_user.uid)
13✔
76
                         update_sidebar_url(req)
13✔
77
                         req
13✔
78
                       else
79
                         # on a page when the request has already been created
80
                         Request.find(params[:request_id])
91✔
81
                       end
82
    end
83

84
    def update_sidebar_url(request_model)
5✔
85
      return unless params["redirectUrl"] && params["redirectUrl"].last == "0"
13✔
86

87
      # take of the zero in the url and replace it with the real request id
88
      params["redirectUrl"] = "#{params['redirectUrl'][0..-2]}#{request_model.id}"
4✔
89
    end
90

91
    # set if id is present or initialize a blank request if not
92
    def set_or_init_request_model
5✔
93
      @princeton_departments = Affiliation.all
97✔
94
      @request_model = if params[:request_id].blank?
97✔
95
                         Request.new(id: 0, requested_by: current_user.uid)
17✔
96
                       else
97
                         Request.find(params[:request_id])
80✔
98
                       end
99
    end
100

101
    def save_request
5✔
102
      request_model.update(request_params)
90✔
103
    end
104

105
    # Only allow a list of trusted parameters through.
106
    def request_params
5✔
107
      request_params = params.fetch(:request, {}).permit(:request_title, :project_title, :state, :data_sponsor, :data_manager,
90✔
108
                                        :project_purpose, :description, :parent_folder, :project_folder, :project_id, :quota,
109
                                        :requested_by, :storage_size, :storage_unit, :number_of_files, :hpc, :smb, :globus, user_roles: [], departments: [])
110
      request_params[:storage_unit] ||= "TB"
90✔
111
      if request_params[:departments].present?
90✔
112
        request_params[:departments] = clean_departments(request_params[:departments])
27✔
113
      end
114
      if request_params[:user_roles].present?
90✔
115
        request_params[:user_roles] = request_params[:user_roles].compact_blank.map do |role_str|
3✔
116
          json = JSON.parse(role_str)
4✔
117
          json["read_only"] = params[:request]["read_only_#{json['uid']}"] == "true"
4✔
118
          json
4✔
119
        end
120
      end
121
      request_params
90✔
122
    end
123

124
    def clean_departments(departments)
5✔
125
      uniq_departments = departments.uniq
27✔
126
      uniq_departments.compact_blank.map { |dep_str| JSON.parse(dep_str) }
48✔
127
    end
128

129
    def set_breadcrumbs
5✔
130
      add_breadcrumb("Dashboard", dashboard_path)
201✔
131
    end
132

133
    def user_eligible_to_modify_request?
5✔
134
      # elevated privs for the current user
135
      if current_user.sysadmin || (current_user.developer && !Rails.env.production?)
201✔
136
        true
109✔
137
      # current user is the requestor
138
      elsif (@request_model.requested_by == current_user.uid) && !@request_model.submitted?
92✔
139
        true
59✔
140
      # a brand new request
141
      elsif params[:request_id].blank?
33✔
142
        true
×
143
      # no access for any other reason
144
      else
145
        false
33✔
146
      end
147
    end
148
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