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

pulibrary / tigerdata-app / a829b9c5-1dc3-477f-a44e-45890dfc33cb

24 Nov 2025 02:38PM UTC coverage: 87.586% (-0.5%) from 88.064%
a829b9c5-1dc3-477f-a44e-45890dfc33cb

Pull #2235

circleci

carolyncole
Do not redirect from home page when login is disabled
fixes #2188
Pull Request #2235: Do not redirect from home page when login is disabled

1 of 5 new or added lines in 2 files covered. (20.0%)

794 existing lines in 37 files now uncovered.

2787 of 3182 relevant lines covered (87.59%)

361.47 hits per line

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

95.24
/app/presenters/project_show_presenter.rb
1
# frozen_string_literal: true
UNCOV
2
class ProjectShowPresenter
2✔
UNCOV
3
  delegate "id", "in_mediaflux?", "mediaflux_id", "status", to: :project
2✔
UNCOV
4
  delegate "project_id", "storage_performance_expectations", to: :project_metadata
2✔
5

UNCOV
6
  attr_reader :project, :project_metadata
2✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
UNCOV
9
  def self.xml_presenter_class
2✔
UNCOV
10
    ProjectXmlPresenter
5✔
UNCOV
11
  end
12

13
  # While we are transitioning to fetching the data straight from Mediaflux `project` can be
14
  # an ActiveRecord Project model (when used from the Project show page) or a Hash with the
15
  # data from Mediaflux (when used from the Dashboard).
16
  # This branching can be refactored (elimitated?) once we implement ticket
17
  # https://github.com/pulibrary/tigerdata-app/issues/2039 and the project data will always
18
  # come from Mediaflux.
UNCOV
19
  def initialize(project, current_user)
2✔
UNCOV
20
    if project.is_a?(Hash)
91✔
UNCOV
21
      @project_mf = project
35✔
UNCOV
22
      @project = rails_project(@project_mf)
35✔
UNCOV
23
    else
UNCOV
24
      @project = project
56✔
UNCOV
25
      @project_mf = project.mediaflux_metadata(session_id: current_user.mediaflux_session)
56✔
UNCOV
26
    end
UNCOV
27
    @project_metadata = @project&.metadata_model
87✔
UNCOV
28
  end
29

UNCOV
30
  def title
2✔
UNCOV
31
    @project_mf[:title]
12✔
UNCOV
32
  end
33

UNCOV
34
  def description
2✔
UNCOV
35
    @project_mf[:description]
4✔
UNCOV
36
  end
37

38
  # @return [String] the XML for the project Document
UNCOV
39
  def to_xml
2✔
UNCOV
40
    xml_document.to_xml
4✔
UNCOV
41
  end
42

43
  # @return [Nokogiri::XML::Document] the XML Document for the Project
UNCOV
44
  def xml_document
2✔
UNCOV
45
    @xml_document ||= xml_presenter.document
5✔
UNCOV
46
  end
47

UNCOV
48
  def created
2✔
49
    @project.created_at.strftime("%b %e, %Y %l:%M %p")
1✔
UNCOV
50
  end
51

UNCOV
52
  def updated
2✔
53
    @project.updated_at.strftime("%b %e, %Y %l:%M %p")
1✔
UNCOV
54
  end
55

UNCOV
56
  def data_sponsor
2✔
UNCOV
57
    User.find_by(uid: @project_mf[:data_sponsor])
27✔
UNCOV
58
  end
59

UNCOV
60
  def data_manager
2✔
UNCOV
61
    User.find_by(uid: @project_mf[:data_manager])
17✔
UNCOV
62
  end
63

UNCOV
64
  def data_read_only_users
2✔
UNCOV
65
    (@project_mf[:ro_users] || []).map { |uid| ReadOnlyUser.find_by(uid:) }.compact
16✔
UNCOV
66
  end
67

UNCOV
68
  def data_read_write_users
2✔
UNCOV
69
    (@project_mf[:rw_users] || []).map { |uid| User.find_by(uid:) }.compact
16✔
UNCOV
70
  end
71

UNCOV
72
  def data_users
2✔
UNCOV
73
    unsorted_data_users = data_read_only_users + data_read_write_users
13✔
UNCOV
74
    sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
19✔
UNCOV
75
    sorted_data_users.uniq { |u| u.uid }
19✔
UNCOV
76
  end
77

UNCOV
78
  def data_user_names
2✔
79
    user_model_names = data_users.map(&:display_name_safe)
2✔
80
    user_model_names.join(", ")
2✔
UNCOV
81
  end
82

UNCOV
83
  def project_purpose
2✔
UNCOV
84
    ProjectPurpose.label_for(@project_mf[:project_purpose])
4✔
UNCOV
85
  end
86

87
  # used to hide the project root that is not visible to the end user
UNCOV
88
  def project_directory
