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

pulibrary / tigerdata-app / a3f50227-2424-4d41-8788-b953b9d6c802

24 Nov 2025 05:22PM UTC coverage: 70.412% (-17.7%) from 88.064%
a3f50227-2424-4d41-8788-b953b9d6c802

push

circleci

web-flow
Deduplicate department field from requests (#2229)

ref #2147

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

833 existing lines in 48 files now uncovered.

2344 of 3329 relevant lines covered (70.41%)

150.39 hits per line

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

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

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

11
  attr_reader :request_model
2✔
12

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

19
  # PUT /request_wizards/1/save
20
  def save
2✔
21
    # save and render dashboard
22
    save_request
28✔
23
    case params[:commit]
28✔
24
    when "Back"
25
      render_back
6✔
26
    when "Next", "Submit"
27
      render_next
7✔
28
    else
29
      if params[:commit].start_with?("http")
15✔
30
        # Go directly to the step the user clicked on
31
        redirect_to params[:commit]
×
32
      else
33
        redirect_to request_path(@request_model)
15✔
34
      end
35
    end
36
  end
37

38
  private
2✔
39

40
    def check_access
2✔
41
      return if user_eligible_to_modify_request?
59✔
42

43
      # request can not be modified by this user, redirect to dashboard
UNCOV
44
      error_message = "You do not have access to this page."
16✔
UNCOV
45
      flash[:notice] = error_message
16✔
UNCOV
46
      redirect_to dashboard_path
16✔
47
    end
48

49
    def exit_without_saving
2✔
50
      if params[:commit] == "Exit without Saving"
35✔
51
        if @request_model.nil?
×
52
          redirect_to dashboard_path
×
53
        else
54
          redirect_to request_path(@request_model)
×
55
        end
56
      end
57
    end
58

59
    def render_current
2✔
60
      raise "Must be implemented"
×
61
    end
62

63
    def render_next
2✔
64
      raise "Must be implemented"
×
65
    end
66

67
    def render_back
2✔
68
      raise "Must be implemented"
×
69
    end
70

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

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

87
    def update_sidebar_url(request_model)
2✔
88
      return unless params[:commit].start_with?("http")
×
89

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

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

104
    def save_request
2✔
105
      request_model.update(request_params)
28✔
106
    end
107

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

127
    def clean_departments(departments)
2✔
NEW
128
      uniq_departments = departments.uniq
2✔
NEW
129
      uniq_departments.compact_blank.map { |dep_str| JSON.parse(dep_str) }
6✔
130
    end
131

132
    def set_breadcrumbs
2✔
133
      add_breadcrumb("Dashboard", dashboard_path)
59✔
134
    end
135

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