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

pulibrary / tigerdata-app / b6e4a7c7-d411-4822-a760-84eba5096a52

01 Dec 2025 03:02PM UTC coverage: 74.875% (-12.7%) from 87.594%
b6e4a7c7-d411-4822-a760-84eba5096a52

Pull #2251

circleci

carolyncole
Updating the department select to utilize LuxInputMultiSelect
The component only allows an item to be selected once (only for non asynch results which departments are).
fiexs #2134
Pull Request #2251: Updating the department select to utilize LuxInputMultiSelect

2390 of 3192 relevant lines covered (74.87%)

215.79 hits per line

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

85.9
/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
49✔
17
  end
18

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

41
  private
2✔
42

43
    def check_access
2✔
44
      return if user_eligible_to_modify_request?
88✔
45

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

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

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

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

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

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

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

90
    def update_sidebar_url(request_model)
2✔
91
      return unless params[:commit].start_with?("http")
11✔
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}"
4✔
95
    end
96

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

107
    def save_request
2✔
108
      request_model.update(request_params)
39✔
109
    end
110

111
    # Only allow a list of trusted parameters through.
112
    def request_params
2✔
113
      request_params = params.fetch(:request, {}).permit(:request_title, :project_title, :state, :data_sponsor, :data_manager,
39✔
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"
39✔
117
      if request_params[:departments].present?
39✔
118
        request_params[:departments] = clean_departments(request_params[:departments])
21✔
119
      end
120
      if request_params[:user_roles].present?
39✔
121
        request_params[:user_roles] = request_params[:user_roles].compact_blank.map do |role_str|
3✔
122
          json = JSON.parse(role_str)
4✔
123
          json["read_only"] = params[:request]["read_only_#{json['uid']}"] == "true"
4✔
124
          json
4✔
125
        end
126
      end
127
      request_params
39✔
128
    end
129

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

135
    def set_breadcrumbs
2✔
136
      add_breadcrumb("Dashboard", dashboard_path)
89✔
137
    end
138

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