2✔
89
    # This value comes from Mediaflux without the extra hidden root
UNCOV
90
    directory = @project_mf[:project_directory] || ""
3✔
UNCOV
91
    directory.start_with?("/") ? directory : "/" + directory
3✔
UNCOV
92
  end
93

UNCOV
94
  def hpc
2✔
95
    @project_mf[:hpc] == true ? "Yes" : "No"
1✔
UNCOV
96
  end
97

UNCOV
98
  def globus
2✔
99
    @project_mf[:globus] == true ? "Yes" : "No"
1✔
UNCOV
100
  end
101

UNCOV
102
  def smb
2✔
103
    @project_mf[:smb] == true ? "Yes" : "No"
1✔
UNCOV
104
  end
105

UNCOV
106
  def number_of_files
2✔
107
    @project_mf[:number_of_files]
1✔
UNCOV
108
  end
109

UNCOV
110
  def departments
2✔
UNCOV
111
    @project_mf[:departments] || []
5✔
UNCOV
112
  end
113

UNCOV
114
  def department_codes
2✔
UNCOV
115
    @dep_with_codes = {}
2✔
UNCOV
116
    departments_list = departments.nil? ? [] : departments.first.split(", ")
2✔
UNCOV
117
    departments_list.map do |dept|
2✔
UNCOV
118
      tmp_code = Affiliation.find_fuzzy_by_name(dept)
2✔
UNCOV
119
      @dep_with_codes[dept] = tmp_code.code unless tmp_code.nil?
2✔
UNCOV
120
    end
UNCOV
121
    @dep_with_codes
2✔
UNCOV
122
  end
123

UNCOV
124
  def project_id
2✔
UNCOV
125
    @project_mf[:project_id]
3✔
UNCOV
126
  end
127

UNCOV
128
  def storage_capacity(session_id: nil)
2✔
UNCOV
129
    return project_metadata.storage_capacity if session_id.nil?
3✔
130

131
    persisted = project.storage_capacity_raw(session_id: session_id)
1✔
132
    value = persisted.to_f
1✔
133

134
    value*default_capacity_divisor
1✔
UNCOV
135
  end
136

UNCOV
137
  def formatted_storage_capacity(session_id:)
2✔
138
    value = storage_capacity(session_id: session_id)
1✔
139
    format("%.3f", value)
1✔
UNCOV
140
  end
141

UNCOV
142
  def formatted_quota_percentage(session_id:)
2✔
143
    value = quota_percentage(session_id:)
1✔
144
    format("%.3f", value)
1✔
UNCOV
145
  end
146

UNCOV
147
  def quota_usage(session_id:)
2✔
148
    "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
1✔
UNCOV
149
  end
150

UNCOV
151
  def quota_percentage(session_id:, dashboard: false)
2✔
152
    storage_capacity = project.storage_capacity_raw(session_id:)
2✔
153
    return 0 if storage_capacity.zero?
2✔
154
    storage_usage = project.storage_usage_raw(session_id:)
2✔
155
    return 0 if storage_usage == 0
2✔
156
    storage_value = (storage_usage.to_f / storage_capacity.to_f) * 100
×
157
    minimum_storage_used = true if storage_value > 0 && storage_value < 1
×
158
    storage_value = 1 if minimum_storage_used
×
159
    storage_value += 1 if minimum_storage_used && dashboard
×
160
    storage_value
×
UNCOV
161
  end
162

UNCOV
163
  def user_has_access?(user:)
2✔
UNCOV
164
    return true if user.eligible_sysadmin?
22✔
UNCOV
165
    data_sponsor&.uid == user.uid || data_manager&.uid == user.uid || data_users.map(&:uid).include?(user.uid)
22✔
UNCOV
166
  end
167

UNCOV
168
  def project_in_rails?
2✔
UNCOV
169
    project != nil
35✔
UNCOV
170
  end
171

UNCOV
172
  private
2✔
173

174
    # Capacity is in bytes
UNCOV
175
    def default_capacity_divisor
2✔
176
      1.0/(1000.0**3)
1✔
UNCOV
177
    end
178

UNCOV
179
    def xml_presenter_args
2✔
UNCOV
180
      project
5✔
UNCOV
181
    end
182

UNCOV
183
    def xml_presenter
2✔
UNCOV
184
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
5✔
UNCOV
185
    end
186

UNCOV
187
    def rails_project(project_mf)
2✔
UNCOV
188
      database_record = Project.where(mediaflux_id:project_mf[:mediaflux_id]).first
35✔
UNCOV
189
      if database_record.nil?
35✔
UNCOV
190
        Rails.logger.warn("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
25✔
UNCOV
191
        Honeybadger.notify("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
25✔
UNCOV
192
      end
UNCOV
193
      database_record
35✔
UNCOV
194
    end
UNCOV
195
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