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

pulibrary / tigerdata-app / 9d76b7eb-940a-44e8-b4ac-cf7b8cdcc98c

01 Dec 2025 03:02PM UTC coverage: 80.707% (-6.9%) from 87.594%
9d76b7eb-940a-44e8-b4ac-cf7b8cdcc98c

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

2602 of 3224 relevant lines covered (80.71%)

263.99 hits per line

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

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

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

11
  attr_reader :request_model
3✔
12

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

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

41
  private
3✔
42

43
    def check_access
3✔
44
      return if user_eligible_to_modify_request?
98✔
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
3✔
53
      if params[:commit] == "Exit without Saving"
52✔
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
3✔
63
      raise "Must be implemented"
×
64
    end
65

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

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

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

79
      @request_model = if params[:request_id] == "0"
52✔
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])
52✔
87
                       end
88
    end
89

90
    def update_sidebar_url(request_model)
3✔
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
3✔
99
      @princeton_departments = Affiliation.all
46✔
100
      @request_model = if params[:request_id].blank?
46✔
101
                         Request.new(id: 0, requested_by: current_user.uid)
2✔
102
                       else
103
                         Request.find(params[:request_id])
44✔
104
                       end
105
    end
106

107
    def save_request
3✔
108
      request_model.update(request_params)
38✔
109
    end
110

111
    # Only allow a list of trusted parameters through.
112
    def request_params
3✔
113
      request_params = params.fetch(:request, {}).permit(:request_title, :project_title, :state, :data_sponsor, :data_manager,
38✔
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"
38✔
117
      if request_params[:departments].present?
38✔
118
        request_params[:departments] = clean_departments(request_params[:departments])
×
119
      end
120
      if request_params[:user_roles].present?
38✔
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
38✔
128
    end
129

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

135
    def set_breadcrumbs
3✔
136
      add_breadcrumb("Dashboard", dashboard_path)
98✔
137
    end
138

139
    def user_eligible_to_modify_request?
3✔
140
      # elevated privs for the current user
141
      if current_user.sysadmin || (current_user.developer && !Rails.env.production?)
98✔
142
        true
61✔
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