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

pulibrary / tigerdata-app / 34dcbd97-a3da-420a-b11e-066310a63dda

01 Dec 2025 07:52PM UTC coverage: 87.656% (-3.7%) from 91.374%
34dcbd97-a3da-420a-b11e-066310a63dda

push

circleci

web-flow
Fixed quota display bug on dashboard (#2256)

Closes #2255 

## Local screenshot

<img width="1262" height="488" alt="Screenshot 2025-12-01 at 2 24 43 PM"
src="https://github.com/user-attachments/assets/c339863e-6d08-48f5-90c4-7a8d994fdc92"
/>

2805 of 3200 relevant lines covered (87.66%)

359.65 hits per line

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

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

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

11
  attr_reader :request_model
4✔
12

13
  # GET /request_wizards/1
14
  def show
4✔
15
    # show the current wizard step form
16
    render_current
31✔
17
  end
18

19
  # PUT /request_wizards/1/save
20
  def save
4✔
21
    # save and render dashboard
22
    save_request
52✔
23
    case params[:commit]
52✔
24
    when "Back"
25
      render_back
11✔
26
    when "Next", "Submit"
27
      render_next
13✔
28
    else
29
      if params[:commit].start_with?("http")
28✔
30
        # Go directly to the step the user clicked on
31
        redirect_to params[:commit]
×
32
      elsif params[:go_to_dashboard] == "yes"
28✔
33
        # The user clicked on the "Dashboard" breadcrumb
34
        redirect_to dashboard_path
×
35
      else
36
        redirect_to request_path(@request_model)
28✔
37
      end
38
    end
39
  end
40

41
  private
4✔
42

43
    def check_access
4✔
44
      return if user_eligible_to_modify_request?
116✔
45

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

52
    def exit_without_saving
4✔
53
      if params[:commit] == "Exit without Saving"
66✔
54
        if @request_model.nil?
×
55
          redirect_to dashboard_path
×
56
        else
57
          redirect_to request_path(@request_model)
×
58
        end
59
      end
60
    end
61

62
    def render_current
4✔
63
      raise "Must be implemented"
×
64
    end
65

66
    def render_next
4✔
67
      raise "Must be implemented"
×
68
    end
69

70
    def render_back
4✔
71
      raise "Must be implemented"
×
72
    end
73

74
    # Use callbacks to share common setup or constraints between actions.
75
    def set_request_model
4✔
76
      # do nothing if we are bailing out without creating a request2
77
      return if params[:request_id] == "0" && params[:commit] == "Exit without Saving"
66✔
78

79
      @request_model = if params[:request_id] == "0"
66✔
80
                         # on the first page with a brand new request that has not been created
81
                         req = Request.create(requested_by: current_user.uid)
×
82
                         update_sidebar_url(req)
×
83
                         req
×
84
                       else
85
                         # on a page when the request has already been created
86
                         Request.find(params[:request_id])
66✔
87
                       end
88
    end
89

90
    def update_sidebar_url(request_model)
4✔
91
      return unless params[:commit].start_with?("http")
×
92

93
      # take of the zero in the url and replace it with the real request id
94
      params[:commit] = "#{params[:commit][0..-2]}#{request_model.id}"
×
95
    end
96

97
    # set if id is present or initialize a blank request if not
98
    def set_or_init_request_model
4✔
99
      @princeton_departments = Affiliation.all
50✔
100
      @request_model = if params[:request_id].blank?
50✔
101
                         Request.new(id: 0, requested_by: current_user.uid)
2✔
102
                       else
103
                         Request.find(params[:request_id])
48✔
104
                       end
105
    end
106

107
    def save_request
4✔
108
      request_model.update(request_params)
52✔
109
    end
110

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

130
    def clean_departments(departments)
4✔
131
      uniq_departments = departments.uniq
4✔
132
      uniq_departments.compact_blank.map { |dep_str| JSON.parse(dep_str) }
12✔
133
    end
134

135
    def set_breadcrumbs
4✔
136
      add_breadcrumb("Dashboard", dashboard_path)
116✔
137
    end
138

139
    def user_eligible_to_modify_request?
4✔
140
      # elevated privs for the current user
141
      if current_user.sysadmin || (current_user.developer && !Rails.env.production?)
116✔
142
        true
79✔
143
      # current user is the requestor
144
      elsif (@request_model.requested_by == current_user.uid) && !@request_model.submitted?
37✔
145
        true
4✔
146
      # a brand new request
147
      elsif params[:request_id].blank?
33✔
148
        true
×
149
      # no access for any other reason
150
      else
151
        false
33✔
152
      end
153
    end
154
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