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

pulibrary / tigerdata-app / ef572ceb-a81a-43e7-bdc7-686bc2a048ee

05 Nov 2025 10:27PM UTC coverage: 83.655% (-7.4%) from 91.073%
ef572ceb-a81a-43e7-bdc7-686bc2a048ee

Pull #2154

circleci

JaymeeH
Display project directory correctly and consistently
Pull Request #2154: Display project directory correctly and consistently

0 of 2 new or added lines in 2 files covered. (0.0%)

711 existing lines in 37 files now uncovered.

2600 of 3108 relevant lines covered (83.66%)

315.14 hits per line

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

92.86
/app/models/request.rb
1
# frozen_string_literal: true
2
# rubocop:disable Metrics/ClassLength
3
class Request < ApplicationRecord
3✔
4
  DRAFT = "draft" # default state set by database
3✔
5
  SUBMITTED = "submitted" # Ready to be approved
3✔
6

7
  def valid_to_submit?
3✔
UNCOV
8
    errors.clear
25✔
9
    # run all validations and then check for errors otherwise ruby stops at the first error
UNCOV
10
    valid_title?
25✔
UNCOV
11
    valid_data_sponsor?
25✔
UNCOV
12
    valid_data_manager?
25✔
UNCOV
13
    valid_departments?
25✔
UNCOV
14
    valid_quota?
25✔
UNCOV
15
    valid_project_purpose?
25✔
UNCOV
16
    valid_description?
25✔
17
    # Is parent folder really required?  For Skeletor let's skip it.
18
    # valid_parent_folder?
UNCOV
19
    valid_project_folder?
25✔
20
    # For Skeletor we are setting the requestor to the data sponsor
21
    # valid_requested_by?
UNCOV
22
    errors.count == 0
25✔
23
  end
24

25
  def valid_title?
3✔
UNCOV
26
    check_errors? do
25✔
UNCOV
27
      field_present?(project_title, :project_title)
25✔
UNCOV
28
      valid_length(project_title, 200, :project_title)
25✔
UNCOV
29
      no_quotes(project_title, :project_title)
25✔
30
    end
31
  end
32

33
  def valid_data_sponsor?
3✔
UNCOV
34
    check_errors? { validate_uid(data_sponsor, :data_sponsor) }
50✔
35
  end
36

37
  def valid_data_manager?
3✔
UNCOV
38
    check_errors? { validate_uid(data_manager, :data_manager) }
50✔
39
  end
40

41
  def valid_departments?
3✔
UNCOV
42
    check_errors? { field_present?(departments, :departments) }
50✔
43
  end
44

45
  def valid_project_purpose?
3✔
UNCOV
46
    check_errors? { project_purpose_present?(project_purpose, :project_purpose) }
50✔
47
  end
48

49
  def valid_description?
3✔
UNCOV
50
    check_errors? do
25✔
UNCOV
51
      field_present?(description, :description)
25✔
UNCOV
52
      valid_length(description, 1000, :description)
25✔
UNCOV
53
      no_quotes(description, :description)
25✔
54
    end
55
  end
56

57
  def valid_parent_folder?
3✔
58
    check_errors? do
×
59
      field_present?(parent_folder, :parent_folder)
×
60
      no_quotes(project_title, :parent_folder)
×
61
    end
62
  end
63

64
  def valid_project_folder?
3✔
UNCOV
65
    check_errors? do
25✔
UNCOV
66
      field_present?(project_folder, :project_folder)
25✔
UNCOV
67
      no_quotes(project_folder, :project_folder)
25✔
68
    end
69
  end
70

71
  def valid_quota?
3✔
UNCOV
72
    if ((quota == "500 GB") || (quota == "2 TB") || (quota == "10 TB") || (quota == "25 TB")) ||
25✔
73
       (custom_quota? && (storage_size.present? && (storage_size > 0)) && ((storage_unit == "GB") || (storage_unit == "TB")))
2✔
UNCOV
74
      true
24✔
75
    else
76
      errors.add(:quota, :invalid, message: "must be one of '500 GB', '2 TB', '10 TB', '25 TB', or 'custom'")
1✔
77
      false
1✔
78
    end
79
  end
80

81
  def custom_quota?
3✔
82
    quota == "custom"
390✔
83
  end
84

85
  def valid_requested_by?
3✔
86
    check_errors? { field_present?(requested_by, :requested_by) }
×
87
  end
88

89
  def approve(approver)
3✔
90
    create_project_operation = ProjectCreate.new
171✔
91
    result = create_project_operation.call(request: self, approver: approver)
171✔
92
    if result.success?
171✔
93
      result.value!
170✔
94
    else
