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

pulibrary / tigerdata-app / bd039a2a-6f1b-4f1e-b08e-58dd6b70d54e

25 Nov 2025 08:28PM UTC coverage: 91.374% (+11.8%) from 79.623%
bd039a2a-6f1b-4f1e-b08e-58dd6b70d54e

Pull #2247

circleci

hectorcorrea
Added tests to the dashboard for the new data
Pull Request #2247: Display the data sponsor and data manager in the dashboard listing

1 of 3 new or added lines in 1 file covered. (33.33%)

724 existing lines in 41 files now uncovered.

2913 of 3188 relevant lines covered (91.37%)

563.89 hits per line

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

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

6
  attr_reader :project, :project_metadata
5✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
9
  def self.xml_presenter_class
5✔
10
    ProjectXmlPresenter
9✔
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.
19
  def initialize(project, current_user)
5✔
20
    if project.is_a?(Hash)
1,240✔
21
      @project_mf = project
1,129✔
22
      @project = rails_project(@project_mf)
1,129✔
23
    else
24
      @project = project
111✔
25
      @project_mf = project.mediaflux_metadata(session_id: current_user.mediaflux_session)
111✔
26
    end
27
    @project_metadata = @project&.metadata_model
1,236✔
28
  end
29

30
  def title
5✔
31
    @project_mf[:title]
259✔
32
  end
33

34
  def description
5✔
UNCOV
35
    @project_mf[:description]
52✔
36
  end
37

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

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

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

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

56
  def data_sponsor
5✔
57
    User.find_by(uid: @project_mf[:data_sponsor])
419✔
58
  end
59

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

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

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

72
  def data_users
5✔
UNCOV
73
    unsorted_data_users = data_read_only_users + data_read_write_users
44✔
UNCOV
74
    sorted_data_users = unsorted_data_users.sort_by { |u| u.family_name || u.uid }
52✔
UNCOV
75
    sorted_data_users.uniq { |u| u.uid }
50✔
76
  end
77

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

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

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

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

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

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

106
  def number_of_files
5✔
UNCOV
107
    @project_mf[:number_of_files]
14✔
108
  end
109

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

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

124
  def project_id
5✔
UNCOV
125
    @project_mf[:project_id]
16✔
126
  end
127

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

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

UNCOV
134
    value*default_capacity_divisor
36✔
135
  end
136

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

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

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

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

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

168
  def project_in_rails?
5✔
169
    project != nil
1,129✔
170
  end
171

172
  private
5✔
173

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

179
    def xml_presenter_args
5✔
180
      project
9✔
181
    end
182

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

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