UNCOV
95
      self.error_message = { message: result.failure }
1✔
UNCOV
96
      save!
1✔
UNCOV
97
      cleanup_incomplete_project
1✔
UNCOV
98
      raise ProjectCreate::ProjectCreateError, result.failure
1✔
99
    end
100
  end
101

102
  def approved_quota_size
3✔
103
    if approved_quota.present?
188✔
104
      if approved_quota == "custom"
168✔
105
        approved_storage_size.to_f
167✔
106
      else
107
        approved_quota.split.first.to_f
1✔
108
      end
109
    else
110
      requested_quota_size
20✔
111
    end
112
  end
113

114
  def requested_quota_size
3✔
115
    if custom_quota?
194✔
116
      storage_size.to_f
170✔
117
    else
118
      quota.split.first.to_f
24✔
119
    end
120
  end
121

122
  def approved_quota_unit
3✔
123
    if approved_quota.present?
188✔
124
      if approved_quota == "custom"
168✔
125
        approved_storage_unit
167✔
126
      else
127
        approved_quota.split.last
1✔
128
      end
129
    else
130
      requested_quota_unit
20✔
131
    end
132
  end
133

134
  def requested_quota_unit
3✔
135
    if custom_quota?
194✔
136
      storage_unit
170✔
137
    else
138
      quota.split.last
24✔
139
    end
140
  end
141

142
  def submitted?
3✔
143
    state == Request::SUBMITTED
173✔
144
  end
145

146
  def project_path
3✔
147
    return project_folder if parent_folder.blank?
2✔
148

149
    [parent_folder, project_folder].join("/")
×
150
  end
151

152
  def requestor
3✔
153
    return "missing" if requested_by.blank?
1✔
154
    User.find_by(uid: requested_by).display_name_safe
1✔
155
  end
156

157
  def data_manager_name
3✔
UNCOV
158
    user_name(data_manager)
23✔
159
  end
160

161
  def data_sponsor_name
3✔
UNCOV
162
    user_name(data_sponsor)
23✔
163
  end
164

165
  private
3✔
166

167
    def user_name(uid)
3✔
UNCOV
168
      return "" if uid.blank?
46✔
UNCOV
169
      user = User.find_by(uid: uid)
14✔
UNCOV
170
      if user.present?
14✔
UNCOV
171
        user.display_name_safe
13✔
172
      else
UNCOV
173
        uid
1✔
174
      end
175
    end
176

177
    def check_errors?
3✔
UNCOV
178
      original_error_count = errors.count
175✔
UNCOV
179
      yield
175✔
UNCOV
180
      original_error_count == errors.count
175✔
181
    end
182

183
    def field_present?(value, name)
3✔
UNCOV
184
      if value.blank?
100✔
UNCOV
185
        errors.add(name, :invalid, message: "cannot be empty")
34✔
186
      end
187
    end
188

189
    def validate_uid(uid, field)
3✔
UNCOV
190
      if uid.blank?
50✔
UNCOV
191
        errors.add(field, :blank, message: "cannot be empty")
18✔
UNCOV
192
      elsif User.where(uid: uid).count == 0
32✔
193
        errors.add(field, :invalid, message: "must be a valid user")
×
194
      end
195
    end
196

197
    def project_purpose_present?(project_purpose, field)
3✔
UNCOV
198
      if project_purpose.blank?
25✔
UNCOV
199
        errors.add(field, :blank, message: "select a project purpose")
9✔
200
      end
201
    end
202

203
    def valid_length(value, length, field)
3✔
UNCOV
204
      return if value.blank?
50✔
UNCOV
205
      if value.length > length
34✔
206
        errors.add(field, :invalid, message: "cannot exceed #{length} characters")
4✔
207
      end
208
    end
209

210
    def no_quotes(value, field)
3✔
UNCOV
211
      return if value.blank?
75✔
UNCOV
212
      if value.include?('"')
50✔
213
        errors.add(field, :invalid, message: "cannot include quotes")
×
214
      end
215
    end
216

217
    # If a request fails to be a approved we make sure there were not orphan
218
    # project records left in our Rails database that do not have a matching
219
    # project in Mediaflux (i.e. collection asset).
220
    def cleanup_incomplete_project
3✔
UNCOV
221
      project = Project.find_by_id(project_id)
1✔
UNCOV
222
      if project && project.mediaflux_id.nil?
1✔
223
        Rails.logger.warn("Deleting project #{project.id} because the approval for request #{id} failed and it was not created in Mediaflux.")
×
224
        project.destroy!
×
225
      end
226
    end
227
end
228
# rubocop:enable Metrics/ClassLength
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